|
@@ -422,9 +422,50 @@ class Api
|
|
|
if($this->auth->isLogin()){
|
|
|
db('user_active')->where('user_id',$this->auth->id)->update(['requesttime'=>time()]);
|
|
|
if($this->auth->is_active == 0){
|
|
|
- db('user')->where('id',$this->auth->id)->update(['is_active'=>1]);
|
|
|
+ $update = $this->ip_to_address();
|
|
|
+ $update['is_active'] = 1;
|
|
|
+
|
|
|
+ db('user')->where('id',$this->auth->id)->update($update);
|
|
|
+
|
|
|
+ if(isset($update['provincename'])){
|
|
|
+ $this->auth->setuser('provincename',$update['provincename']);
|
|
|
+ }
|
|
|
+ if(isset($update['cityname'])){
|
|
|
+ $this->auth->setuser('cityname',$update['cityname']);
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ //ip获取地址
|
|
|
+ private function ip_to_address(){
|
|
|
+ $ip = request()->ip();
|
|
|
+ //$ip = '182.37.138.94';
|
|
|
+
|
|
|
+ // http协议:http://api.ip138.com/ip/
|
|
|
+ // https协议:https://api.ip138.com/ip/
|
|
|
+
|
|
|
+ $url = 'http://api.ip138.com/ip/?ip='.$ip.'&datatype=jsonp&token=010e8e53e47166c0623380697e7540e4';
|
|
|
+ $result = json_decode(curl_get($url),true);
|
|
|
+ //dump($result);
|
|
|
+
|
|
|
+ $data = [];
|
|
|
+ if(is_array($result) && !empty($result)){
|
|
|
+ if(isset($result['ret']) && $result['ret'] == 'ok'){
|
|
|
+ if(isset($result['data']) && is_array($result['data']) && !empty($result['data'])){
|
|
|
+
|
|
|
+ if(isset($result['data'][1]) && !empty($result['data'][1])){
|
|
|
+ $data['provincename'] = $result['data'][1];
|
|
|
+ }
|
|
|
+ if(isset($result['data'][2]) && !empty($result['data'][2])){
|
|
|
+ $data['cityname'] = $result['data'][2];
|
|
|
+ }
|
|
|
+
|
|
|
+ }
|
|
|
}
|
|
|
}
|
|
|
+ //dump($data);
|
|
|
+ return $data;
|
|
|
}
|
|
|
|
|
|
|