需要说明的是:
- 此方法是微信长连接转【短链接】,不是转永久连接
- 接口获得条件:订阅号无法开通此接口,【服务号】必须通过【微信认证】
第一步:获取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