This article mainly introduces C# related content related to service server configuration in WeChat development. Interested friends can refer to it
The editor is very interested in WeChat development and has reviewed relevant articles on the Internet to organize them so that everyone can learn together.
1. Register an account - fill in the server configuration
on https://mp.weixin.qq.com/ WeChat public platform Register an account;
The service account is a WeChat public account applied by the company, and the subscription account is applied by an individual, with relatively few personal permissions;
After logging in to the official website of the WeChat public platform, manage the page in the backend of the public platform - On the developer center page, click the "Modify Configuration" button, fill in the server address (URL), Token and EncodingAESKey, where the URL is used by developers to receive WeChat messages and ##InterfaceURL of #event. The Token can be filled in by the developer arbitrarily and used to generate a signature (the Token will be compared with the Token contained in the interface URL to verify the security). EncodingAESKey is manually filled in by the developer or randomly generated, and will be used as the message body encryption and decryption key.
At the same time, developers can choose the message encryption and decryption methods: plain textmode, compatibility mode and security mode. The mode selection and server configuration will take effect immediately after submission. Developers are advised to fill in and select carefully. The default state of the encryption and decryption method is plaintext mode. Selecting compatibility mode and security mode requires configuring the relevant encryption and decryption codes in advance. For details, please refer to the documentation on message body signature and encryption and decryption.
URL must be port 80, and can only be on the server! ! !
2. Verify whether the URL is valid
private string Token = ConfigurationManager.AppSettings["Token"]; [HttpGet] [ActionName("Index")] public ActionResult Get(string signature, string timestamp, string nonce, string echostr) { if (CheckSignature.Check(signature, timestamp, nonce, Token)) { return Content(echostr);//返回隨機字符串則表示驗證通過 } else { return Content("failed:" + signature + "," + CheckSignature.GetSignature(timestamp, nonce, Token) + "。如果你在瀏覽器中看到這句話,說明此地址可以被作為微信公眾賬號后臺的Url,請注意保持Token一致。"); } } /// <summary> /// 檢查簽名是否正確 /// </summary> /// <param name="signature"></param> /// <param name="timestamp"></param> /// <param name="nonce"></param> /// <param name="token"></param> /// <returns></returns> public static bool Check(string signature, string timestamp, string nonce, string token = null) { return signature == GetSignature(timestamp, nonce, token); } /// <summary> /// 返回正確的簽名 /// </summary> /// <param name="timestamp"></param> /// <param name="nonce"></param> /// <param name="token"></param> /// <returns></returns> public static string GetSignature(string timestamp, string nonce, string token = null) { token = token ?? Token; var arr = new[] { token, timestamp, nonce }.OrderBy(z => z).ToArray(); var arrString = string.Join("", arr); //var enText = FormsAuthentication.HashPasswordForStoringInConfigFile(arrString, "SHA1");//使用System.Web.Security程序集 var sha1 = System.Security.Cryptography.SHA1.Create(); var sha1Arr = sha1.ComputeHash(Encoding.UTF8.GetBytes(arrString)); StringBuilder enText = new StringBuilder(); foreach (var b in sha1Arr) { enText.AppendFormat("{0:x2}", b); } return enText.ToString(); }
Submit the configuration. Only after successful verification can you continue to use more functions. If the submission fails, you can write a log yourself to check the reason.
The editor has just come into contact with WeChat development. I have compiled several articles on
asp.netWeChat development. Today I will start to compile relevant knowledge about C# WeChat development. Since I am also a beginner, If there are any mistakes or mistakes, please forgive me and we can make progress together.
The above is the detailed content of Using C# WeChat Development Server Configuration Instructions. For more information, please follow other related articles on the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

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

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)