Эх сурвалжийг харах

feat(lakala): 更新命名空间并添加分账服务
- 更新了 V2LakalaApi 中的命名空间引用
- 为 V2ModelResponse 和 ModelResponse 添加了 headers 和 originalText 属性
- 引入了 ObjectSerializer 类以支持模型序列化- 新增 LedgerService用于处理分账接收方创建申请- 添加了对应的测试类 LedgerServiceTest 来验证功能实现
- 优化了 openssl_free_key 的调用条件以兼容 PHP 8.0 以上版本

runphp 4 сар өмнө
parent
commit
cae8dffa48

+ 4 - 4
src/OpenAPISDK/V2/Api/V2LakalaApi.php

@@ -60,7 +60,7 @@ class V2LakalaApi
     }
 
     public function tradeApi($resourcePath, V2ModelRequest $v2ModelRequest,
-                                            $returnType = '\Lakala\OpenAPISDK\V2\Model\V2ModelResponse',
+                                            $returnType = '\SixShop\Lakala\OpenAPISDK\V2\Model\V2ModelResponse',
                                             $method = 'POST')
     {
         $headerParams = [];
@@ -77,7 +77,7 @@ class V2LakalaApi
     }
 
     public function apiWithBody($resourcePath, $httpBody, $headerParams = [], $method = 'POST',
-                                               $returnType = '\Lakala\OpenAPISDK\V2\Model\V2ModelResponse')
+                                               $returnType = '\SixShop\Lakala\OpenAPISDK\V2\Model\V2ModelResponse')
     {
         $this->setResourcePath($resourcePath);
 
@@ -193,7 +193,7 @@ class V2LakalaApi
     {
         $options = [
             'timeout' => 10,
-            'respond_type' => \Lakala\OpenAPISDK\V2\Util\V2HttpService::RESPOND_TYPE_ARRAY,
+            'respond_type' => \SixShop\Lakala\OpenAPISDK\V2\Util\V2HttpService::RESPOND_TYPE_ARRAY,
         ];
 
         return $options;
@@ -241,7 +241,7 @@ class V2LakalaApi
             throw new V2ApiException('获取私钥失败');
         }
         $res = openssl_sign($content, $sign, $privateKey, OPENSSL_ALGO_SHA256);
-        if (function_exists('openssl_free_key')) {
+        if (function_exists('openssl_free_key')  && version_compare(PHP_VERSION, '8.0.0', '<')) {
             openssl_free_key($privateKey);
         }
         if (!$res) {

+ 2 - 0
src/OpenAPISDK/V2/Model/V2ModelResponse.php

@@ -21,6 +21,8 @@ class V2ModelResponse {
     protected $respId;
     protected $ver;
     protected $respData;
+    protected $headers;
+    protected $originalText;
     
     public function setRetCode($retCode)
     {

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

@@ -11,6 +11,8 @@
 
 namespace SixShop\Lakala\OpenAPISDK\V3\Model;
 
+use SixShop\Lakala\OpenAPISDK\V3\ObjectSerializer;
+
 class ModelResponse {
     // 返回业务代码	M	String(8)	返回业务代码(000000为成功,其余按照错误信息来定)
     /**

+ 2 - 0
src/OpenAPISDK/V3/Model/ModelTradeNotify.php

@@ -13,6 +13,8 @@
 
 namespace SixShop\Lakala\OpenAPISDK\V3\Model;
 
+use SixShop\Lakala\OpenAPISDK\V3\ObjectSerializer;
+
 class ModelTradeNotify {
     // 响应头信息
     protected $headers;

+ 48 - 0
src/Service/LedgerService.php

@@ -0,0 +1,48 @@
+<?php
+declare(strict_types=1);
+namespace SixShop\Lakala\Service;
+
+use SixShop\Lakala\Config;
+use SixShop\Lakala\OpenAPISDK\V2\Api\V2LakalaApi;
+use SixShop\Lakala\OpenAPISDK\V2\Model\V2ModelRequest;
+
+/**
+ * LedgerService
+ */
+class LedgerService
+{
+    private V2LakalaApi $v2LakalaApi;
+    public function __construct(Config $config)
+    {
+        $this->v2LakalaApi = new V2LakalaApi($config->getV2Config());
+    }
+
+    /**
+     * 分账接收方创建申请
+     *
+     * @link https://o.lakala.com/#/home/document/detail?id=382
+     */
+    public function applyLedgerReceiver()
+    {
+        $request = new V2ModelRequest();
+        $request->setReqData([
+
+        ]);
+        $response = $this->v2LakalaApi->tradeApi('/api/v2/mms/openApi/ledger/applyLedgerReceiver', $request);
+      dd($response);
+        if ($response->getRespData()) {
+            print_r($response->getRespData());
+            print_r($response->getAccRespFields());
+        }
+        else {
+            print_r($response);
+        }
+        echo $response->getRetCode();
+
+        # 响应头信息
+        print_r($response->getHeaders());
+
+        # 响应原文
+        echo $response->getOriginalText();
+    }
+}

+ 19 - 0
tests/Service/LedgerServiceTest.php

@@ -0,0 +1,19 @@
+<?php
+declare(strict_types=1);
+namespace SixShop\Lakala\Service;
+
+use PHPUnit\Framework\TestCase;
+
+class LedgerServiceTest extends TestCase
+{
+    private LedgerService $ledgerService;
+    protected function setUp(): void
+    {
+        $this->ledgerService = app(LedgerService::class);
+    }
+
+    public function testApplyLedgerReceiver():void
+    {
+        $this->ledgerService->applyLedgerReceiver();
+    }
+}