Advanced Introduction to open-source OSS. Social, and oss. social
In the essay parsing of the open-source OSS. Social project, I will briefly share with you the outline design of the project in progress, which focuses on the solution ideas and processes without detailed implementation and usage introduction. In this article, I will break down the project structure, usage methods, and subsequent plans, hoping to make everyone smooth. At the same time, the current project is performing a transition to the. Net Standard class library. We believe that after a while, we can provide support for. net framework and. net core at the same time.
This project is one of the open-source projects of the entire OSS series. It is mainly for interface packaging of social networking products, while the project is currently in progress. In the entire project, it contains three major modules (see the preceding Section or the module division Mind Map). Here we will explain the three modules step by step.
1. Real-Time Message Module
The current module mainly processes Real-Time Messages. Its outline design idea and related flowchart have been introduced in the previous article. Here we will describe the specific implementation of the project.
First, I will introduce the file structure of the message module.
The current module is mainly in the Msg folder of the project, and the corresponding object is in the Msg/Mos folder. There are three classes in the folder:
WxMsgBaseHandler (basic message type processing)
WxMsgHandler (Advanced extended Message Processing)
Cryptography (Security Mode encryption makeup method)
In the object folder, the object mainly includes the base class (BaseMos), the common message type entity (RecMsgMos-basic message receiving entity, and the RecEventMsgMos-basic event message receiving entity) and the message response entity (ReplyMsgMos-Response Message entity). Here, you need to focus mainly on the BaseMos (BaseRecMsg, BaseRecEventMsg) and BaseReplyMsg, corresponding to the normal message, event message, and Response Message Base Class respectively.
After understanding the basic structure, let's take a look at the specific call method, because this module provides two call modes, which are described here:
1. Basic message modeThis mode is mainly used to call common message types. The entities in the RecMsgMos and RecEventMsgMos files also mainly define the basic mode for receiving messages, the applicable scenario of the current mode is that developers do not need to consider special event messages such as coupons. Use the current mode. The call demonstration is as follows:
A. the custom message processing class WxBasicMsgService inherits from WxBasicMsgHandler. You only need to delegate Handler to the relevant event (please note that it is different from the event of the event message) to add processing events, the passed message entity will correspond to each other based on different delegate events. For example, TextHandler corresponds to TextRecMsg.
The event corresponding to the current basic message type implementation is:
Normal message:
TextHandler (text message)
ImageHandler (image message)
VoiceHandler (voice message)
VideoHandler (video)
LocationHandler (location message)
LinkHandler (link message)
Event message:
SubscribeEventHandler (subscribe to events)
ScanEventHandler (SCAN event)
LocationEventHandler (reporting location events)
ClickEventHandler (click menu event)
ViewEventHandler (click the menu to jump to the event)
B. Declare configuration information
C. Page call
2. Advanced Message mode,This mode contains all the events in the basic mode. The main application scenario is to customize special event messages. The call method differs from the basic mode in the custom message processing class section. A simple custom advanced mode processing class is displayed here:
In advanced mode, you need to call the registration method. RegisterMsgHandler-registers the normal message, and RegisterEventMsgHandler-registers the event message. The first parameter is the message type name. If it is an event message, it is the event name. The third parameter is the specific logic processing delegate. The second parameter is the entity type of the received message. Here is an example. So I used LocationRecEventMsg directly. Of course, you can also define the receiver entity you need. Normal messages are inherited from BaseRecMsg, the event message is inherited from BaseRecEventMsg. For example:
Public class CustomRecMsg: BaseRecMsg
{
Protected override void FormatPropertiesFromMsg ()
{
Base. FormatPropertiesFromMsg ();
Content = this ["Content"];
}
Public string Content {get; set ;}
}
If you have other questions about the message module, you can add an osscoder public account to ask questions and I will solve them all at night.
Ii. functional interface module
This module is mainly a functional interface in the public account. The Global AccessToken needs to be called during the call. The interface file is mainly in the Offcial folder, and the submodule is classified according to the function object category, the file structure is similar to that in the message module. However, note that there are several class files in the same folder, but the class names are the same. For example, the Basic file contains the User, Menu, media and other api files, but the class names are the same: WxOffBasicApi.
The Partail keyword is used to ensure the structure is clear and the call is simple. For detailed classification, see the following structure:
That is, the functional module interfaces mainly include the following: WxOffBasicApi, WxOffCardApi, WxOffStatApi (statistics, short for), WxOffStoreApi, and WxOffAssist. You can directly declare the instance call. Of course, the current interface is not completely completed, it is mainly concentrated in the unmarked part in the figure. If you want to use an interface that does not exist, here we provide a method call example in the WxOffBaseApi base class. You only need to return a WxBaseResp or its subclass, wxBaseResp has the IsSuccess attribute, which can be used to determine the current returned result:
Of course, there is also a simple rule for file naming:
Request Entity: Wx + Action + object/Module name + Req/Resp (for example, WxAddMemberCardReq)
Object: Wx + object/Module name + Mo (for example, WxMemberCardMo)
Interface Class: Wx + Off + Module name + Api
3. Social interface module
The current module is mainly concentrated in the Sns folder, and its functions are user-oriented. This function mainly focuses on authorizing and obtaining the basic information of authorized users. The file composition is relatively simple, it provides two page authorization modes: PC scan authorization and mobile page authorization. The call method is also very simple,
The above is a description of the structure and calling method of several parts. All the instance code is in OSS. Social. Samples. You can download it from github or open source China.
Iv. OSS Project Planning
Currently, open-source projects include OSS. Common, OSS. Http, and OSS. Social. In the future, there will be three projects, payment, customer service, and user. In the last two weeks, my main task is to complete OSS. social project. net Standard project. net core support. You are also welcome to contribute code to complete this simple, basic, and practical series of projects.
Continued: here we will review the Real-Time Message Processing process. We can compare it with the usage introduction.
When you see this, you have read it. Thank you very much for your patience. If you have any other questions, please follow the Public Account (osscoder) to ask questions.