需要說明的是:
- 此方法是微信長連接配接轉【短連結】,不是轉永久連接配接
- 接口獲得條件:訂閱号無法開通此接口,【服務号】必須通過【微信認證】
第一步:擷取ACCESS_TOKEN
先在微信公衆号背景擷取APPID和APPSECRET
通過接口擷取ACCESS_TOKEN
GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
文檔:
https://developers.weixin.qq.com/doc/offiaccount/Basic_Information/Get_access_token.html第二步:長連接配接轉短連接配接
POST https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN
content-type: application/json
{
"action": "long2short",
"long_url":"https://mp.weixin.qq.com/s/mcChCB3vRKmte5a1oP0qVQ"
}
傳回結果
{
"errcode": 0,
"errmsg": "ok",
"short_url": "https:\/\/w.url.cn\/s\/AE7X97r"
}
https://developers.weixin.qq.com/doc/offiaccount/Account_Management/URL_Shortener.html