冰豆网

分享网络精彩
bingdou.com.cn

php生成微信短网址

时间: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;
}

打 赏
打赏二维码

TGA: php 技巧

分享到:


官方微信二维码冰豆网官方微信公众号