


3.0 Obtain interface call credentials
①Interface description
access_token is the globally unique ticket of the official account. When the official account calls each interface All require access_token. Developers need to store it properly. At least 512 characters of space must be reserved for access_token storage. The validity period of access_token is currently 2h (7200s) and needs to be refreshed regularly. Repeated acquisition will cause the last access_token to become invalid.
Instructions on the use and generation of access_token required for API calls on the public platform:
1. In order to keep appsecrect confidential, the third party needs an access_token to obtain and Refreshed central control server. The access_token used by other business logic servers comes from the central control server and should not be refreshed individually, otherwise the access_token will be overwritten and affect the business;
2. The current validity period of the access_token is conveyed through the returned expire_in , currently the value within 7200 seconds. The central control server needs to refresh the new access_token in advance according to this valid time. During the refresh process, the central control server still outputs the old access_token. At this time, the public platform backend will ensure that both the old and new access_token are available within a short time of refresh, which ensures the smooth transition of third-party services;
3. The validity time of access_token may be adjusted in the future, so the central control server not only needs to actively refresh internally at regular intervals, but also needs to provide an interface for passively refreshing access_token, so that the business server can know that the access_token has been updated during API calls. In the case of timeout, the refresh process of access_token can be triggered.
How to get AppID and AppSecret! ?
The public account can use AppID and AppSecret to call this interface to obtain 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: Use the https protocol when calling all WeChat interfaces; also, if the third party does not use the central control server, but selects each business If each logical point refreshes access_taken, conflicts may occur, resulting in service instability.
②Request interface
Interface call request description:
/// <summary> /// 获取公众号的ACCESS_TOKEN /// </summary> /// <returns>返回操作凭据</returns> public string GetAccessToken() { if (HttpContext.Current.Cache["access_token"] == null) { string para = string.Format("grant_type=client_credential&appid={0}&secret={1}", AppID, AppSecret); string results = SendHTTPRequest("POST", "https://api.weixin.qq.com/cgi-bin/token", para); JObject obj = (JObject)JsonConvert.DeserializeObject(results); //*******************************设置access_token的过期机制************************** Cache cache = HttpContext.Current.Cache; cache.Insert("access_token", obj["access_token"].ToString(), null, DateTime.Now.AddSeconds(7000), System.Web.Caching.Cache.NoSlidingExpiration); //******************************************end************************************* return HttpContext.Current.Cache["access_token"].ToString(); } else { return HttpContext.Current.Cache["access_token"].ToString(); } }Return parameter description:

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

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

VSCode Windows 64-bit Download
A free and powerful IDE editor launched by Microsoft

DVWA
Damn Vulnerable Web App (DVWA) is a PHP/MySQL web application that is very vulnerable. Its main goals are to be an aid for security professionals to test their skills and tools in a legal environment, to help web developers better understand the process of securing web applications, and to help teachers/students teach/learn in a classroom environment Web application security. The goal of DVWA is to practice some of the most common web vulnerabilities through a simple and straightforward interface, with varying degrees of difficulty. Please note that this software

EditPlus Chinese cracked version
Small size, syntax highlighting, does not support code prompt function

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

Zend Studio 13.0.1
Powerful PHP integrated development environment
