Obtain the AccessToken and ASP. netaccesstoken by using the asp. NET public account.
Access_token is the globally unique interface call credential of the public account. access_token is required when the Public Account calls each interface. Developers need to properly store them. The storage of access_token must contain at least 512 characters. The validity period of access_token is currently 2 hours. You need to refresh it regularly. Repeated access_token acquisition will invalidate the last access_token. The following is an example of using ASP. NET WebForm to obtain the public account AccessToken. Code and documentation are provided.
First, the effect when no appid is input:
Get the correct result:
The long string is the AccessToken. The valid time is 2 hours in 7200 seconds.
The obtained result is in json format. You can use Newtonsoft. Json. dll to process json information and provide sample code in the next article. Reference: http://hovertree.com/h/bjag/l0aqhe0f.htm
Code of the HtAccessToken. aspx page:
<% @ Page Language = "C #" AutoEventWireup = "true" CodeBehind = "HtAccessToken. aspx. cs" Inherits = "ExampleHoverTree. HtWechat. HtAccessToken" %> <! DOCTYPE html>
HtAccessToken. aspx. cs code:
using HoverTree.HoverTreeFrame.HtWeb;using System;using System.Text;namespace ExampleHoverTree.HtWechat{ public partial class HtAccessToken : System.Web.UI.Page { protected void Page_Load(object sender, EventArgs e) { } protected void button_get_Click(object sender, EventArgs e) { literal_tips.Text = HtGetAccessToken(textBox_appid.Text, textBox_secret.Text); } string HtGetAccessToken(string appid, string appsecret) { string h_url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + appsecret; return HtWebHelper.GetHtmlByUrl(h_url, Encoding.Default); } }}
Download the HoverTreeTop source code for the GetHtmlByUrl (string url, System. Text. Encoding enCode) method of the HtWebHelper class in the HoverTreeFrame project. : Http://hovertree.com/h/bjaf/hv6cqe5n.htm
Description of how to use and generate access_token for API calls on the public platform:
1. It is recommended that developers of public accounts use the Central Control Server to obtain and refresh Access_token in a unified manner. access_token used by other business logic servers comes from the Central Control Server and should not be refreshed separately. Otherwise, conflicts may occur, as a result, access_token overwrite affects the business;
2. Currently, the validity period of the Access_token is expressed by the returned expire_in. Currently, the value is within 7200 seconds. The central control server needs to refresh the new access_token in advance based on the validity period. During the refresh process, the Central Control Server still outputs the old access_token. At this time, the background of the public platform will ensure that the new and old access_token are available within a short period of time, this ensures the smooth transition of third-party services;
3. The validity period of Access_token may be adjusted in the future. Therefore, the Central Control Server not only needs to regularly refresh internally, but also needs to provide an interface for passively refresh access_token, in this way, the Service server can trigger the refresh process of the access_token when the access_token has timed out during API calls. More: http://hovertree.com/h/bjag/x6usc7ya.htm
Recommended: http://www.cnblogs.com/roucheng/category/827769.html