{"id":144,"date":"2019-08-14T17:16:44","date_gmt":"2019-08-14T09:16:44","guid":{"rendered":"http:\/\/www.cgh0610.cn\/?p=144"},"modified":"2019-08-14T17:16:44","modified_gmt":"2019-08-14T09:16:44","slug":"%e9%80%9a%e8%bf%87ip%e8%8e%b7%e5%8f%96ip%e5%86%85%e5%90%ab%e4%bf%a1%e6%81%af","status":"publish","type":"post","link":"https:\/\/www.cgh0610.cn\/?p=144","title":{"rendered":"\u901a\u8fc7IP\u83b7\u53d6IP\u5185\u542b\u4fe1\u606f"},"content":{"rendered":"<pre><code class=\"language-php line-numbers\">class Taobaoip {\n\n\/**\n * \u6dd8\u5b9dIP\u5730\u5740\u5e93 Reset API\n * @author \n * @param  [string] <span class=\"katex math inline\">ip [IP\u5730\u5740]\n * @return [type]     [\u53ea\u8fd4\u56de\u83b7\u53d6\u6210\u529f\u7684ip\u6570\u636e]\n *\/\n    public function getLocation(<\/span>ip) {\n        if (empty(<span class=\"katex math inline\">ip))<\/span>ip = get_client_ip();\n        <span class=\"katex math inline\">taobaoUrl = \"http:\/\/ip.taobao.com\/service\/getIpInfo.php?ip=\";<\/span>url       = <span class=\"katex math inline\">taobaoUrl .<\/span>ip;\n        <span class=\"katex math inline\">data      = self::httpRequest(<\/span>url);\n        <span class=\"katex math inline\">data      = preg_replace(\"#\\\\\\u([0-9a-f]{4})#ie\", \"iconv('UCS-2BE', 'UTF-8', pack('H4', '\\\\1'))\",<\/span>data);\n        <span class=\"katex math inline\">data      = json_decode(<\/span>data, true);\n        return <span class=\"katex math inline\">data[data];\n    }\n\n    Static Private function httpRequest(<\/span>url) {\n        <span class=\"katex math inline\">ch = curl_init();\n        curl_setopt(<\/span>ch, CURLOPT_URL, <span class=\"katex math inline\">url);\n        curl_setopt(<\/span>ch, CURLOPT_RETURNTRANSFER, 1);\n        <span class=\"katex math inline\">output = curl_exec(<\/span>ch);\n        curl_close(<span class=\"katex math inline\">ch);\n        if (<\/span>output === FALSE) {\n            return \"cURL Error: \" . curl_error(<span class=\"katex math inline\">ch);\n        }\n        return<\/span>output;\n    }\n\n\n}\n#\u6210\u529f\u8fd4\u56de\n#{\"code\":0,\"data\":{\"ip\":\"113.70.24.1\",\"country\":\"\u4e2d\u56fd\",\"area\":\"\",\"region\":\"\u5e7f\u4e1c\",\"city\":\"\u4f5b\u5c71\",\"county\":\"XX\",\"isp\":\"\u7535\u4fe1\",\"country_id\":\"CN\",\"area_id\":\"\",\"region_id\":\"440000\",\"city_id\":\"440600\",\"county_id\":\"xx\",\"isp_id\":\"100017\"}}\n<\/code><\/pre>\n","protected":false},"excerpt":{"rendered":"<p>class Taobaoip { \/** * \u6dd8\u5b9dIP\u5730\u5740\u5e93 Reset API * @author * @p &hellip; <a href=\"https:\/\/www.cgh0610.cn\/?p=144\" class=\"more-link\">\u7ee7\u7eed\u9605\u8bfb<span class=\"screen-reader-text\">\u901a\u8fc7IP\u83b7\u53d6IP\u5185\u542b\u4fe1\u606f<\/span><\/a><\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"open","ping_status":"open","sticky":false,"template":"","format":"aside","meta":[],"categories":[38,12],"tags":[60],"_links":{"self":[{"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=\/wp\/v2\/posts\/144"}],"collection":[{"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcomments&post=144"}],"version-history":[{"count":1,"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=\/wp\/v2\/posts\/144\/revisions"}],"predecessor-version":[{"id":145,"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=\/wp\/v2\/posts\/144\/revisions\/145"}],"wp:attachment":[{"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fmedia&parent=144"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=%2Fwp%2Fv2%2Fcategories&post=144"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/www.cgh0610.cn\/index.php?rest_route=%2Fwp%2Fv2%2Ftags&post=144"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}