Explorar o código

fix(miniapp): 修复小程序运单查询逻辑并优化代码格式

- 添加了对运单不存在错误码931023的特殊处理
- 使用自定义异常抛出运单不存在的错误信息
- 统一了参数类型的空格格式化规范
- 优化了错误处理流程,区分不同错误码的处理方式
runphp hai 1 semana
pai
achega
8be00d7c98
Modificáronse 1 ficheiros con 7 adicións e 4 borrados
  1. 7 4
      src/Trait/MiniAppTrait.php

+ 7 - 4
src/Trait/MiniAppTrait.php

@@ -5,6 +5,7 @@ namespace SixShop\WechatPay\Trait;
 use SixShop\Wechat\Facade\WechatUser;
 use SixShop\WechatPay\Facade\WechatPayBuilder;
 use think\facade\Log;
+use function SixShop\Core\throw_logic_exception;
 
 trait MiniAppTrait
 {
@@ -53,7 +54,7 @@ trait MiniAppTrait
         string $trackingNo = '',
         string $expressCompany = '',
         string $receiverContact = '',
-        int $logisticsType = 1,
+        int    $logisticsType = 1,
         bool   $failException = true,
     ): array
     {
@@ -104,11 +105,11 @@ trait MiniAppTrait
      * @see https://developers.weixin.qq.com/miniprogram/dev/platform-capabilities/industry/express/business/express_search.html
      */
     private function waybillToken(
-        int $userID,
+        int    $userID,
         string $receiverPhone,
         string $waybillID,
         string $deliveryID,
-        array $detailList,
+        array  $detailList,
         bool   $failException = true
     ): array
     {
@@ -126,7 +127,9 @@ trait MiniAppTrait
         $response = WechatPayBuilder::getMiniApp()->getClient()->postJson('cgi-bin/express/delivery/open_msg/trace_waybill', $data);
         $result = $response->getContent();
         $result = json_decode($result, true);
-        if ($result['errcode'] !== 0) {
+        if ($result['errcode'] == 931023) {
+            throw_logic_exception("运单不存在:".$waybillID);
+        } else if ($result['errcode'] !== 0) {
             Log::error('获取运单token失败{errcode}:{errmsg}:' . json_encode($data), $result);
             $failException && throw new \RuntimeException($result['errmsg'], $result['errcode']);
         }