zory 1 settimana fa
parent
commit
15df15d7d1

+ 23 - 2
README.md

@@ -1,5 +1,5 @@
 # 交易小程序
-
+```angular2html
 composer require yzh52521/easyhttp
 composer require "linqiao/php-addtran:^0.1"
 composer require webman/event
@@ -21,4 +21,25 @@ composer require aliyuncs/oss-sdk-php
 composer require qcloud/cos-sdk-v5
 composer require qiniu/php-sdk
 composer require luckycmc/webman-province-city-area
-composer require tinywan/captcha:^2.1
+composer require tinywan/captcha:^2.1
+```
+
+## API核销流程
+
+#### 通过抖音订单ID获取encrypted_code
+```angular2html
+https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/life.capacity.fulfilment/certificate.query
+获取到 encrypted_code
+```
+
+### 发起核销
+```angular2html
+https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/life.capacity.fulfilment/certificate.verify
+
+{
+    "verify_token": "4600000194202606129883397878", // 可随机生成
+    "poi_id": "7644106137976965139", // POIID
+    "encrypted_codes": ["CgYIASAHKAESLgosV9U88cYt5F3q0PunWznwayRS5aK20VokyuBMWnPrWm1mvAmszlN02+Ks93AaAA=="], // 第一步获取的encrypted_code
+    "order_id": "1110177134099228984" // 订单ID
+}
+```

+ 54 - 0
app/controller/notify/Life.php

@@ -4,6 +4,9 @@ namespace app\controller\notify;
 
 use app\extra\basic\Base;
 use LinFly\Annotation\Attributes\Route\Controller;
+use LinFly\Annotation\Attributes\Route\PostMapping;
+use support\Request;
+use support\Response;
 
 
 /**
@@ -13,4 +16,55 @@ use LinFly\Annotation\Attributes\Route\Controller;
 class Life extends Base
 {
 
+
+    #[PostMapping("spi")]
+    public function getLifeSpi(Request $request): Response
+    {
+        try {
+            $param = $request->all();
+            echo getDateFull()."===自研应用回调===\n";
+            print_r($param);
+            return error("ddd");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
+
+    #[PostMapping("hook")]
+    public function getLifeHook(Request $request): Response
+    {
+        try {
+            $data = $request->all();
+            echo getDateFull()."===自研应用回调WebHook===\n";
+            print_r($data);
+            if (isset($data['event']) && $data['event'] == "verify_webhook") {
+                return json(['challenge' => $data['content']['challenge']]);
+            }
+            return error("ddd");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
+
+
+
+    #[PostMapping("mini")]
+    public function getMiniHook(Request $request): Response
+    {
+        try {
+            $data = $request->all();
+            echo getDateFull()."===小程序WebHook===\n";
+            print_r($data);
+            if (isset($data['event']) && $data['event'] == "verify_webhook") {
+                return json(['challenge' => $data['content']['challenge']]);
+            }
+            return error("ddd");
+        } catch (\Throwable $throwable) {
+            return error($throwable->getMessage());
+        }
+    }
+
 }

+ 2 - 2
app/extra/dyLife/data/BaseData.php

@@ -71,7 +71,6 @@ class BaseData extends BasicLife
         } else { // 多sku
 
         }
-        print_r($param);
         return $this->curlPostApi("goodlife/v1/goods/product/save/",$param);
     }
 
@@ -80,8 +79,9 @@ class BaseData extends BasicLife
      * 参数处理
      * @param string $key
      * @param array $data
+     * @return string
      */
-    protected function getProductAttrs(string $key = "",array $data = [])
+    protected function getProductAttrs(string $key = "",array $data = []): string
     {
         switch ($key)
         {

+ 67 - 0
app/extra/dyLife/data/OrderData.php

@@ -0,0 +1,67 @@
+<?php
+
+namespace app\extra\dyLife\data;
+
+use app\extra\dyLife\BasicLife;
+
+/**
+ * 订单相关
+ */
+class OrderData extends BasicLife
+{
+
+    /**
+     * 通过订单ID获取 encrypted_code
+     * https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/life.capacity.fulfilment/certificate.query
+     * @param string $orderId
+     * @param string $accountId
+     * data['certificates'][0]['encrypted_code']
+     * @return array
+     */
+    public function getCertificate(string $orderId = "",string $accountId = ""): array
+    {
+        $param = [
+            "account_id"    => $accountId,
+            "order_id"      => $orderId
+        ];
+        return $this->curlPostApi("goodlife/v1/fulfilment/certificate/query/",$param);
+    }
+
+    /**
+     * 发起核销
+     * https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/life.capacity.fulfilment/certificate.verify
+     * @param array $data
+     * data['verify_results'][0]
+     * certificate_id、verify_id
+     * @return array
+     */
+    public function verifyCertificate(array $data = []): array
+    {
+        $param = [
+            "account_id"        => $data['account_id'],
+            "verify_token"      => $data['pay_sn'],
+            "encrypted_codes"   => [$data['encrypted_code']],
+            "order_id"          => $data['order_id']
+        ];
+        return $this->curlPostApi("goodlife/v1/fulfilment/certificate/verify/",$param);
+    }
+
+    /**
+     * 撤销核销
+     * https://developer.open-douyin.com/docs/resource/zh-CN/local-life/develop/OpenAPI/general-capabilities/life.capacity.fulfilment/certificate.cancel
+     * @param array $data
+     * data['cancel_results'][0]
+     * result_code
+     * @return array
+     */
+    public function cancelCertificate(array $data = []): array
+    {
+        $param = [
+            "certificate_id"    => $data['certificate_id'],
+            "verify_id"         => $data['verify_id'],
+            "account_id"        => $data['account_id']
+        ];
+        return $this->curlPostApi("goodlife/v1/fulfilment/certificate/verify/",$param);
+    }
+
+}