71 行
2.3 KiB
PHP
71 行
2.3 KiB
PHP
<?php
|
||
|
||
namespace addons\shopro_wechat_trade\library;
|
||
|
||
class WxOrderPathService
|
||
{
|
||
protected $client;
|
||
protected $config;
|
||
|
||
public function __construct()
|
||
{
|
||
$this->client = new WxTradeClient();
|
||
$this->config = WxTradeConfig::getInstance();
|
||
}
|
||
|
||
public function updatePath($path = null)
|
||
{
|
||
$path = self::normalizePath($path ?: $this->config->getOrderDetailPath());
|
||
$response = $this->client->postJson('/wxa/sec/order/update_order_detail_path', [
|
||
'path' => $path,
|
||
]);
|
||
return $this->client->callOrThrow($response, '配置订单详情路径');
|
||
}
|
||
|
||
/**
|
||
* 微信要求:不含前导 /;必须含 ${商品订单号};页面须已存在于线上或提审版本
|
||
*/
|
||
public static function normalizePath($path)
|
||
{
|
||
$path = trim((string) $path);
|
||
$path = ltrim($path, '/');
|
||
if (strpos($path, '${商品订单号}') === false) {
|
||
throw new \InvalidArgumentException('path 必须包含 ${商品订单号}');
|
||
}
|
||
return $path;
|
||
}
|
||
|
||
public static function defaultPath()
|
||
{
|
||
return 'pages/order/detail?id=${商品订单号}';
|
||
}
|
||
|
||
public static function explainPathError($errcode, $errmsg = '')
|
||
{
|
||
$code = intval($errcode);
|
||
if ($code === 10060034) {
|
||
return '请先在小程序后台签署订单中心授权协议(支付与交易 → 订单管理/购物订单)';
|
||
}
|
||
if ($code === 10060035) {
|
||
return '无效的路径(10060035):请确认 ① path 为 pages/order/detail?id=${商品订单号}(无前导/,参数名建议用 id)'
|
||
. ' ② 该页面已存在于小程序当前线上版或提审版(需先发布含订单详情页的小程序代码)'
|
||
. ' ③ 也可在小程序后台手动配置订单详情 path,不必强依赖 API';
|
||
}
|
||
if ($code === 10060036) {
|
||
return '请求编码须为 UTF-8(10060036)';
|
||
}
|
||
return trim($errmsg) ?: '未知错误';
|
||
}
|
||
|
||
public function getPath()
|
||
{
|
||
$response = $this->client->postJson('/wxa/sec/order/get_order_detail_path', []);
|
||
return $this->client->callOrThrow($response, '查询订单详情路径');
|
||
}
|
||
|
||
public function isTradeManaged()
|
||
{
|
||
return $this->client->getJson('/wxa/sec/order/is_trade_managed');
|
||
}
|
||
}
|