Browse Source

feat(lakala): 更新交易服务配置与序列化字段- 修改 LocationInfo 序列化字段名格式为 snake_case
- 更新 ModelResponse 的 jsonSerialize 方法返回类型声明
- 修复 TransactionService 中商户号和订单号设置逻辑
- 设置微信子应用 ID 和用户 ID 为实际测试值
- 根据总金额动态设置商品详情价格和数量
- 在 Config 类中添加 merchant_no 属性注释- 更新测试用例中的请求 IP 地址

runphp 4 months ago
parent
commit
66cc38b076

+ 1 - 0
src/Config.php

@@ -7,6 +7,7 @@ use SixShop\Lakala\OpenAPISDK\V3\Configuration;
 use SixShop\System\Trait\ConfigTrait;
 
 /**
+ * @property string $merchant_no 商户ID
  * @property string $term_no 终端号
  * @property string $notify_url 商户通知地址
  * @property string $complete_notify_url 收货确认通知地址

+ 2 - 2
src/Dto/LocationInfo.php

@@ -28,8 +28,8 @@ class LocationInfo implements \JsonSerializable
     public function jsonSerialize(): array
     {
         return [
-            'requestIP' => $this->requestIP,
-            'baseStation' => $this->baseStation,
+            'request_ip' => $this->requestIP,
+            'base_station' => $this->baseStation,
             'location' => $this->location
         ];
     }

+ 2 - 1
src/OpenAPISDK/V3/Model/ModelResponse.php

@@ -107,7 +107,8 @@ class ModelResponse {
         return $this->originalText;
     }
 
-    public function jsonSerialize()
+    #[\ReturnTypeWillChange]
+    public function jsonSerialize(): mixed
     {
        return ObjectSerializer::sanitizeForSerialization($this);
     }

+ 7 - 7
src/Service/TransactionService.php

@@ -54,9 +54,9 @@ class TransactionService
     {
         $request = new TransPreorderRequest();
 
-        $request->setMerchantNo($outTradeNo);
+        $request->setMerchantNo($this->config->merchant_no);
         $request->setTermNo($this->config->term_no);
-        $request->setOutTradeNo(date('YmdHis'));
+        $request->setOutTradeNo($outTradeNo);
         $request->setAccountType($accountType);
         $request->setTransType($transType);
         $totalAmount = round($totalAmount * 100, 0);
@@ -77,8 +77,8 @@ class TransactionService
         // 微信主扫场景 - 账户端业务信息
         $acc_busi_fields = new TradePreorderWechaAccBusiFields();
         $acc_busi_fields->setTimeoutExpress('');
-        $acc_busi_fields->setSubAppid('');
-        $acc_busi_fields->setUserId('2843132323');
+        $acc_busi_fields->setSubAppid('wx1308d811d01639eb');
+        $acc_busi_fields->setUserId('oPuRO15wmxv3AwRyEznRfuDLehrk');
         $acc_busi_fields->setDetail('');
         $acc_busi_fields->setGoodsTag('');
         $acc_busi_fields->setAttach('');
@@ -88,15 +88,15 @@ class TransactionService
         $acc_busi_fields->setLimitPayer('');
 
         $detail = new TradePreorderWechaDetail();
-        $detail->setCostPrice('100');
+        $detail->setCostPrice($totalAmount);
         $detail->setReceiptId('');
 
         $goods_detail = new TradePreorderWechaGoodsDetail();
         $goods_detail->setGoodsId('3452234');
         $goods_detail->setWxpayGoodsId('');
         $goods_detail->setGoodsName('');
-        $goods_detail->setQuantity('');
-        $goods_detail->setPrice('');
+        $goods_detail->setQuantity(1);
+        $goods_detail->setPrice($totalAmount);
 
         $detail->setGoodsDetail([$goods_detail]);
 

+ 1 - 1
tests/Service/TransactionServiceTest.php

@@ -19,7 +19,7 @@ class TransactionServiceTest extends TestCase
         $this->transactionService->preOrder(
             outTradeNo: generate_number(NumberBizEnum::ORDER_PAY),
             totalAmount: .01,
-            locationInfo: new LocationInfo(requestIP: '127.0.0.1'),
+            locationInfo: new LocationInfo(requestIP: '183.214.109.50'),
             subject: '测试订单',
         );
     }