public function get_by_api($ip) { $http = new HttpClient(); $result = $http->get('http://ip.taobao.com/service/getIpInfo.php?ip=' . $ip); $res = json_decode($result, true); return $res['code'] == 0 ? $res['data'] : false; }
/** * 新浪短连接生成 * @param string $url 要缩短的连接 * @param string $key App_key * @return boolean */ function short_url($url, $app_key = '879062653') { static $http = null; if ($http == null) { $http = new HttpClient(); } $result = $http->get("https://api.weibo.com/2/short_url/shorten.json?source={$app_key}&url_long={$url}"); $data = json_decode($result->getBody(), true); if (isset($data['error'])) { return false; } else { return $data['urls'][0]['url_short']; } }