Converts a long URL to a short URL.

Use cases: A long URL for generating a product or payment QR code may slow down the scanning speed and affect its success rate. This API is used to convert the long URL to a short URL to increase the scanning speed and success rate.

API Request Format

Developers can use OpenID to get basic user information. Be sure to use the HTTPS protocol.

HTTP request method: POST
https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN

Parameters

Parameter Required Description
access_token Yes The credential for API call
action Yes Enter long2short, which indicates converting a long URL to a short URL
long_url Yes The long URL to be converted. URLs starting with http://, https://, and weixin://wxpay are supported.

Call example

curl -d "{\"action\":\"long2short\",\"long_url\":\"http://wap.koudaitong.com/v2/showcase/goods?alias=128wi9shh&spm=h56083&redirect_count=1\"}" "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN"

Response Description

For a successful request, Weixin returns the following JSON packet to the Official Account:

{"errcode":0,"errmsg":"ok","short_url":"http:\/\/w.url.cn\/s\/AvCo6Ih"}

Parameters

Parameter Description
errcode Error code
errmsg Error message
short_url Short URL

When an error occurs, Weixin will return an error code and related information. An example of the JSON packet (for an invalid AppID error) is shown below:

{"errcode":40013,"errmsg":"invalid appid"}