/**
* 长链接转短链接接口
*
* @string $long_url 需要转换的长链接,支持http://、https://、weixin://wxpay 格式的url
*
* @return array(err, data)
* - `err`, 调用失败时得到的异常
* - `res`, 调用正常时得到的对象
*
* Examples:
* ```
* list($err, $data) = $api->shorturl('http://me.diary8.com/category/web-front-end.html');
* echo $data->short_url;
* ```
* Result:
* ```
* http://w.url.cn/s/ABJrkxE
* ```
*/
public function shorturl($long_url)
{
$url = self::API_DOMAIN . 'cgi-bin/shorturl?access_token=' . $this->get_access_token();
$xml = '{"action":"long2short","long_url":"' . $long_url . '"}';
$res = HttpCurl::post($url, $xml, 'json');
// 异常处理: 获取时网络错误
if ($res === FALSE) {
return Error::code('ERR_GET');
}
// 判断是否调用成功
if ($res->errcode == 0) {
return array(NULL, $res);
} else {
return array($res, NULL);
}
}