|
@@ -6,6 +6,8 @@ use app\common\exception\ShoproException;
|
|
use app\common\service\order\shippingInfo\OrderShippingInfo;
|
|
use app\common\service\order\shippingInfo\OrderShippingInfo;
|
|
use app\commom\model\data\WechatExpress;
|
|
use app\commom\model\data\WechatExpress;
|
|
use app\common\exception\BusinessException;
|
|
use app\common\exception\BusinessException;
|
|
|
|
+use app\common\facade\HttpClient;
|
|
|
|
+use think\Cache;
|
|
|
|
|
|
/**
|
|
/**
|
|
* 补充 小程序购物订单
|
|
* 补充 小程序购物订单
|
|
@@ -30,7 +32,6 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
} else {
|
|
} else {
|
|
$uploadParams = $orderShippingInfo->getShippingParams();
|
|
$uploadParams = $orderShippingInfo->getShippingParams();
|
|
}
|
|
}
|
|
-
|
|
|
|
// 设置消息跳转地址
|
|
// 设置消息跳转地址
|
|
$this->setMessageJumpPath();
|
|
$this->setMessageJumpPath();
|
|
|
|
|
|
@@ -54,10 +55,11 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
}
|
|
}
|
|
|
|
|
|
$params['upload_time'] = date(DATE_RFC3339);
|
|
$params['upload_time'] = date(DATE_RFC3339);
|
|
-
|
|
|
|
- \think\Log::error('发货信息录入' . json_encode($params));
|
|
|
|
|
|
+
|
|
|
|
+ \think\Log::info('发货信息录入参数' . json_encode($params));
|
|
|
|
+
|
|
$result = $this->uploadShippingInfo($params);
|
|
$result = $this->uploadShippingInfo($params);
|
|
-
|
|
|
|
|
|
+
|
|
if ($result['errcode'] != 0) {
|
|
if ($result['errcode'] != 0) {
|
|
throw new BusinessException('获取失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
|
|
throw new BusinessException('获取失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
|
|
}
|
|
}
|
|
@@ -79,7 +81,7 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
$access_token = $this->getAccessToken();
|
|
$access_token = $this->getAccessToken();
|
|
|
|
|
|
$add_template_url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info";
|
|
$add_template_url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info";
|
|
- $result = \addons\shopro\facade\HttpClient::request('post', $add_template_url, [
|
|
|
|
|
|
+ $result = HttpClient::request('post', $add_template_url, [
|
|
'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
|
|
'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
|
|
'query' => ["access_token" => $access_token['access_token']],
|
|
'query' => ["access_token" => $access_token['access_token']],
|
|
'headers' => ['Content-Type' => 'application/json']
|
|
'headers' => ['Content-Type' => 'application/json']
|
|
@@ -112,7 +114,7 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
format_log_error($e, 'checkAndSetMessageJumpPath', '自动设置微信小程序发货信息管理消息跳转路径失败');
|
|
format_log_error($e, 'checkAndSetMessageJumpPath', '自动设置微信小程序发货信息管理消息跳转路径失败');
|
|
if ($exception) {
|
|
if ($exception) {
|
|
// 抛出异常
|
|
// 抛出异常
|
|
- throw new ShoproException($e->getMessage());
|
|
|
|
|
|
+ throw new BusinessException($e->getMessage());
|
|
}
|
|
}
|
|
}
|
|
}
|
|
|
|
|
|
@@ -129,23 +131,23 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
public function isTradeManaged($is_force = false)
|
|
public function isTradeManaged($is_force = false)
|
|
{
|
|
{
|
|
$key = 'wechat:is_trade_managed';
|
|
$key = 'wechat:is_trade_managed';
|
|
- if (!$is_force && redis_cache('?' . $key)) {
|
|
|
|
- return redis_cache($key); // 直接返回是否有权限
|
|
|
|
|
|
+ if (!$is_force && Cache::get($key)) {
|
|
|
|
+ return Cache::get($key); // 直接返回是否有权限
|
|
}
|
|
}
|
|
|
|
|
|
$access_token = $this->getAccessToken();
|
|
$access_token = $this->getAccessToken();
|
|
$add_template_url = "https://api.weixin.qq.com/wxa/sec/order/is_trade_managed";
|
|
$add_template_url = "https://api.weixin.qq.com/wxa/sec/order/is_trade_managed";
|
|
|
|
|
|
- $mini_appid = sheep_config('shop.platform.WechatMiniProgram.app_id');
|
|
|
|
|
|
+ $mini_appid = shop_config('shop.platform.wechat_mini_program.app_id');
|
|
if (!$mini_appid) {
|
|
if (!$mini_appid) {
|
|
// 没有配置微信小程序参数
|
|
// 没有配置微信小程序参数
|
|
- throw new ShoproException('微信小程序发货管理查询失败,没有配置微信小程序');
|
|
|
|
|
|
+ throw new BusinessException('微信小程序发货管理查询失败,没有配置微信小程序');
|
|
}
|
|
}
|
|
|
|
|
|
$params = [
|
|
$params = [
|
|
'appid' => $mini_appid
|
|
'appid' => $mini_appid
|
|
];
|
|
];
|
|
- $result = \addons\shopro\facade\HttpClient::request('post', $add_template_url, [
|
|
|
|
|
|
+ $result = HttpClient::request('post', $add_template_url, [
|
|
'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
|
|
'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
|
|
'query' => ["access_token" => $access_token['access_token']],
|
|
'query' => ["access_token" => $access_token['access_token']],
|
|
'headers' => ['Content-Type' => 'application/json']
|
|
'headers' => ['Content-Type' => 'application/json']
|
|
@@ -156,12 +158,12 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
|
|
|
|
if ($result['errcode'] != 0 && $result['errcode'] != '48001') {
|
|
if ($result['errcode'] != 0 && $result['errcode'] != '48001') {
|
|
// 48001 时不抛出异常,当没有权限处理
|
|
// 48001 时不抛出异常,当没有权限处理
|
|
- throw new ShoproException('查询是否有微信发货信息管理权限失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
|
|
|
|
|
|
+ throw new BusinessException('查询是否有微信发货信息管理权限失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
|
|
}
|
|
}
|
|
|
|
|
|
$is_trade_managed = isset($result['is_trade_managed']) ? intval($result['is_trade_managed']) : 0;
|
|
$is_trade_managed = isset($result['is_trade_managed']) ? intval($result['is_trade_managed']) : 0;
|
|
|
|
|
|
- redis_cache($key, $is_trade_managed, 7200); // 缓存结果,两小时
|
|
|
|
|
|
+ Cache::set($key, $is_trade_managed, 7200); // 缓存结果,两小时
|
|
|
|
|
|
return $is_trade_managed;
|
|
return $is_trade_managed;
|
|
}
|
|
}
|
|
@@ -176,7 +178,7 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
*/
|
|
*/
|
|
public function setMessageJumpPath($is_force = false, $path = 'pages/order/detail?comein_type=wechat')
|
|
public function setMessageJumpPath($is_force = false, $path = 'pages/order/detail?comein_type=wechat')
|
|
{
|
|
{
|
|
- if (!$is_force && redis_cache('?wechat:set_message_jump_path')) {
|
|
|
|
|
|
+ if (!$is_force && cache('?wechat:set_message_jump_path')) {
|
|
// 已经设置过了,无需再次设置
|
|
// 已经设置过了,无需再次设置
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -187,7 +189,7 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
$params = [
|
|
$params = [
|
|
'path' => $path
|
|
'path' => $path
|
|
];
|
|
];
|
|
- $result = \addons\shopro\facade\HttpClient::request('post', $add_template_url, [
|
|
|
|
|
|
+ $result = HttpClient::request('post', $add_template_url, [
|
|
'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
|
|
'body' => json_encode($params, JSON_UNESCAPED_UNICODE),
|
|
'query' => ["access_token" => $access_token['access_token']],
|
|
'query' => ["access_token" => $access_token['access_token']],
|
|
'headers' => ['Content-Type' => 'application/json']
|
|
'headers' => ['Content-Type' => 'application/json']
|
|
@@ -197,14 +199,14 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
$result = json_decode($result, true);
|
|
$result = json_decode($result, true);
|
|
|
|
|
|
if ($result['errcode'] != 0) {
|
|
if ($result['errcode'] != 0) {
|
|
- throw new ShoproException('设置微信发货消息跳转地址失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
|
|
|
|
|
|
+ throw new BusinessException('设置微信发货消息跳转地址失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
|
|
}
|
|
}
|
|
|
|
|
|
if ($is_force) {
|
|
if ($is_force) {
|
|
// 充值订单发货时,清掉缓存
|
|
// 充值订单发货时,清掉缓存
|
|
- redis_cache('wechat:set_message_jump_path', null); // 清除缓存
|
|
|
|
|
|
+ cache('wechat:set_message_jump_path', null); // 清除缓存
|
|
} else {
|
|
} else {
|
|
- redis_cache('wechat:set_message_jump_path', time()); // 永久有效
|
|
|
|
|
|
+ cache('wechat:set_message_jump_path', time()); // 永久有效
|
|
}
|
|
}
|
|
|
|
|
|
return $result;
|
|
return $result;
|
|
@@ -220,7 +222,7 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
*/
|
|
*/
|
|
public function getDelivery($is_force = false)
|
|
public function getDelivery($is_force = false)
|
|
{
|
|
{
|
|
- if (!$is_force && redis_cache('?wechat:get_delivery_list')) {
|
|
|
|
|
|
+ if (!$is_force && cache('?wechat:get_delivery_list')) {
|
|
// 已经设置过了,无需再次设置
|
|
// 已经设置过了,无需再次设置
|
|
return true;
|
|
return true;
|
|
}
|
|
}
|
|
@@ -228,7 +230,7 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
$access_token = $this->getAccessToken();
|
|
$access_token = $this->getAccessToken();
|
|
$get_delivery_url = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/get_delivery_list";
|
|
$get_delivery_url = "https://api.weixin.qq.com/cgi-bin/express/delivery/open_msg/get_delivery_list";
|
|
|
|
|
|
- $result = \addons\shopro\facade\HttpClient::request('post', $get_delivery_url, [
|
|
|
|
|
|
+ $result = HttpClient::request('post', $get_delivery_url, [
|
|
'body' => '{}',
|
|
'body' => '{}',
|
|
'query' => ["access_token" => $access_token['access_token']],
|
|
'query' => ["access_token" => $access_token['access_token']],
|
|
'headers' => ['Content-Type' => 'application/json']
|
|
'headers' => ['Content-Type' => 'application/json']
|
|
@@ -238,7 +240,7 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
$result = json_decode($result, true);
|
|
$result = json_decode($result, true);
|
|
|
|
|
|
if ($result['errcode'] != 0) {
|
|
if ($result['errcode'] != 0) {
|
|
- throw new ShoproException('获取微信 delivery 列表失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
|
|
|
|
|
|
+ throw new BusinessException('获取微信 delivery 列表失败: errcode:' . $result['errcode'] . '; errmsg:' . $result['errmsg']);
|
|
}
|
|
}
|
|
|
|
|
|
// 存库
|
|
// 存库
|
|
@@ -257,7 +259,7 @@ class WechatMiniProgramShop extends EasywechatPlus
|
|
$wechatExpress->save($current);
|
|
$wechatExpress->save($current);
|
|
}
|
|
}
|
|
|
|
|
|
- redis_cache('wechat:get_delivery_list', time()); // 永久有效
|
|
|
|
|
|
+ cache('wechat:get_delivery_list', time()); // 永久有效
|
|
|
|
|
|
return $result;
|
|
return $result;
|
|
}
|
|
}
|