Przeglądaj źródła

test接口 测试

sunxbiao 1 rok temu
rodzic
commit
ced0629c3b

+ 61 - 0
app/controller/api/store/merchant/Taskorderlianc.php

@@ -13,6 +13,67 @@ use think\Request;
13 13
 class Taskorderlianc
14 14
 {
15 15
 
16
+    private const API_KEY = "EXTERNAL_SYSTEM_B_KEY";
17
+    private const API_SECRET = "STRONG_SECRET_123456";
18
+    private const GATEWAY_URL = "http://localhost:9002";
19
+
20
+    public function getUserPoints()
21
+    {
22
+        $timestamp = round(microtime(true) * 1000);  // 获取当前时间戳(毫秒)
23
+        $signature = $this->generateSignature(self::API_KEY, $timestamp);
24
+
25
+        // 设置请求头
26
+        $headers = [
27
+            "X-API-KEY: " . self::API_KEY,
28
+            "X-TIMESTAMP: " . $timestamp,
29
+            "X-SIGNATURE: " . $signature,
30
+            "Content-Type: application/json"
31
+        ];
32
+        // 请求的 POST 数据(例如用户信息)
33
+        $postData = [
34
+            'pm' => 1,
35
+            'rewardScore' => 5,
36
+            'orderId' => 'johndoe@example.com',
37
+            'orderType' => '1234567890',
38
+        ];
39
+
40
+
41
+        // 请求 URL
42
+        // $url = self::GATEWAY_URL . "/external/userCenter_service/user/getUserList?uid=1592";
43
+        // 请求 URL POST
44
+        $url = self::GATEWAY_URL . "/external/userCenter_service/user/1592/score";
45
+
46
+
47
+        // // 使用 cURL 发起 GET 请求
48
+        // $ch = curl_init();
49
+        // curl_setopt($ch, CURLOPT_URL, $url);
50
+        // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
51
+        // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
52
+        // $response = curl_exec($ch);
53
+        // curl_close($ch);
54
+
55
+        // 使用 cURL 发起 POST 请求
56
+        $ch = curl_init();
57
+        curl_setopt($ch, CURLOPT_URL, $url);
58
+        curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
59
+        curl_setopt($ch, CURLOPT_POST, true);
60
+        curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
61
+        curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData)); // 转换为 JSON 字符串
62
+        $response = curl_exec($ch);
63
+        curl_close($ch);
64
+
65
+        // 解析返回的 JSON 数据
66
+        $responseData = json_decode($response, true);
67
+
68
+        return json($responseData); // 返回用户积分,默认值为 0
69
+    }
70
+
71
+    private function generateSignature($apiKey, $timestamp)
72
+    {
73
+        $data = $apiKey . "|" . $timestamp . "|" . self::API_SECRET;
74
+        return md5($data); // 返回 MD5 签名
75
+    }
76
+
16 77
     /**
17 78
      * 会员升级
18 79
      */

+ 1 - 0
route/api.php

@@ -1309,6 +1309,7 @@ Route::get('test_hehuoren_zero', 'api.store.merchant.TaskZeroLinePartnerProfits/
1309 1309
 Route::get('test_guquan', 'api.store.merchant.Taskorderguquan/lst6');
1310 1310
 Route::get('test_lianchuang', 'api.store.merchant.Taskorderlianc/lst2');
1311 1311
 Route::get('test_lianchuang_zero', 'api.store.merchant.TaskZeroLineOrderLianc/lst2');
1312
+Route::get('test_external', 'api.store.merchant.Taskorderlianc/getUserPoints');
1312 1313
 Route::any('/share', function () {
1313 1314
     return view(app()->getRootPath() . 'public/share/register.html');
1314 1315
 });