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

View File

@ -13,7 +13,7 @@
// +----------------------------------------------------------------------
namespace app\common\service\wechat;
use DateTime;
use EasyWeChat\Kernel\Exceptions\Exception;
use EasyWeChat\MiniApp\Application;
use support\Cache;
@ -100,23 +100,25 @@ class WeChatMnpService
/**
* @notes 发货
*/
public function delivery()
public function delivery($order_id)
{
$token=Cache::get('mmp_access_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", [
'order_key' =>[
'order_number_type'=>1,
'out_trade_no'=>'PF171564998868869065'
'out_trade_no'=>$order_id
],
'logistics_type'=>4,
'delivery_mode'=>'UNIFIED_DELIVERY',
'shipping_list'=>[
['item_desc'=>'商品']
],
'upload_time'=>date('Y-m-d H:i:s'),
'upload_time'=>$formattedDateTime,
'payer'=>[
'openid'=>'onoIP7VVWhCZSWX8zazdNS4KazPE'
]
@ -126,17 +128,12 @@ class WeChatMnpService
* @notes 获取access_token
* @return string
*/
public function getStableAccessToken()
public function getAccessToken()
{
$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'];
$token=$this->app->getAccessToken()->getToken();
if($token){
Cache::set('mmp_access_token',$token,7200);
return $token;
}
}
}