<?php namespace ip; use think\Request; class Shielded{ public function doGet($url){ //初始化 $ch = curl_init(); curl_setopt($ch, CURLOPT_URL,$url); // 執(zhí)行后不直接打印出來 curl_setopt($ch, CURLOPT_RETURNTRANSFER, true); curl_setopt($ch, CURLOPT_HEADER, false); // 跳過證書檢查 curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 不從證書中檢查SSL加密算法是否存在 curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); //執(zhí)行并獲取HTML文檔內(nèi)容 $output = curl_exec($ch); //釋放curl句柄 curl_close($ch); return $output; } /** * [is_china 通過自動獲取ip,再判斷ip是否是中國的] * @Author lmkj * @DateTime 2018-09-04 * @copyright [lmkj] * @license [lmkj] * @version [version] * @return boolean [返回code和msg] */ public function is_china(){ //獲取ip $ip = request()->ip(); if (!$ip) { return ['code' => 0, 'msg' => '獲取不到ip']; } //通過ip檢測是不是中國的 $taobao_param['ip'] = $ip; $taobao_ip = $this->doGet('http://ip.taobao.com/service/getIpInfo.php?ip='.$ip); $taobao_ip=json_decode($taobao_ip,true); // dump($taobao_ip); if ($taobao_ip['code'] == 0) { if ($taobao_ip['data']['country'] == '中國') { return ['code' => 1, 'msg' => 'ip是中國的,!']; }else{ return ['code' => 0, 'msg' => 'ip是不是中國或者為未查詢到']; } }else{ return ['code' => 0, 'msg' => '查詢失敗']; } } }
|
|