Access to the Java version of wechat payment_ token

access_ Token is the official account of the official account. When the public number calls the interfaces, it needs access_. token。 Developers need to keep it properly. access_ At least 512 character space should be reserved for token storage. access_ The validity period of the token is currently 2 hours. It needs to be refreshed regularly. Repeated acquisition will result in the access obtained last time_ The token is invalid.

Access required for API call of public platform_ Description of token usage and generation method:

1. In order to keep appsecrect confidential, the third party needs an access_ The central control server for token acquisition and refresh. Access used by other business logic servers_ The tokens are from the central control server and should not be refreshed separately, otherwise access will be caused_ The service is affected by token coverage; 2. Current access_ The validity period of the token is determined by the returned expire_ In, which is currently within 7200 seconds. The central control server needs to refresh the new access in advance according to this effective time_ token。 During the refresh process, the external output of the central control server is still the old access_ Token. At this time, the background of the public platform will ensure that the new and old access will be updated in a short time_ Tokens are available, which ensures the smooth transition of third-party services; 3、access_ The effective time of the token may be adjusted in the future, so the central control server not only needs to refresh actively internally, but also needs to provide passive refresh access_ Token interface, so that the business server can know access in API call_ When the token has timed out, access can be triggered_ Refresh process of token.

If the third party does not use the central control server, but selects each business logic point to refresh access_ Token, then conflicts may occur, resulting in service instability.

The official account can be called by AppID and AppSecret to get access_. token。 Appid and appsecret can be obtained from the official website of wechat public platform - Developer Center page (you need to have become a developer and the account has no abnormal status). Note that HTTPS protocol should be used when calling all wechat interfaces.

Interface call request description HTTP request method: get https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=APPID&secret=APPSECRET

Parameter description

Return description

Normally, WeChat will return the following JSON packets to the official account: {"access_token": "ACCESS_TOKEN", "expires_in": 7200})

In case of error, wechat will return error code and other information. An example of JSON packet is as follows (this example is an invalid appid error): {"errCode": 40013, "errmsg": "invalid appid"}

2. Code implementation

Appid and appsecret can be queried in the public account

The above is the whole content of this article. I hope it will be helpful to your study, and I hope you can support programming tips.

The content of this article comes from the network collection of netizens. It is used as a learning reference. The copyright belongs to the original author.
THE END
分享
二维码
< <上一篇
下一篇>>