IP查询
其他 官方文档
根据ip地址获取其所在省市区
基本说明:
接口地址:http://whois.pconline.com.cn/ipJson.jsp
返回格式:json
请求方式:get/post
请求示例:http://whois.pconline.com.cn/ipJson.jsp?json=true
请求参数说明:
名称 类型 必填 说明
json String 必填 值为true
ip String 选填 指定IP地址,否则为本地ip
返回参数说明:
名称 类型 说明
参考JSON返回示例 - -
JSON返回示例:
{
	"pro": "广东省",
	"proCode": "440000",
	"city": "广州市",
	"cityCode": "440100",
	"region": "",
	"regionCode": "",
	"error": "必须传入坐标参数才能进行查询!"
}
服务级错误码参照
错误码 说明
- -
完整教学代码示例
<?php
/**
 * Created by PhpStorm.
 * User: FZS
 * Time: 2019/3/15 17:50
 */
//----------------------------------
// 太平洋网络 IP查询 调用类
//----------------------------------
class freeApi{
    private $apiUrl = 'http://whois.pconline.com.cn/ipJson.jsp?json=true';
    /**
     * 获取 IP查询 结果
     * @return array
     */
    public function getResult(){
        return $this->freeApiCurl($this->apiUrl);
    }
    /**
     * 请求接口返回内容
     * @param  string $url [请求的URL地址]
     * @param  string $params [请求的参数]
     * @param  int $ipost [是否采用POST形式]
     * @return  string
     */
    public function freeApiCurl($url,$params=false,$ispost=0){
        $ch = curl_init();
        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
        curl_setopt( $ch, CURLOPT_USERAGENT , 'chuanshuoapi' );
        curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
        curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
        curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
        if( $ispost )
        {
            curl_setopt( $ch , CURLOPT_POST , true );
            curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
            curl_setopt( $ch , CURLOPT_URL , $url );
        }
        else
        {
            if($params){
                curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
            }else{
                curl_setopt( $ch , CURLOPT_URL , $url);
            }
        }
        $response = curl_exec( $ch );
        if ($response === FALSE) {
            return false;
        }
        curl_close( $ch );
        return $response;
    }
}