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
Copy after login
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}
Copy after login
Parameters
Description
##access_token
Obtained voucher
expires_in
Voucher validity time, unit: seconds
WeChat will return in case of error Error code and other information, the JSON data packet example is as follows (this example is an invalid AppID error):
{"errcode":40013,"errmsg":"invalid appid"}
Copy after login
2. AppId and AppSecret Use the WeChat background to find advanced functions - Development mode After becoming a developer, you can see the appid and appsecert If there is no url and Token, you can first use the following test from Fangbei Studio to passURL: http://discuz.comli.com/test.php
Token: weixin
3. Obtain Access TokenThe program is implemented as follows
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 description
Every 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:
Return code
Description
-1
System busy
0
Request successful
40001
AppSecret error when obtaining access_token, or access_token is invalid
40002
Illegal credential type
40003
Illegal OpenID
40004
Illegal media file type
40005
Illegal file type
40006
Illegal file size
40007
Illegal media file id
##40008
Illegal message type
40009
Illegal image file size
##40010
Illegal voice file size
40011
Illegal video file size
##40012
Illegal thumbnail file size
40013
Illegal APPID
40014
Illegal access_token
##40015
Illegal menu type
40016
Number of illegal buttons
40017
Number of illegal buttons
40018
Illegal button name length
40019
Illegal button KEY length
40020
Illegal button URL length
40021
Illegal menu version number
40022
Number of illegal submenu levels
40023
Number of illegal submenu buttons
##40024
Illegal submenu button type
40025
Illegal submenu button name length
40026
Illegal submenu button KEY length
40027
Illegal submenu button URL length
40028
Illegal custom menu user
40029
Illegal oauth_code
40030
Illegal refresh_token
40031
Illegal openid list
40032
Illegal openid list length
40033
Illegal request characters, cannot contain \uxxxx format characters
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn