MENU

php生成微信短网址

January 17, 2020 • php

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;
}
转载请注明出处,并添加原文地址

Archives QR Code Tip
QR Code for this page
Tipping QR Code