range

If there were you, the world would be just right

打点记录一下

1 如果有设置,先清空

DROP PROCEDURE IF EXISTS proc_batch_insert;

2 创建存储过程

CREATE PROCEDURE proc_batch_insert()
BEGIN
DECLARE i INT;
SET i=100000;

WHILE i < 2000000 DO
    INSERT INTO hd_carry_prize_dzq(`date`,addtime,user_id,username,prize_id,ip,status) VALUES('2019-05-22','1558454400',i,'测试','10105','127.0.0.1',1);
SET i=i+1;
END WHILE;
END;  

3 执行存储过程

call proc_batch_insert();

需求
找出用户ip归属地
解决
大多接口需要收费,但是通过抓包我们还是能从一些查询网站中,找到他们的接口来供自己调用

// ip.cn
public static function ip_cn($ip){
    $url    ='https://ip.cn/api/index?type=1&ip='.$ip;
    $result = Curl::httpGet($url);
    $arr    = json_decode($result,true);
    print_r($arr);;
}

// 百度接口
public static function ip_baidu($ip){        
    $t  = time().rand(100,666);
    $et = time().rand(666,999);
    $statime = (time()+5).rand(100,999);
    $url ='https://sp0.baidu.com/8aQDcjqpAAV3otqbppnN2DJv/api.php?query='.$ip.'&co=&resource_id=6006&t='.$statime.'&ie=utf8&oe=gbk&cb=op_aladdin_callback&format=json&tn=baidu&cb=jQuery110207'.$et.'_'.$t.'&_='.$et;
    $result = Curl::httpGet($url);
    $return_data = mb_convert_encoding($result, "UTF-8","GBK");
    $city_str = '';
    $city = array(); 
    preg_match_all("/(?:\()(.*)(?:\))/i",$return_data, $city); 
    if(!empty($city[1][0])){
        $ipstr = $city[1][0];
        $ipdata = json_encode($ipstr);
        $ipdata = json_decode( json_decode($ipdata),true );
        if(!empty($ipdata['data'][0]['location'])){
            Log::syslog("百度接口:".$ipdata['data'][0]['location'], "get_h5url");
            $city_str = $ipdata['data'][0]['location'];
        }
    }
    return $city_str;
}

// ip168 接口
public static function ip_168($ip){
    $post_data['keyword']   = $ip;
    $post_data['btnsearch'] = '查询';
    $url ='http://www.ip168.com/chxip/doGetIp.do';
    $result = Curl::httpPost($url,$post_data);
    $city_str = '';
    if(!empty($result)){
        Log::syslog("ip168接口:".$result, "get_h5url");
        $city_str = $result;
    }
    return $city_str;
}

// 淘宝接口
public static function ip_taobao($ip){
    $url="http://ip.taobao.com/service/getIpInfo.php?ip=".$ip;
    $result = Curl::httpGet($url);
    $ip = json_decode($result,true);
    $city_str = '';
    if(!empty($ip['data']['city'])){
        Log::syslog("淘宝接口:".$ip['data']['city'], "get_h5url");
        $city_str = $ip['data']['city'];
    }
    return $city_str;
}