In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-01-18 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/03 Report--
This article mainly introduces how to use asp.net to develop Wechat public platform to obtain and deal with user messages, the article is very detailed, has a certain reference value, interested friends must read it!
Get user messages
The message sent by the user is contained in a HTTP POST request sent by the Wechat server. To get the message sent by the user, it is obtained from the data stream of the POST request.
Example of a HTTP request message that a Wechat server pushes messages to a server
POST / cgi-bin/wxpush? Msg_signature=477715d11cdb4164915debcba66cb864d751f3e6×tamp=1409659813&nonce=1372623149 HTTP/1.1
Host: qy.weixin.qq.com
Get data from a POST request
There may be two kinds of user messages obtained in this way: encrypted messages or unencrypted messages, which is related to the choice of message encryption and decryption mode when you configure a website on Wechat public platform. If plaintext mode is selected, it will not be encrypted. If compatibility mode is selected, both ciphertext and plaintext exist. If security mode is selected, user messages will be encrypted and need to be decrypted before further processing.
two。 Reply to user messages
Refer to Wechat public platform development documentation
Text message
{2}
Picture message
{2}
The message format is already in place, and then we just need to set the appropriate parameters.
ResponseContent = string.Format (ReplyType.Message_Text, FromUserName.InnerText, ToUserName.InnerText, DateTime.Now.Ticks, String.IsNullOrEmpty (reply)? "Sorry,I can not follow you.": reply)
3. Encryption and decryption of user messages and server messages
The Wechat public platform developer documentation provides examples of encryption and decryption in various languages, such as cantilever, magic, java and other languages. We only need to add two of these files to the project. Sample.cs is the sample code given by the Wechat team, which does not need to be referenced.
Just add references to the WXBizMsgCrypt.cs and Cryptography.cs files. To further encapsulate and facilitate invocation, I created a new class WeChatSecurityHelper
Two methods are defined in the class, which are used to encrypt (EncryptMsg) and decrypt (DecryptMsg), create a WXBizMsgCrypt object and call its method to encrypt and decrypt. For more information, please see the code example.
WeChatSecurityHelper
Using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;namespace Common {public class WeChatSecurityHelper {/ define Token, be consistent with Token on Wechat public platform / private const string Token = "StupidMe"; / AppId should be consistent with AppId on Wechat public platform / private const string AppId = "11111111111" / private const string AESKey = "pvX2KZWRLQSkUAbvArgLSAxCwTtxgFWF3XOnJ9iEUMG" for encryption; private static Tencent.WXBizMsgCrypt wxcpt = new Tencent.WXBizMsgCrypt (Token, AESKey, AppId); private string signature,timestamp,nonce; private static LogHelper logger = new LogHelper (typeof (WeChatSecurityHelper)); public WeChatSecurityHelper (string signature, string timestamp, string nonce) {this.signature = signature; this.timestamp = timest this.nonce = nonce } / encrypted message / / encrypted message public string EncryptMsg (string msg) {string encryptMsg= "; int result = wxcpt.EncryptMsg (msg, timestamp, nonce, ref encryptMsg); if (result = = 0) {return encryptMsg } else {logger.Error ("message encryption failed"); return ";}} / decrypt the message / message body / plaintext message public string DecryptMsg (string msg) {string decryptMsg ="; int result = wxcpt.DecryptMsg (signature, timestamp, nonce, msg,ref decryptMsg) If (result! = 0) {logger.Error ("message decryption failed, result:" + result);} return decryptMsg;} above is all the content of this article "how to use asp.net to develop Wechat public platform to obtain and deal with user messages". Thank you for reading! Hope to share the content to help you, more related knowledge, welcome to follow the industry information channel!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.