|
|
@@ -13,6 +13,72 @@ 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
|
+ $postData = [
|
|
|
40
|
+ 'uid' => 1592,
|
|
|
41
|
+ 'sex' => 2,
|
|
|
42
|
+ 'spreadUid' => 767
|
|
|
43
|
+ ];
|
|
|
44
|
+
|
|
|
45
|
+
|
|
|
46
|
+ // 请求 URL
|
|
|
47
|
+ // $url = self::GATEWAY_URL . "/external/userCenter_service/user/getUserList?uid=1592";
|
|
|
48
|
+ // 请求 URL POST
|
|
|
49
|
+ $url = self::GATEWAY_URL . "/external/userCenter_service/user/updateUserInfo";
|
|
|
50
|
+
|
|
|
51
|
+
|
|
|
52
|
+ // // 使用 cURL 发起 GET 请求
|
|
|
53
|
+ // $ch = curl_init();
|
|
|
54
|
+ // curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
55
|
+ // curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
56
|
+ // curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
57
|
+ // $response = curl_exec($ch);
|
|
|
58
|
+ // curl_close($ch);
|
|
|
59
|
+
|
|
|
60
|
+ // 使用 cURL 发起 POST 请求
|
|
|
61
|
+ $ch = curl_init();
|
|
|
62
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
63
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
|
|
|
64
|
+ curl_setopt($ch, CURLOPT_POST, true);
|
|
|
65
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
66
|
+ curl_setopt($ch, CURLOPT_POSTFIELDS, json_encode($postData)); // 转换为 JSON 字符串
|
|
|
67
|
+ $response = curl_exec($ch);
|
|
|
68
|
+ curl_close($ch);
|
|
|
69
|
+
|
|
|
70
|
+ // 解析返回的 JSON 数据
|
|
|
71
|
+ $responseData = json_decode($response, true);
|
|
|
72
|
+
|
|
|
73
|
+ return json($responseData); // 返回用户积分,默认值为 0
|
|
|
74
|
+ }
|
|
|
75
|
+
|
|
|
76
|
+ private function generateSignature($apiKey, $timestamp)
|
|
|
77
|
+ {
|
|
|
78
|
+ $data = $apiKey . "|" . $timestamp . "|" . self::API_SECRET;
|
|
|
79
|
+ return md5($data); // 返回 MD5 签名
|
|
|
80
|
+ }
|
|
|
81
|
+
|
|
16
|
82
|
/**
|
|
17
|
83
|
* 会员升级
|
|
18
|
84
|
*/
|