- 我的小程序销售虚拟产品,发货使用订阅模板消息通知用户,当模板消息发送完成后,再调用微信的订单状态更新接口,将该订单在微信支付中的状态改为status=2,调用时报错。用deepseek问答,其回复申请API权限:
- 在API安全设置中,找到“API权限”或“API设置”。
- 检查是否已经开通了
/shop/order/update
接口的权限。 - 如果未开通,点击申请权限,按照提示提交申请。
===============
请问这个权限怎么申请,我在微信支付平台中找不到。这个权限可以申请吗?
================================
以下是代码段和日志
Log::record('订阅消息发送结果:' . json_encode($result));
// 如果订阅消息发送成功,调用 updateOrder 接口更新订单状态
if (isset($result['errcode']) && $result['errcode'] == 0) {
// 获取 access_token
try {
$accessToken = Wechat::getAccessToken();
} catch (\Exception $e) {
Log::record('获取 access_token 异常:' . $e->getMessage());
return ['errcode' => -1, 'errmsg' => '获取 access_token 失败'];
}
// 调用 updateOrder 接口
$updateResult = $this->updateOrderStatus($accessToken['access_token'], $message['out_trade_no'], $deliveryTime);
// 记录订单状态更新结果
Log::record('订单状态更新结果:' . json_encode($updateResult));
// 如果订单状态更新失败,返回错误信息
if (isset($updateResult['errcode']) && $updateResult['errcode'] != 0) {
Log::record('订单状态更新失败:' . json_encode($updateResult));
return ['errcode' => $updateResult['errcode'], 'errmsg' => $updateResult['errmsg']];
}
updateOrderStatus代码段:
$url = "https://api.weixin.qq.com/shop/order/update?access_token={$accessToken}";
// 请求数据
$postData = [
'order_id' => $orderId,
'status' => 2, // 2 表示已发货
'delivery_type' => 1, // 1 表示虚拟发货
'ship_done_time' => $deliveryTime // 发货完成时间
];
// 初始化 cURL
$ch = curl_init();以下省略
返回的日志信息:
[ 2025-01-17T14:57:36+08:00 ] 121.51.58.172 POST ******/addons/unidrink/pay/notify
[运行时间:0.904048s] [吞吐率:1.11req/s] [内存消耗:7,375.57kb] [文件加载:306]
[ log ] 支付回调信息:result:{"return_code":"SUCCESS","return_msg":"OK","result_code":"SUCCESS","mch_id":"165******39","appid":"wxef6f*******6240","openid":"oxmm************4qmS8VIbHVmM","is_subscribe":"N","trade_type":"JSAPI","trade_state":"SUCCESS","bank_type":"CCB_DEBIT","total_fee":"20","fee_type":"CNY","cash_fee":"20","cash_fee_type":"CNY","transaction_id":"4200002531202501178777492873","out_trade_no":"121","attach":null,"time_end":"20250117145734","trade_state_desc":"\u652f\u4ed8\u6210\u529f","nonce_str":"ljim4iSEG6XUT8Mn","sign":"023B03B6***********48952791"}
[ log ] 订阅消息发送参数:{"openId":"oxmm**************bHVmM","templateId":"I4SQMU-L*********gKyAaKN39-Zs","data":{"character_string1":{"value":"121"},"character_string2":{"value":"4200002531202501178777492873"},"time3":{"value":"2025-01-17 14:57:35"},"thing4":{"value":"\u865a\u62df\u53d1\u8d27"}}}
[ log ] 订阅消息发送结果:{"errcode":0,"errmsg":"ok","msgid":3816896917370667008}
[ log ] response:{"errcode":48001,"errmsg":"api unauthorized rid: 6789ff60-05da4450-4d6b0d8b"}
[ log ] 订单状态更新结果:{"errcode":48001,"errmsg":"api unauthorized rid: 6789ff60-05da4450-4d6b0d8b"}
[ log ] 订单状态更新失败:{"errcode":48001,"errmsg":"api unauthorized rid: 6789ff60-05da4450-4d6b0d8b"}