[Original] [Download] Senparc. Weixin. MP-WeChat public platform SDK (C #)-supported WeChat 4.5 APIs

Source: Internet
Author: User

I am planning to build a robot and need to use ASP. NET. I found a php sdk without C #, so I wrote a script and completed the basic functions.

Public platform address: http://mp.weixin.qq.com

Senparc. Weixin. MP address: http://weixin.senparc.com

All source code (SDK + example): https://github.com/JeffreySu/WeiXinMPSDK (new version released, you can view the latest code and tutorials on github)

Technical Exchange QQ group: 300313885

Scan the following QR code to add a test account as a friend (send text, location, and image information after adding it to test the feedback ):

Note: Before starting development, you need to apply for a public account, enable "keyword auto-reply => public platform message interface", and set token and other information as prompted.

All Senparc. Weixin. MP project files are as follows:


(The project has been updated. Please go to https://github.com/jeffreysu/weixinmpsdk.pdf or synchronize the latest code)

Several key classes of Senparc. Weixin. MP are described as follows:

  • Entities/Request *. cs is used to receive Entities automatically sent from the platform to the server (XML is sent), including text, location, and image.
  • Entities/Response *. cs is the Information Entity (eventually converted to XML) used for feedback to the sender, including text and News (text ).
  • Helpers/EntityHelper. cs is used for conversions between entities and XML (because there are many fields and types that require special processing, XML serialization cannot be used here)
  • Helpers/MsgTypeHelper. cs is used to obtain the Message Type
  • CheckSignature. cs verification request validity class
  • Enums. cs Enumeration
  • RequestMessageFactory. cs is used to automatically generate entities of different Request types and fill in necessary data.

Several key classes and important methods of Senparc. Weixin. MP (sort by general process)

  1. Generate a verification string: Senparc. weixin. MP. checkSignature. getSignature (string timestamp, string nonce, string token = null), returns the verification string encrypted by SHA1 based on the data provided by the platform (note that the token must be consistent with the public platform setting)
  2. Verification request: Senparc. Weixin. MP. CheckSignature. Check (string signature, string timestamp, string nonce, string token = null), verify whether the request is valid
  3. Request Entity: var requestMessage = Senparc. weixin. MP. requestMessageFactory. getRequestEntity (XDocument doc); automatically generates entities that can be used for operations based on different request types (doc only needs to use XDocument. parse (xmlString) can be generated), requestMessage. msgType is the request Enumeration type.
  4. Make judgments and perform various operations.
  5. Create an object of the response type as needed, such as var responseMessage = ResponseMessageBase. CreateFromRequestMessage (requestMessage, ResponseMsgType. Text) as ResponseMessageText; to return Text type information.
    Note: After v0.3, this method can be abbreviated:Var responseMessage = ResponseMessageBase. CreateFromRequestMessage <ResponseMessageText> (requestMessage );
  6. Currently, only the data returned by XML is accepted, so a conversion is required before returning: XDocument responseDoc = Senparc. weixin. MP. helpers. entityHelper. convertEntityToXml (responseMessage); var xmlString = responseDoc. toString ();
  7. The automatic response process for the entire public account has ended.

All Senparc. Weixin. MP source code and sample code are open-source (for example, ASP. net mvc 4 and. NET 4.0). To improve compatibility,Senparc. Weixin. MPThe source code uses. NET 3.5 ):

Https://github.com/JeffreySu/WeiXinMPSDK


(Contains three folders: Senparc. Weixin. MP, Senparc. Weixin. MP. BuildOutPut, Senparc. Weixin. MP. Sample, which correspondSenparc. Weixin. MP. dll source code project,Senparc. Weixin. MP. dll output directory and Web example. We recommend that you test the Web sample on the public network so that the public platform can automatically send it.)

The SDK is still being tested. You are welcome to give your valuable comments!

 

Supplement:

About direct useSenparc. Weixin. MP. SampleIf you deploy it on a server for testing, pay attention to the following points:

  1. After entering the public account background, goAdvanced functions> Development Mode> Become a developer, EditInterface Configuration InformationIn the Url, enter the Url of the default port (80), as shown in figureHttp://weixin.senparc.com/weixin(Note the following/WeixinMust be added. This is a Controller address used for verification)
  2. To ensure securityInterface Configuration InformationIt is better to enter a complex string inSenparc. Weixin. MP. Sample/Controllers/WeixinController. csModify the Token in to make it match, for example:

 

AboutSenparc. Weixin. MP. TestUnit test item:All core Senparc. Weixin. MP code has passed the unit test. Users without Internet deployment conditions can also useSenparc. Weixin. MP. TestThe unit tests provided by the project are also applicable to functions that are not officially released and cannot be actually tested, such as message push:


Corresponding test version: v0.3.1

 

Update history: https://github.com/JeffreySu/WeiXinMPSDK/blob/master/Senparc.Weixin.MP.BuildOutPut/readme.md

 

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.