An open-source dream of technology-Development Kit and open-source development kit
Due to the Spring Festival relationship, the progress of the WeixinSDK open-source project was delayed by about a month. It is worth noting that important modules of the project have been developed so far.
-About Projects
The background of this project is that the development of public accounts, service numbers, and even small programs is very common. All of the above development needs to be involved, but the official website does not provide the original one. the. Net SDK is for our use, and the official examples are also Bug-connected, so we decided to set up this open-source project.
There are already some excellent ones. net version of WeixinSDK, and the features are very comprehensive, the scalability is also very good, so you have to ask why we need to repeat the wheel, this question points, all my open-source projects are designed for project use. Another reason is for everyone to learn. each class of all projects has complete code annotations, and each class also has a corresponding unit test. The code is easy to understand, and interfaces or abstractions are also extended.
Let's talk less about follow me .....
-Project dependency
This project depends on some basic components. These components are also my own open source projects:
- Wlitsoft. Framework. Common [public class library]
- Wlitsoft. Framework. Common. Serializer. JsonNet [serialization implementation based on Json. Net]
- Wlitsoft. Framework. Common. Logger. Log4Net [log4net-based log recorder]
- Wlitsoft. Framework. Caching. Redis [distributed cache Redis implementation]
-Basic API
For time reasons, only some common APIs are implemented first.
-Token and js token acquisition;
-Template message;
-Oau2authorization APIs;
-User management interfaces;
The payment interface will be highlighted later.
-Token service
I mentioned the Token and js Token in the basic API just now. There are two tokens for the entire WeixinSDK: one is the Token used to call the interface, and the other is the JsTickect used by JSSDK, the official usage is that the token is valid for 7200 seconds and has a limit on the number of calls per day. Therefore, you need to cache the token for reuse.
-The TokenServiceBase token service base class provides basic implementation and abstraction of all token services.
-GeneralTokenService: A Basic token service implemented by using a local cache and a timer. This token service can be used for applications running on a single site on a single machine.
-DebugTokenService: Used to debug the Token service. You can directly specify a Token to call the interface in WeixinSDK.
-DistributedTokenService: distributed token service, which is implemented using distributed cache. It is mainly used in multi-host, multi-site scenarios.
-- Configure the token service
You need to execute it once in the application startup code.
GeneralTokenService tokenService = new GeneralTokenService();App.Builder.SetWeixinTokenService(tokenService);
-Message Processing
Some development capabilities are provided for us, such as the reception of some events (follow events, cancel follow events, button click events, etc.), reception of common text messages, voice messages, and other functions.
This SDK develops a simple message processing framework for the message processing module. You only need to write some implementation classes according to the specified writing method.
-WeixinSDK/src/WeixinSDK/Message/Request Message entity.
-WeixinSDK/src/WeixinSDK/Message/Response Message entity.
-WeixinSDK/src/WeixinSDK/Message/Process/Message processing logic.
WeixinMessageHandler is the main implementation code.
This article will be explained in detail in the future.
-- Configure Message Processing
Considering the scalability, message processing configuration supports multiple configuration methods, such as hard encoding and configuration files. You can also access Ioc and other related code to complete the message processing functions.
1. Hard-coding Configuration
MessageProcessConfiguration pc = new MessageProcessConfiguration();pc.MessageList.Add(new MessageConfiguration<RequestTextMessageProcessFake>(RequestMsgType.Text));App.Builder.SetWeixinMessageConfig(pc);
2. configuration file configuration
1 { 2 "Messages": [ 3 { 4 "MsgType": "Text", 5 "Type": "WeixinSDK.Config.Test.Fake.MessageProcessDemo01,WeixinSDK.Config.Test" 6 } 7 ], 8 "EventMessages": [ 9 {10 "EventType": "Subscribe",11 "EventKey": "Key01",12 "Type": "WeixinSDK.Config.Test.Fake.EventMessageProcessDemo01,WeixinSDK.Config.Test"13 }14 ]15 }
App.Builder.SmtWeixinMessageProcessConfigByJsonFile("./xxxx.json");
All message processing classes are composedWeixinMessageProcessBaseThe implementation code is as follows:
1 /************************************** **************************************** **************************************** 2 * description: 3 * message processing base class. 4*5 * change history: 6 * Author: Li Liang time: in July, a new version of 7*8 *********************************** **************************************** **************************************** **/9 namespace Wlitsoft. framework. weixinSDK. core10 {11 /// <summary> 12 // message processing base class. 13 /// </summary> 14 public abstract class WeixinMessageProcessBase: IWeixinMessageProcess15 {16 # region IWeixinMessageProcess member 17 18 /// <summary> 19 /// set the request message. 20 /// </summary> 21 public IRequestMessage RequestMessage {protected get; set;} 22 23 /// <summary> 24 /// obtain the corresponding message. 25 /// </summary> 26 public IResponseMessage ResponseMessage {get; protected set ;} 27 28 /// <summary> 29 // obtain or set whether to return an empty string to the server. 30 /// <para> the default value is <c> false </c>, when the message processing logic does not need to respond to the message to the sender, set this attribute to <c> true </c>. </Para> 31 // </summary> 32 public bool IsResponseEmptyString {get; set;} 33 34 // <summary> 35 // execute the processing. 36 /// </summary> 37 public abstract void Process (); 38 39 # endregion40 41 # region constructor 42 43 // <summary> 44 // initialize a new instance of <see cref = "WeixinMessageProcessBase"/>. 45 /// </summary> 46 protected weixinmessageprocxtender () 47 {48 49} 50 51 # endregion52 53 # region protection method 54 55 // <summary> 56 // obtain the corresponding type of request message based on the Request Message type. 57 /// </summary> 58 // <typeparam name = "TRequestMessage"> Request Message type. </Typeparam> 59 // <returns> request message object. </Returns> 60 protected TRequestMessage GetRequestMessage <TRequestMessage> () 61 {62 return (TRequestMessage) this. RequestMessage; 63} 64 65 # endregion66} 67}
-Payment
-MPPay: public account payment.
-H5Pay H5 payment.
-PayApi payment APIs.
-MchPayApi: Enterprise payment APIs.
-End
Project Source Code address: https://github.com/Wlitsoft/WeixinSDK
An open-source dream of technology-directory