diff --git a/app/api/controller/IndexController.php b/app/api/controller/IndexController.php index c19cca0..f2c949e 100644 --- a/app/api/controller/IndexController.php +++ b/app/api/controller/IndexController.php @@ -19,9 +19,8 @@ class IndexController extends BaseApiController public function index() { - $app=new WeChatMnpService(); - $a= $app->delivery('PF171564998868869065'); - d($a); + + d(config('payment.wechat.default.mch_id')); $queue = 'send-mail'; // 数据,可以直接传数组,无需序列化 $data = ['to' => 'tom@gmail.com', 'content' => 'hello']; diff --git a/app/common/logic/PayNotifyLogic.php b/app/common/logic/PayNotifyLogic.php index f8ebae7..e2d8f51 100644 --- a/app/common/logic/PayNotifyLogic.php +++ b/app/common/logic/PayNotifyLogic.php @@ -9,6 +9,7 @@ use app\common\model\recharge\RechargeOrder; use app\common\model\retail\Cashierclass; use app\common\model\user\User; use app\common\service\PushService; +use app\common\service\wechat\WeChatMnpService; use support\Log; use think\facade\Db; @@ -72,6 +73,9 @@ class PayNotifyLogic extends BaseLogic } } PushService::push('cash_register_'.$order['user_id'], $order['user_id'], '您有一笔订单已支付'); + if(isset($orderSn,$extra['payer']['openid'])){ + (new WeChatMnpService)->delivery($orderSn,$extra['payer']['openid']); + } return true; } diff --git a/app/common/service/wechat/WeChatMnpService.php b/app/common/service/wechat/WeChatMnpService.php index 7ce2851..5d9bc9b 100644 --- a/app/common/service/wechat/WeChatMnpService.php +++ b/app/common/service/wechat/WeChatMnpService.php @@ -100,7 +100,7 @@ class WeChatMnpService /** * @notes 发货 */ - public function delivery($order_id) + public function delivery($order_id,$openid) { $token=Cache::get('mmp_access_token'); if(!$token){ @@ -108,10 +108,11 @@ class WeChatMnpService } $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()->postJson("wxa/sec/order/upload_shipping_info?access_token=$token", [ 'order_key' =>[ 'order_number_type'=>1, - 'out_trade_no'=>$order_id + 'out_trade_no'=>$order_id, + 'mchid'=>config('payment.wechat.default.mch_id') ], 'logistics_type'=>4, 'delivery_mode'=>'UNIFIED_DELIVERY', @@ -120,7 +121,7 @@ class WeChatMnpService ], 'upload_time'=>$formattedDateTime, 'payer'=>[ - 'openid'=>'onoIP7VVWhCZSWX8zazdNS4KazPE' + 'openid'=>$openid ] ])->toArray(); } @@ -134,6 +135,8 @@ class WeChatMnpService if($token){ Cache::set('mmp_access_token',$token,7200); return $token; + }else{ + throw new Exception('获取access_token失败'); } } }