Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert long links to short links through accesstoken in the development of Wechat official account

Shulou Source: shulou.com Published: 2022-06-03 15:54:47 11月12日 Update

This article mainly introduces how to convert long links into short links through accesstoken in the development of Wechat official account, which has a certain reference value, and interested friends can refer to it. I hope you can learn a lot after reading this article.

Business scenario: there are often some very long links in the development process of the official account of Wechat. At this time, if a QR code is generated, the recognition will be slow in the process of scanning the code. If it is stored in the database, the field length of the database will have to be set to be very long, so it is becoming more and more important to convert long links into short links.

Address of API description document:

Mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1443433600&token=&lang=zh_CN

API calls URL: https://api.weixin.qq.com/cgi-bin/shorturl?access_token=ACCESS_TOKEN

API request method: post

Parameter data passed via API: json

Example of passing parameters via API:

{"action": "long2short", "long_url": "https:\ / ss2.bdstatic.com\ / kfoZeXSm1A5BphGlnYG\ / icon\ / 7282.png"}

The API returns data:

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

Convert to json to:

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

The specific implementation code is as follows:

The effect is as shown in the figure:

Thank you for reading this article carefully. I hope the article "how to convert long links into short links through accesstoken in the development of Wechat official account" shared by the editor will be helpful to you. At the same time, I hope you will support us and follow the industry information channel. More related knowledge is waiting for you to learn!

Tags: Interface link article public development data database process important business code value example interest parameter at the same time address scenario field often Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Microsoft MySQL Shulou Information Docker macOS