. Net Enterprise code development (3) interface development in callback mode and. net callback
I. Preface
There are two modes for enterprise number applications: one is normal mode, which can only be used for simple webpage links and sending fixed messages. In order to allow the enterprise account user to better interact with the application, the callback mode is provided. This mode can forward the information sent by the user to a callback interface provided by the user, this interface parses the information sent by the user and then performs the corresponding action. In the callback mode, many items can be called, such as scan code, images, videos, and geographic location information.
In the Application Mode, select the callback mode, and then set three parameters (1. callback interface URL; 2. token; 3. the URL is the provided callback interface, which forwards the information provided by the user to this interface. The url we use here is http://m.xxx.com: 10000/WeiXin/MessageInterface /. Http Get is used for Interface Verification, and Post is used for interface obtaining messages. To set the callback mode, you must first implement the verification interface.
This interface verification provides the corresponding development kit, which is dedicated to c #. The main function of the development kit is to verify the signature and encrypt and decrypt it.
The Interface Verification Code is as follows:
public string MessageInterface() { string signature = Request.QueryString["msg_signature"]; string timestamp = Request.QueryString["timestamp"]; string nonce = Request.QueryString["nonce"]; string echostr = Request.QueryString["echostr"]; //Careysoft.Basic.Public.Log.LogWrite("111"); if (Request.HttpMethod.ToUpper() == "GET") { string decryptEchoString = ""; if (Careysoft.WeiXin.Public.WeiXinFunction.CheckSignature(m_Token, signature, timestamp, nonce, m_Corpid, m_EncodingAESKey, echostr, ref decryptEchoString)) { if (!string.IsNullOrEmpty(decryptEchoString)) { return decryptEchoString; } } }}
M_Token is the Token set in the callback mode, m_Corpid is the enterprise Id, m_EncodingAESKey is the AESKey set in the callback mode, and other parameters are the parameters passed in the callback mode.
The following is the CheckSignature function:
Public static bool CheckSignature (string token, string signature, string timestamp, string nonce, string corpId, string encodingAESKey, string echostr, ref string retEchostr) {empty wxcpt = new WXBizMsgCrypt (token, encodingAESKey, corpId); int result = wxcpt. verifyURL (signature, timestamp, nonce, echostr, ref retEchostr); if (result! = 0) {return false;} return true; // ret = 0 indicates that the verification is successful, and the retEchostr parameter indicates the plain text. You need to use retEchostr as the return parameter of the get request, returns the enterprise ID. // HttpUtils. SetResponse (retEchostr );}
WXBizMsgCrypt is the platform callback interface development kit. You can download and reference it.
Okay. This is the callback verification interface. With this interface, you can set the application mode to the callback mode!
In the next section, we will try to receive the information sent by the user from the callback interface and reply to the user.
See. net Enterprise ID development (4) receive and send Interface Information in callback Mode