|
|
@@ -774,8 +774,72 @@ class Events
|
|
|
return false;
|
|
|
}
|
|
|
|
|
|
- public
|
|
|
- static function getUserIPinfo($ip)
|
|
|
+ static function CurlGet($url, $header)
|
|
|
+ {
|
|
|
+ $ch = curl_init();
|
|
|
+ curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTP_VERSION, CURL_HTTP_VERSION_1_1);
|
|
|
+ curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
|
|
|
+ curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
+ curl_setopt($ch, CURLOPT_CONNECTTIMEOUT, 3);
|
|
|
+ $handles = curl_exec($ch);
|
|
|
+ curl_close($ch);
|
|
|
+ return $handles;
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ ////ip信息转换---begin
|
|
|
+ public static function getUserIPinfo($ip)
|
|
|
+ {
|
|
|
+ $info = self::getUserIPinfo_db($ip);
|
|
|
+ if (!empty($info)) {
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+ $info = self::getUserIPinfo_v2($ip);
|
|
|
+ if (empty($info)) {
|
|
|
+ $info = self::getUserIPinfo_v1($ip);
|
|
|
+ }
|
|
|
+ if ($info) {
|
|
|
+ self::writeUserIpinfo($ip, $info);
|
|
|
+ }
|
|
|
+ return $info;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getUserIPinfo_v2($ip)
|
|
|
+ {
|
|
|
+ $url = 'http://api.ip138.com/query/?datatype=jsonp&ip=' . $ip;
|
|
|
+ $header = array('token:db48a8df731a5b0bf023de966dae9d9b');
|
|
|
+ $ret = self::CurlGet($url, $header);
|
|
|
+
|
|
|
+ if (empty($ret)) {
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+ $ret = json_decode($ret, true);
|
|
|
+
|
|
|
+ if ($ret && isset($ret['ret']) && strtolower($ret['ret']) == 'ok') {
|
|
|
+ if (isset($ret['data']) && isset($ret['data']['0']) && isset($ret['data']['1']) && isset($ret['data']['2'])) {
|
|
|
+ return trim($ret['data']['0'] . '.' . $ret['data']['1'] . '.' . $ret['data']['2'], '.');
|
|
|
+ }
|
|
|
+ }
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getUserIPinfo_db($ip)
|
|
|
+ {
|
|
|
+ $ret = self::$db->select('info')->from('ws_ipinfocache')->where("ip='$ip'")->row();
|
|
|
+ if ($ret) {
|
|
|
+ return $ret['info'];
|
|
|
+ }
|
|
|
+ return '';
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function writeUserIpinfo($ip, $info)
|
|
|
+ {
|
|
|
+ $ret = self::$db->insert('ws_ipinfocache')->cols(['ip' => $ip, 'info' => $info])->query();
|
|
|
+ return $ret;
|
|
|
+ }
|
|
|
+
|
|
|
+ public static function getUserIPinfo_v1($ip)
|
|
|
{
|
|
|
$url = 'http://www.ip168.com/chxip/doGetIp.do?keyword=' . $ip;
|
|
|
$ret = file_get_contents($url);
|
|
|
@@ -798,8 +862,13 @@ class Events
|
|
|
}
|
|
|
}
|
|
|
return $defret;
|
|
|
+
|
|
|
}
|
|
|
|
|
|
+
|
|
|
+ ////ip信息转换---end
|
|
|
+
|
|
|
+
|
|
|
//用户发送邦定用户事件
|
|
|
public
|
|
|
static function userInitEnt($client_id, $message)
|