This commit is contained in:
mkm 2024-05-14 17:30:17 +08:00
parent 6d77498105
commit ab8c406c12
2 changed files with 14 additions and 16 deletions

View File

@ -7,6 +7,7 @@ use app\admin\logic\tools\GeneratorLogic;
use app\common\service\pay\PayService; use app\common\service\pay\PayService;
use app\common\service\wechat\WeChatMnpService; use app\common\service\wechat\WeChatMnpService;
use app\common\service\wechat\WeChatOaService; use app\common\service\wechat\WeChatOaService;
use DateTime;
use Webman\Config; use Webman\Config;
use Webman\RedisQueue\Redis; use Webman\RedisQueue\Redis;
use Yansongda\Pay\Pay; use Yansongda\Pay\Pay;
@ -19,7 +20,7 @@ class IndexController extends BaseApiController
public function index() public function index()
{ {
$app=new WeChatMnpService(); $app=new WeChatMnpService();
$a= $app->delivery(); $a= $app->delivery('PF171564998868869065');
d($a); d($a);
$queue = 'send-mail'; $queue = 'send-mail';
// 数据,可以直接传数组,无需序列化 // 数据,可以直接传数组,无需序列化

View File

@ -13,7 +13,7 @@
// +---------------------------------------------------------------------- // +----------------------------------------------------------------------
namespace app\common\service\wechat; namespace app\common\service\wechat;
use DateTime;
use EasyWeChat\Kernel\Exceptions\Exception; use EasyWeChat\Kernel\Exceptions\Exception;
use EasyWeChat\MiniApp\Application; use EasyWeChat\MiniApp\Application;
use support\Cache; use support\Cache;
@ -100,23 +100,25 @@ class WeChatMnpService
/** /**
* @notes 发货 * @notes 发货
*/ */
public function delivery() public function delivery($order_id)
{ {
$token=Cache::get('mmp_access_token'); $token=Cache::get('mmp_access_token');
if(!$token){ if(!$token){
$token=$this->getStableAccessToken(); $token=$this->getAccessToken();
} }
$dateTime = new DateTime(date('Y-m-d H:i:s'));
$formattedDateTime = $dateTime->format('Y-m-d\TH:i:s.uP');
return $this->app->getClient()->post("wxa/sec/order/upload_shipping_info?access_token=$token", [ return $this->app->getClient()->post("wxa/sec/order/upload_shipping_info?access_token=$token", [
'order_key' =>[ 'order_key' =>[
'order_number_type'=>1, 'order_number_type'=>1,
'out_trade_no'=>'PF171564998868869065' 'out_trade_no'=>$order_id
], ],
'logistics_type'=>4, 'logistics_type'=>4,
'delivery_mode'=>'UNIFIED_DELIVERY', 'delivery_mode'=>'UNIFIED_DELIVERY',
'shipping_list'=>[ 'shipping_list'=>[
['item_desc'=>'商品'] ['item_desc'=>'商品']
], ],
'upload_time'=>date('Y-m-d H:i:s'), 'upload_time'=>$formattedDateTime,
'payer'=>[ 'payer'=>[
'openid'=>'onoIP7VVWhCZSWX8zazdNS4KazPE' 'openid'=>'onoIP7VVWhCZSWX8zazdNS4KazPE'
] ]
@ -126,17 +128,12 @@ class WeChatMnpService
* @notes 获取access_token * @notes 获取access_token
* @return string * @return string
*/ */
public function getStableAccessToken() public function getAccessToken()
{ {
$token =$this->app->getClient()->postJson("cgi-bin/stable_token", [ $token=$this->app->getAccessToken()->getToken();
'grant_type'=>'client_credential', if($token){
'appid'=>$this->config['app_id'], Cache::set('mmp_access_token',$token,7200);
'secret'=>$this->config['secret'], return $token;
'force_refresh'=>true
])->toArray();
if($token['access_token']){
Cache::set('mmp_access_token',$token['access_token'],$token['expires_in']);
return $token['access_token'];
} }
} }
} }