|
|
@@ -48,12 +48,14 @@ use think\App;
|
|
48
|
48
|
use think\db\exception\DataNotFoundException;
|
|
49
|
49
|
use think\db\exception\DbException;
|
|
50
|
50
|
use think\db\exception\ModelNotFoundException;
|
|
|
51
|
+use think\Env;
|
|
51
|
52
|
use think\Exception;
|
|
52
|
53
|
use think\exception\HttpResponseException;
|
|
53
|
54
|
use think\facade\Cache;
|
|
54
|
55
|
use think\facade\Db;
|
|
55
|
56
|
use think\facade\Log;
|
|
56
|
57
|
use think\Filesystem;
|
|
|
58
|
+use think\Response;
|
|
57
|
59
|
|
|
58
|
60
|
/**
|
|
59
|
61
|
* Class Auth
|
|
|
@@ -1322,6 +1324,41 @@ class Auth extends BaseController
|
|
1322
|
1324
|
return $res;
|
|
1323
|
1325
|
}
|
|
1324
|
1326
|
|
|
|
1327
|
+
|
|
|
1328
|
+ /**
|
|
|
1329
|
+ * 获取验签公钥
|
|
|
1330
|
+ * @return Response
|
|
|
1331
|
+ */
|
|
|
1332
|
+ public function getPublicKey(): Response
|
|
|
1333
|
+ {
|
|
|
1334
|
+ $path = env('RSA_PUBLIC_KEY_PATH');
|
|
|
1335
|
+
|
|
|
1336
|
+ if (empty($path)) {
|
|
|
1337
|
+ return json([
|
|
|
1338
|
+ 'code' => 500,
|
|
|
1339
|
+ 'msg' => '公钥路径未配置',
|
|
|
1340
|
+ 'data' => null
|
|
|
1341
|
+ ]);
|
|
|
1342
|
+ }
|
|
|
1343
|
+
|
|
|
1344
|
+ if (!file_exists($path)) {
|
|
|
1345
|
+ return json([
|
|
|
1346
|
+ 'code' => 500,
|
|
|
1347
|
+ 'msg' => '公钥文件不存在: ' . $path,
|
|
|
1348
|
+ 'data' => null
|
|
|
1349
|
+ ]);
|
|
|
1350
|
+ }
|
|
|
1351
|
+
|
|
|
1352
|
+ $publicKey = file_get_contents($path);
|
|
|
1353
|
+ return json([
|
|
|
1354
|
+ 'code' => 200,
|
|
|
1355
|
+ 'msg' => 'success',
|
|
|
1356
|
+ 'data' => [
|
|
|
1357
|
+ 'public_key' => $publicKey
|
|
|
1358
|
+ ]
|
|
|
1359
|
+ ]);
|
|
|
1360
|
+ }
|
|
|
1361
|
+
|
|
1325
|
1362
|
public function verify(UserAuthValidate $validate)
|
|
1326
|
1363
|
{
|
|
1327
|
1364
|
$data = $this->request->params(['phone', 'code', 'key',"type"]);
|
|
|
@@ -1464,30 +1501,32 @@ class Auth extends BaseController
|
|
1464
|
1501
|
|
|
1465
|
1502
|
$domain = $this->request->domain();
|
|
1466
|
1503
|
|
|
1467
|
|
- if (!$this->checkSmsCode($data['phone'], $data['sms_code'])) {
|
|
1468
|
|
- if (($data['sms_code'] != '6865')) {
|
|
1469
|
|
- $uid= Db::name('user')->where("phone", $data["phone"])->value('uid');
|
|
1470
|
|
- if($uid){
|
|
1471
|
|
- $allTeams = Db::name('user_zero_line')->field('team_uid,custom_code')->select()->toArray();
|
|
1472
|
|
- $hasTeam = false;
|
|
1473
|
|
- foreach ($allTeams as $team) {
|
|
1474
|
|
- $sql = "select getUserLevelId({$team['team_uid']}) as uids";
|
|
1475
|
|
- $spread_user_list = Db::query($sql);
|
|
1476
|
|
- $member_uids = explode(",", trim($spread_user_list[0]['uids'], '$,'));
|
|
1477
|
|
- if (in_array($uid, $member_uids)){
|
|
1478
|
|
- $hasTeam = true;
|
|
1479
|
|
- if ($data['sms_code'] != $team['custom_code']) {
|
|
1480
|
|
- return app('json')->fail('验证码不正确');
|
|
1481
|
|
- }
|
|
1482
|
|
- break;
|
|
|
1504
|
+ //如果手机验证码错误并且验证码不是6865,进入查验团队验证码环节
|
|
|
1505
|
+ if (!$this->checkSmsCode($data['phone'], $data['sms_code']) && $data['sms_code'] !== '6865') {
|
|
|
1506
|
+ $uid= Db::name('user')->where("phone", $data["phone"])->value('uid');//通过输入的手机号查询用户的uid
|
|
|
1507
|
+ if($uid){
|
|
|
1508
|
+ $allTeams = Db::name('user_zero_line')->field('team_uid,custom_code')->select()->toArray();//去user_zero_line表查询团队team_uid和团队自定义的验证码
|
|
|
1509
|
+ $hasTeam = false; //先将用户设成不为团队成员
|
|
|
1510
|
+ foreach ($allTeams as $team) {
|
|
|
1511
|
+ $cacheKey = 'team_members_' . $team['team_uid'];
|
|
|
1512
|
+ $member_uids = Cache::get($cacheKey);
|
|
|
1513
|
+ $sql = "select getUserLevelId({$team['team_uid']}) as uids"; //查询所有团队下成员的uid
|
|
|
1514
|
+ $spread_user_list = Db::query($sql);
|
|
|
1515
|
+ $member_uids = explode(",", trim($spread_user_list[0]['uids'], '$,'));
|
|
|
1516
|
+ Cache::set($cacheKey, $member_uids, 300); //结果缓存5分钟
|
|
|
1517
|
+ if (in_array($uid, $member_uids)){
|
|
|
1518
|
+ $hasTeam = true; //若用户属于团队,将其设为团队成员
|
|
|
1519
|
+ if ($data['sms_code'] != $team['custom_code']) {
|
|
|
1520
|
+ return app('json')->fail('验证码不正确'); //如果与用户所属团队的验证码不一致,返回验证码不正确
|
|
1483
|
1521
|
}
|
|
|
1522
|
+ break;
|
|
1484
|
1523
|
}
|
|
1485
|
|
- if (!$hasTeam) {
|
|
1486
|
|
- return app('json')->fail('验证码不正确');
|
|
1487
|
|
- }
|
|
1488
|
|
- } else {
|
|
|
1524
|
+ }
|
|
|
1525
|
+ if (!$hasTeam) {
|
|
1489
|
1526
|
return app('json')->fail('验证码不正确');
|
|
1490
|
1527
|
}
|
|
|
1528
|
+ } else {
|
|
|
1529
|
+ return app('json')->fail('验证码不正确');
|
|
1491
|
1530
|
}
|
|
1492
|
1531
|
}
|
|
1493
|
1532
|
|