This article introduces the concept and method of obtaining Access Token under the WeChat public platform.
1. Access Token
access_token is the globally unique ticket of the public account. The public account needs to use access_token when calling each interface. Under normal circumstances, access_token is valid for 7200 seconds. Repeated acquisition will cause the last access_token to become invalid.
The public account can use AppID and AppSecret to call this interface to obtain access_token. AppID and AppSecret can be obtained in development mode (you need to be a developer and your account has no abnormal status). Note that the https protocol must be used when calling all WeChat interfaces.
Interface call request description
http请求方式: GET https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET
Parameter description
Parameter | Is it necessary | Explanation |
---|---|---|
grant_type | Yes | Get access_token and fill in client_credential |
appid | is | The only credential for third-party users |
secret | is | The unique credential key for third-party users, both appsecret |
Return instructions
Under normal circumstances, WeChat will return the following JSON data packet to the public account:
{"access_token":"ACCESS_TOKEN","expires_in":7200}
Parameters | Description |
---|---|
Obtained voucher | |
Voucher validity time, unit: seconds |
{"errcode":40013,"errmsg":"invalid appid"}2. AppId and AppSecret Use the WeChat background to find advanced functions - Development mode
Token: weixin
$appid = ""; $appsecret = ""; $url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=$appid&secret=$appsecret"; $ch = curl_init(); curl_setopt($ch, CURLOPT_URL, $url); curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE); curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, FALSE); curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1); $output = curl_exec($ch); curl_close($ch); $jsoninfo = json_decode($output, true); $access_token = $jsoninfo["access_token"];You can also splice the address directly in the browser address bar, and after execution, obtain The following data
{"access_token":"N2L7KXa084WvelONYjkJ_traBMCCvy_UKmpUUzlrQ0EA2yNp3Iz6eSUrRG0bhaR_viswd50vDuPkY5nG43d1gbm-olT2KRMxOsVE08RfeD9lvK9lMguNG9kpIkKGZEjIf8Jv2m9fFhf8bnNa-yQH3g","expires_in":7200}The parameter description is as follows
##Parameter
|
Description
|
||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
Obtained voucher | ##expires_in | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
The validity time of the voucher, unit: seconds |
Or use the official interface debugging tool, the address is: Use the web debugging tool to debug the custom menu interface Click to check the problem and get In this way, you also get the access token Attachment: Global return code descriptionEvery time a public account calls an interface, it may get a correct or incorrect return code. Developers can debug the interface based on the return code information and troubleshoot errors. The global return code description is as follows:
|

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

SublimeText3 Chinese version
Chinese version, very easy to use

SublimeText3 English version
Recommended: Win version, supports code prompts!

MantisBT
Mantis is an easy-to-deploy web-based defect tracking tool designed to aid in product defect tracking. It requires PHP, MySQL and a web server. Check out our demo and hosting services.

Dreamweaver CS6
Visual web development tools

WebStorm Mac version
Useful JavaScript development tools