6
0
Fork 0

微信支付 发货信息

base
panliang 2026-06-29 19:38:18 +08:00
parent 3197244f6e
commit f98aed8153
2 changed files with 30 additions and 23 deletions

View File

@ -95,29 +95,36 @@ class PayService
} }
// 订单支付成功, 调用发货信息API // 订单支付成功, 调用发货信息API
if ($userId) { try {
$socialite = SocialiteUser::where('user_id', $userId)->where('socialite_type', SocialiteType::WechatMiniProgram)->first(); if (!$userId) {
if ($socialite) { throw new BizException("未找到userId");
$openid = $socialite->socialite_id;
if ($openid) {
$data = [
"order_key" => [
"order_number_type" => 1,
"out_trade_no" => $payLog->pay_sn,
],
"logistics_type" => 4,
"delivery_mode" => 1,
"shipping_list" => [
"item_desc" => "定制服务"
],
"upload_time" => $payLog->pay_at,
"payer" => [
"openid" => $openid
]
];
WxMpService::make()->uploadShippingInfo($data);
}
} }
$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" => [
"order_number_type" => 1,
"out_trade_no" => $payLog->pay_sn,
],
"logistics_type" => 4,
"delivery_mode" => 1,
"shipping_list" => [
"item_desc" => "定制服务"
],
"upload_time" => $payLog->pay_at->format('Y-m-d H:i:s'),
"payer" => [
"openid" => $openid
]
];
WxMpService::make()->uploadShippingInfo($data);
} catch (\Exception $e) {
logger()->error("微信小程序-发货信息录入, " . $e->getMessage(), ['pay_log_id' => $payLog->id]);
} }
return $payLog; return $payLog;

View File

@ -29,7 +29,7 @@ class WxMpService
$result = $response->json(); $result = $response->json();
$code = data_get($result, "errcode"); $code = data_get($result, "errcode");
if ($code != 0) { if ($code != 0) {
throw new BizException("微信小程序-发货信息录入, 失败: (".$code.")" . data_get($result, "errmsg")); throw new BizException("失败: (".$code.")" . data_get($result, "errmsg"));
} }
} }
} }