Kaynağa Gözat

Merge branch 'dev' into dev-sxb

sunxbiao 1 yıl önce
ebeveyn
işleme
40265c1e10

+ 28 - 69
app/common/middleware/SignatureMiddleware.php

@@ -3,96 +3,55 @@
3 3
 namespace app\common\middleware;
4 4
 
5 5
 use think\facade\Cache;
6
-use think\facade\Log;
7
-use think\Request;
8 6
 use think\Response;
9 7
 
10 8
 class SignatureMiddleware
11 9
 {
12
-    public function handle(Request $request, \Closure $next)
10
+    public function handle($request, \Closure $next)
13 11
     {
14
-        // 获取必要参数
15
-        $essential = $request->only(['timestamp', 'nonce', 'signature']);
16
-
17
-        // 验证必要参数
18
-        if (count(array_filter($essential)) !== 3) {
19
-            return $this->errorResponse('参数不完整', 400);
20
-        }
21
-
22
-        // 验证时间戳(5分钟内有效)
23
-        if (abs(time() - (int)$essential['timestamp']) > 300) {
24
-            return $this->errorResponse('请求已过期', 400);
25
-        }
26
-
27
-        // 验证nonce唯一性
28
-        $nonceKey = 'nonce:' . $essential['nonce'];
29
-        if (Cache::has($nonceKey)) {
30
-            return $this->errorResponse('重复请求', 400);
31
-        }
32
-
33
-        // 构造签名数据(与前端完全一致)
34
-        $signData = $request->param();
35
-        unset($signData['signature']);
36
-
37
-        // 按键名排序
38
-        ksort($signData);
39
-
40
-        // 生成签名字符串(与前端相同格式)
41
-        $signContent = '';
42
-        foreach ($signData as $key => $value) {
43
-            $signContent .= "{$key}={$value}&";
12
+        // 1. 获取加密签名
13
+        $sign = $request->header('X-Sign');
14
+        if (!$sign) {
15
+            return $this->reject('缺少签名', 401);
44 16
         }
45
-        $signContent = rtrim($signContent, '&');
46
-
47
-        // 记录原始签名内容(用于调试)
48
-        Log::debug("Sign Content: " . $signContent);
49
-
50
-        // 获取公钥
51
-        $publicKey = openssl_pkey_get_public(
52
-            file_get_contents(env('RSA_PUBLIC_KEY_PATH'))
53
-        );
54 17
 
55
-        if (!$publicKey) {
56
-            Log::error("公钥加载失败");
57
-            return $this->errorResponse('系统错误', 500);
18
+        // 2. 读取私钥
19
+        $privateKey = file_get_contents(env('RSA_PRIVATE_KEY_PATH'));
20
+        if (!$privateKey) {
21
+            return $this->reject('服务器密钥错误', 500);
58 22
         }
59 23
 
60
-        // 计算签名的MD5值(与前端一致)
61
-        $md5Hash = md5($signContent);
62
-        Log::debug("MD5 Hash: " . $md5Hash);
63
-
64
-        // 解码前端签名(前端使用公钥加密)
65
-        $signature = base64_decode($essential['signature']);
66
-
67
-        // 使用公钥解密签名
24
+        // 3. 解密数据
68 25
         $decrypted = '';
69
-        $success = openssl_public_decrypt($signature, $decrypted, $publicKey);
26
+        openssl_private_decrypt(base64_decode($sign), $decrypted, $privateKey);
70 27
 
71
-        if (!$success) {
72
-            Log::error("签名解密失败: " . openssl_error_string());
73
-            return $this->errorResponse('签名验证失败', 403);
28
+        if (!$decrypted || !strpos($decrypted, ':')) {
29
+            return $this->reject('无效签名', 403);
74 30
         }
75 31
 
76
-        Log::debug("解密结果: " . $decrypted);
32
+        // 4. 分离随机数和时间戳
33
+        list($nonce, $timestamp) = explode(':', $decrypted, 2);
77 34
 
78
-        // 比较解密后的值与MD5哈希
79
-        if ($decrypted !== $md5Hash) {
80
-            Log::error("签名验证失败: 期望 {$md5Hash}, 实际 {$decrypted}");
81
-            return $this->errorResponse('签名验证失败', 403);
35
+        // 5. 验证时间有效性(5分钟内)
36
+        if (abs(time() - $timestamp / 1000) > 300) {
37
+            return $this->reject('请求已过期', 403);
82 38
         }
83 39
 
84
-        // 记录已使用的nonce(5分钟过期)
85
-        Cache::set($nonceKey, 1, 300);
40
+        // 6. 防重放攻击(检查nonce唯一性)
41
+        $cacheKey = 'nonce_' . $nonce;
42
+        if (Cache::has($cacheKey)) {
43
+            return $this->reject('重复请求', 403);
44
+        }
45
+        Cache::set($cacheKey, 1, 300); // 5分钟缓存
86 46
 
87 47
         return $next($request);
88 48
     }
89 49
 
90
-    private function errorResponse(string $message, int $code): Response
50
+    private function reject($msg, $code): Response
91 51
     {
92
-        return json([
52
+        return Response::create([
93 53
             'code' => $code,
94
-            'msg' => $message,
95
-            'data' => null
96
-        ])->code($code);
54
+            'msg'  => $msg
55
+        ], 'json')->code($code);
97 56
     }
98 57
 }

+ 6 - 3
app/common/repositories/finance/FinanceRepository.php

@@ -157,6 +157,7 @@ class FinanceRepository extends BaseRepository
157 157
 
158 158
             // 会员专区订单总数
159 159
             //总数
160
+            $mer_idhy = 496;
160 161
             $chengjiaomoney = Db::name('store_order')->where($where)->where('mer_id', 496)->count();
161 162
             $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 496)->count();
162 163
             $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 496)->count();
@@ -165,6 +166,7 @@ class FinanceRepository extends BaseRepository
165 166
     
166 167
             //精彩生活区订单总数
167 168
             //总数
169
+            $mer_idjc = 439;
168 170
             $chengjiaocount = Db::name('store_order')->where($where)->where('mer_id', 439)->count();
169 171
             $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 439)->count();
170 172
             $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 439)->count();
@@ -181,6 +183,7 @@ class FinanceRepository extends BaseRepository
181 183
     
182 184
             //复购区订单总数
183 185
             //总数
186
+            $mer_idfg = 491;
184 187
             $tuikuanmoney = Db::name('store_order')->where($where)->where('mer_id', 491)->count();
185 188
             $weekCount = Db::name('store_order')->where($weekWhere)->where('mer_id', 491)->count();
186 189
             $todayCount = Db::name('store_order')->where($dayWhere)->where('mer_id', 491)->count();
@@ -246,10 +249,10 @@ class FinanceRepository extends BaseRepository
246 249
             $list6[] = ['count' => $todayCount, 'name' => '日订单总数'];
247 250
     
248 251
     
249
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaomoney), 'name' => '会员专区订单总数', 'list' => $list1];
250
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaocount), 'name' => '精彩生活区订单总数', 'list' => $list2];
252
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaomoney), 'name' => '会员专区订单总数', 'mer_id' => $mer_idhy, 'list' => $list1];
253
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaocount), 'name' => '精彩生活区订单总数', 'mer_id' => $mer_idjc, 'list' => $list2];
251 254
             $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($chengjiaoren), 'name' => '商贸区订单总数', 'list' => $list3];
252
-            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanmoney), 'name' => '复购区订单总数', 'list' => $list4];
255
+            $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanmoney), 'name' => '复购区订单总数', 'mer_id' => $mer_idfg, 'list' => $list4];
253 256
             $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuancount), 'name' => '三方平台订单总数', 'list' => $list5];
254 257
             $data[] = ['className' => 'el-icon-s-goods', 'count' => set_price_rtrim($tuikuanren), 'name' => '线下订单总数', 'list' => $list6];
255 258
             return $data;

+ 15 - 5
app/controller/admin/user/User.php

@@ -281,6 +281,10 @@ class User extends BaseController
281 281
         }
282 282
         $user['marker_phone_list'] = $marker_phone_list;
283 283
 
284
+        $old_user_lianc_data = Db::name("old_user_lianc")->select()->toArray();//将联创等级数据一起发送到前端
285
+        $user['old_user_lianc_data'] = $old_user_lianc_data;
286
+
287
+
284 288
         return app('json')->success($user);
285 289
     }
286 290
 
@@ -383,6 +387,12 @@ class User extends BaseController
383 387
 
384 388
         $this->repository->update($id, $data);
385 389
 
390
+        $originatorIdOld = request()->post('originator_id_old','');//接收originator_id_old数据,并更新到数据库里
391
+        if ($originatorIdOld === '') {
392
+            $originatorIdOld = null;
393
+        }
394
+        Db::name('user')->where('uid', $id)->update(['originator_id_old' => $originatorIdOld]);
395
+
386 396
         //更新身份证信息
387 397
         $cardData = [];
388 398
         if ($data['card_id']) {
@@ -414,11 +424,11 @@ class User extends BaseController
414 424
             Db::name('user_rich')->insert($user_rich_ypdate);
415 425
         }
416 426
 
417
-
418
-
419
-
420
-
421
-        return app('json')->success('编辑成功');
427
+        $user = Db::name('user')->where('uid', $id)->find();
428
+        if (isset($user['originator_id_old']) && is_null($user['originator_id_old'])) {
429
+            $user['originator_id_old'] = '';
430
+        }
431
+        return app('json')->success('编辑成功',$user);
422 432
     }
423 433
 
424 434
     public function maker_check_phone($id)

+ 1 - 1
app/controller/api/Auth.php

@@ -1354,7 +1354,7 @@ class Auth extends BaseController
1354 1354
             'code' => 200,
1355 1355
             'msg' => 'success',
1356 1356
             'data' => [
1357
-                'public_key' => $publicKey
1357
+                'publicKey' => $publicKey
1358 1358
             ]
1359 1359
         ]);
1360 1360
     }

+ 2 - 1
route/api.php

@@ -979,7 +979,8 @@ Route::group('api/', function () {
979 979
     Route::get('auth/getPublicKey', 'api.Auth/getPublicKey');
980 980
 
981 981
     //验证码
982
-    Route::post('auth/verify', 'api.Auth/verify')
982
+    Route::post('auth/verify', 'api.Auth/verify');
983
+    Route::post('auth/sendSms', 'api.Auth/verify')
983 984
         ->middleware(SignatureMiddleware::class)
984 985
         ->middleware(RateLimitMiddleware::class);
985 986
     //微信配置