时间:2020-07-11加入收藏
function get_short($longUrl, $accessToken)
{
$url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=" . $accessToken;
$header[] = "Content-Type: application/json";
$postData = "{\"action\": \"long2short\", \"long_url\": \"$longUrl\"}";
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_HTTPHEADER, $header);
curl_setopt($ch, CURLOPT_POSTFIELDS, $postData);
$result = curl_exec($ch);
curl_close($ch);
return $result;
}