From 6d77498105c7d0dcf16cb5819f9b5d5826f5a353 Mon Sep 17 00:00:00 2001 From: mkm <727897186@qq.com> Date: Tue, 14 May 2024 17:23:51 +0800 Subject: [PATCH] =?UTF-8?q?=E6=9B=B4=E6=96=B0=E4=BB=A3=E7=A0=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../service/wechat/WeChatMnpService.php | 38 +++++++++++++++---- 1 file changed, 30 insertions(+), 8 deletions(-) diff --git a/app/common/service/wechat/WeChatMnpService.php b/app/common/service/wechat/WeChatMnpService.php index 6883ec6..a4242c2 100644 --- a/app/common/service/wechat/WeChatMnpService.php +++ b/app/common/service/wechat/WeChatMnpService.php @@ -16,7 +16,7 @@ namespace app\common\service\wechat; use EasyWeChat\Kernel\Exceptions\Exception; use EasyWeChat\MiniApp\Application; - +use support\Cache; /** * 微信功能类 @@ -102,19 +102,41 @@ class WeChatMnpService */ public function delivery() { - $accessToken = $this->app->getAccessToken(); - $token = $accessToken->getToken(); - return $this->app->getClient()->postJson('product/delivery/send?access_token=' . $token, [ - 'order_id' => 'PF171564998868869065', + $token=Cache::get('mmp_access_token'); + if(!$token){ + $token=$this->getStableAccessToken(); + } + return $this->app->getClient()->post("wxa/sec/order/upload_shipping_info?access_token=$token", [ + 'order_key' =>[ + 'order_number_type'=>1, + 'out_trade_no'=>'PF171564998868869065' + ], + 'logistics_type'=>4, + 'delivery_mode'=>'UNIFIED_DELIVERY', + 'shipping_list'=>[ + ['item_desc'=>'商品'] + ], + 'upload_time'=>date('Y-m-d H:i:s'), + 'payer'=>[ + 'openid'=>'onoIP7VVWhCZSWX8zazdNS4KazPE' + ] ])->toArray(); } /** * @notes 获取access_token * @return string */ - public function AccessToken() + public function getStableAccessToken() { - $accessToken = $this->app->getAccessToken(); - return $accessToken->getToken(); // string + $token =$this->app->getClient()->postJson("cgi-bin/stable_token", [ + 'grant_type'=>'client_credential', + 'appid'=>$this->config['app_id'], + 'secret'=>$this->config['secret'], + 'force_refresh'=>true + ])->toArray(); + if($token['access_token']){ + Cache::set('mmp_access_token',$token['access_token'],$token['expires_in']); + return $token['access_token']; + } } }