技术教程
当前位置:首页 > 技术教程

php生成微信短网址

( 更新: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;
}

相关阅读