Merge branch 'feature/testing_resource_account' of wmtx/sdk into master

测试资源账号登录限制
master
廖金灵 4 years ago committed by Gogs
commit 92e60bd40a

@ -4,6 +4,7 @@ namespace Base\Service;
use Base\Tool\TaskClient;
use Think\Log;
use Base\Tool\Redis;
use Base\Tool\IPTool;
/**
*
@ -107,16 +108,19 @@ class UserService
return ['status' => false, 'message' => '密码错误'];
}
$testResource = M('test_resource','tab_')->where('user_id=%s and apply_status=2', $user['id'])->find(); //测试资源(扶持号)
if ($testResource) {
if ($this->isIpWarning($user, $clientIp)) {
$this->ipWarningLog($user, $testResource, $clientIp);
$testingUser = M('testing_user', 'tab_')->where(['user_id' => $user['id']])->find();
if ($testingUser) {
if ($testingUser['verify_status'] != 1) {
return ['status' => false, 'message' => '该账号不可使用!'];
}
if ($testingUser['status'] == 3) {
return ['status' => false, 'message' => '该账号已被禁用!'];
}
if ($this->isDeviceError($user, $testResource, $deviceNum)) {
$userData['last_device_number'] = $deviceNum;
$userData['lock_status'] = 0 ;
$this->deviceErrorLog($user, $testResource, $deviceNum);
return ['status' => false, 'message' => '该账号已被禁用'];
if ($this->isIpWarning($user, $clientIp)) {
M('testing_user', 'tab_')->where(['user_id' => $user['id']])->save([
'status' => 2,
'update_time' => time()
]);
}
}
@ -180,7 +184,9 @@ class UserService
}
}
/**
* @deprecated
*/
protected function isDeviceError($user, $testResource, $deviceNum)
{
if ($testResource && $user['device_number'] && $deviceNum && $user['device_number'] != $deviceNum) {
@ -189,6 +195,9 @@ class UserService
return false;
}
/**
* @deprecated
*/
protected function deviceErrorLog($user, $testResource, $deviceNum){
$data = [];
$data['user_id'] = $user['id'];
@ -208,17 +217,21 @@ class UserService
protected function isIpWarning($user, $clientIp)
{
$newResult = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$clientIp);
$oldResult = file_get_contents('http://ip.taobao.com/service/getIpInfo.php?ip='.$user['login_ip']);
$newResult = json_decode($newResult, true);
$oldResult = json_decode($oldResult, true);
if($newResult['data']['city'] != $oldResult['data']['city']) {
return true;
$newResult = IPTool::getIpInfo($clientIp);
$oldResult = IPTool::getIpInfo($user['login_ip']);
if (
$newResult['country_id'] == $oldResult['country_id'] &&
$newResult['region_id'] == $oldResult['region_id'] &&
$newResult['city_id'] == $oldResult['city_id']
) {
return false;
}
return false;
return true;
}
// 扶持号登录IP异常
/**
* @deprecated
*/
protected function ipWarningLog($user, $testResource, $clientIp){
$data = [];
$data['user_id'] = $user['id'];

@ -0,0 +1,41 @@
<?php
namespace Base\Tool;
class IPTool
{
public static function getIpInfo($ip)
{
$host = 'https://api01.aliyun.venuscn.com';
$path = '/ip';
$method = 'GET';
$appcode = '244181f0846541a19e24df409736d3b9';
$headers = [];
array_push($headers, 'Authorization:APPCODE ' . $appcode);
$querys = 'ip=' . $ip;
$bodys = '';
$url = $host . $path . '?' . $querys;
$curl = curl_init();
curl_setopt($curl, CURLOPT_CUSTOMREQUEST, $method);
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_FAILONERROR, false);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, true);
// curl_setopt($curl, CURLOPT_HEADER, true);
if (1 == strpos('$'.$host, 'https://')) {
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
$response = curl_exec($curl);
if (!$response) {
return null;
}
$result = json_decode($response, true);
if ($result['ret'] == 200) {
return $result['data'];
} else {
return null;
}
}
}
Loading…
Cancel
Save