6
0
Fork 0
panliang 2026-06-29 21:07:52 +08:00
parent 8d89ba1a5f
commit 79434da3f1
2 changed files with 38 additions and 38 deletions

View File

@ -6,6 +6,7 @@ use App\Enums\OfflineOrderStatus;
use App\Enums\SocialiteType;
use App\Exceptions\BizException;
use App\Exceptions\InvalidPaySerialNumberException;
use App\Jobs\UploadShippingInfoJob;
use App\Models\PayLog;
use App\Models\{OfflineOrder, Order, OrderPre, SocialiteUser};
@ -94,43 +95,41 @@ class PayService
(new \App\Services\VipService())->success($payable, ['pay_at' => $payLog->pay_at]);
}
// 延迟1分钟执行, 不然会出现错误信息: (10060001)支付单不存在
sleep(60);
// 订单支付成功, 调用发货信息API
try {
if (!$userId) {
throw new BizException("未找到userId");
}
$socialite = SocialiteUser::where('user_id', $userId)->where('socialite_type', SocialiteType::WechatMiniProgram)->first();
if (!$socialite) {
throw new BizException("未找到 SocialiteUser 记录, userId: " . $userId);
}
$openid = $socialite->socialite_id;
if (!$openid) {
throw new BizException("未找到 openid, userId: " . $userId);
}
$data = [
"order_key" => [
// "mchid" => config("wechat.payment.sub.mch_id"),
// "out_trade_no" => $payLog->pay_sn,
"order_number_type" => 2,
"transaction_id" => $payLog->out_trade_no,
],
"logistics_type" => 4,
"delivery_mode" => 1,
"shipping_list" => [
["item_desc" => "定制服务"]
],
"upload_time" => $payLog->pay_at->format('Y-m-d\TH:i:s.vP'),
"payer" => [
"openid" => $openid
]
];
logger("微信小程序-发货信息录入", $data);
WxMpService::make()->uploadShippingInfo($data);
} catch (\Exception $e) {
logger()->error("微信小程序-发货信息录入, " . $e->getMessage(), ['pay_log_id' => $payLog->id]);
}
// TODO 延迟1分钟执行, 不然会出现错误信息: (10060001)支付单不存在
// TODO 订单支付成功, 调用发货信息API
// try {
// if (!$userId) {
// throw new BizException("未找到userId");
// }
// $socialite = SocialiteUser::where('user_id', $userId)->where('socialite_type', SocialiteType::WechatMiniProgram)->first();
// if (!$socialite) {
// throw new BizException("未找到 SocialiteUser 记录, userId: " . $userId);
// }
// $openid = $socialite->socialite_id;
// if (!$openid) {
// throw new BizException("未找到 openid, userId: " . $userId);
// }
// $data = [
// "order_key" => [
// // "mchid" => config("wechat.payment.sub.mch_id"),
// // "out_trade_no" => $payLog->pay_sn,
// "order_number_type" => 2,
// "transaction_id" => $payLog->out_trade_no,
// ],
// "logistics_type" => 4,
// "delivery_mode" => 1,
// "shipping_list" => [
// ["item_desc" => "定制服务"]
// ],
// "upload_time" => $payLog->pay_at->format('Y-m-d\TH:i:s.vP'),
// "payer" => [
// "openid" => $openid
// ]
// ];
// WxMpService::make()->uploadShippingInfo($data);
// } catch (\Exception $e) {
// logger()->error("微信小程序-发货信息录入, " . $e->getMessage(), ['pay_log_id' => $payLog->id]);
// }
return $payLog;
}

View File

@ -19,6 +19,7 @@ class WxMpService
*/
public function uploadShippingInfo(array $data)
{
logger("微信小程序-发货信息录入, 参数", $data);
$app = Factory::miniProgram(config('wechat.mini_program.default'));
$accessToken = $app->access_token->getToken()['access_token'];
$url = "https://api.weixin.qq.com/wxa/sec/order/upload_shipping_info?access_token=" . $accessToken;
@ -26,7 +27,7 @@ class WxMpService
$response->throw();
$result = $response->json();
logger("微信小程序-发货信息录入", $result);
logger("微信小程序-发货信息录入, 结果", $result);
$code = data_get($result, "errcode");
if ($code != 0) {
throw new BizException("失败: (".$code.")" . data_get($result, "errmsg"));