The overall framework demo source code of the first 6 articles of asp.net development of WeChat public platform (7)

高洛峰
Release: 2017-02-23 14:23:10
Original
1728 people have browsed it

The demo given here is the source code of the WeChat public platform with an overall framework. The so-called demo is something that can be directly demonstrated and used. Of course, it will not have very detailed things specific to the business level and data level. Everyone You can freely develop on this basis. As long as you read the first 6 articles, you will definitely be able to develop something of your own.

The demo is simple and easy to understand, anyone can understand it. Here are the differences between the demo and my actual project:

1. The demo is not connected to the database. The demo download can be used directly. Connecting to the database is not convenient for everyone. In the first article, the complete database has been open sourced, including the visual interface during design. If you want to connect to the database, add an EF after creating the database. Just connect. The connection method is in Part 2

2. The demo does not encapsulate the received WeChat message model. Because the purpose of encapsulating the received message is to record the message and add it to the database. Since there is no 1, there is no more. Part 3 of message encapsulation has been written;

3. There is no verification at the demo entrance. Cryptographic signature. Because the demo can be used by anyone after taking it back, if encrypted signature verification is added, many people may not be able to adjust it. For local testing, there is no encrypted signature for verification at all (in fact, local testing can directly return true), so that everyone can After understanding it, I removed the verification method. The code of the verification method is in the second article.

4. The demo does not have IOC injection or caching related. Not every business requirement requires caching and IOC injection, and not everyone has been exposed to these. For the sake of generality, they are removed. If you encounter problems related to IOC injection and cache processing in other projects, you can ask me, I will be happy to answer

Summary: The demo is a complete and simple framework for the WeChat public platform, and is suitable for any development Author; The previous articles related to the databases that need to be used in actual projects all have codes and operation methods;

Anyone can quickly create their own WeChat public platform based on the demo.

The most important thing is to share the overall idea~ The WeChat public platform is actually very simple. Most people have not figured out the ins and outs of message reception and processing. Take the entrance as an example. There may be many developments for these different cases. It will take a long time for anyone to figure it out (it has nothing to do with technical ability, mainly because some friends can't figure it out at once), and share this demo source code so that anyone can get started

public void LookMsgType(string msgType)
        {

            #region 判断消息类型
            switch (msgType)
            {
                case "text":
                    RText mText = new RText();
                    mText = ReadXml.GetModel<RText>(mText, xmlModel);
                    BLLWei.DoText(dbHome, mText);//文本消息
                    break;
                case "image":
                    RImg mImg = new RImg();
                    mImg = ReadXml.GetModel<RImg>(mImg, xmlModel);
                    BLLWei.DoImg(dbHome,mImg);//图片
                    break;
                case "voice": //声音
                    RVoice mVoice = new RVoice();
                    mVoice = ReadXml.GetModel<RVoice>(mVoice, xmlModel);
                    BLLWei.DoVoice(dbHome,mVoice);
                    break;

                case "video"://视频
                    RVideo mVideo = new RVideo();
                    mVideo = ReadXml.GetModel<RVideo>(mVideo, xmlModel);
                    BLLWei.DoVideo(dbHome, mVideo);
                    break;

                case "location"://地理位置
                    RLocation mLocation = new RLocation();
                    mLocation = ReadXml.GetModel<RLocation>(mLocation, xmlModel);
                    BLLWei.DoLocation(dbHome,mLocation);
                    break;
                case "link"://链接
                    RLink mLink = new RLink();
                    mLink = ReadXml.GetModel<RLink>(mLink, xmlModel);
                    BLLWei.DoLink(dbHome,mLink);
                    break;
                #region 事件
                case "event":

                    switch (ReadXml.ReadModel("Event", xmlModel))
                    {
                        case "subscribe":

                            if (ReadXml.ReadModel("EventKey", xmlModel).IndexOf("qrscene_") >= 0)
                            {
                                RCodeNotSub mNotSub = new RCodeNotSub();
                                mNotSub = ReadXml.GetModel<RCodeNotSub>(mNotSub, xmlModel);
                                BLLWei.DoCodeNotSub(dbHome,mNotSub);//未关注的新用户,扫描带参数的二维码关注
                            }
                            else
                            {
                                RSub mSub = new RSub();
                                mSub = ReadXml.GetModel<RSub>(mSub, xmlModel);
                                BLLWei.DoSub(dbHome,mSub);//普通关注
                            }
                            break;
                        case "unsubscribe":
                            RUnsub mUnSub = new RUnsub ();
                            mUnSub = ReadXml.GetModel<RUnsub>(mUnSub, xmlModel);
                            BLLWei.DoUnSub(dbHome,mUnSub);//取消关注
                            break;

                        case "SCAN":
                            RCodeSub mCodeSub = new RCodeSub();
                            mCodeSub = ReadXml.GetModel<RCodeSub>(mCodeSub, xmlModel);
                            BLLWei.DoCodeSub(dbHome,mCodeSub);//已经关注的用户扫描带参数的二维码
                            break;
                        case "LOCATION"://用户上报地理位置

                            RSubLocation mSubLoc = new RSubLocation();
                            mSubLoc = ReadXml.GetModel<RSubLocation>(mSubLoc, xmlModel);

                            BLLWei.DoSubLocation(dbHome, mSubLoc);
                            break;
                        case "CLICK"://自定义菜单点击

                            RMenuClick mMenuClk = new RMenuClick();
                            mMenuClk = ReadXml.GetModel<RMenuClick>(mMenuClk, xmlModel);
                            BLLWei.DoMenuClick(dbHome, mMenuClk);
                            break;
                        case "VIEW"://自定义菜单跳转事件

                            RMenuView mMenuVw = new RMenuView();
                            mMenuVw = ReadXml.GetModel<RMenuView>(mMenuVw, xmlModel);
                            BLLWei.DoMenuView(dbHome, mMenuVw);
                            break;
                    };
                    break;
                #endregion
            }
            #endregion
        }
Copy after login

I will also write articles in the future, Sharing process, just to share the development process, you can see that all the screenshots in these articles of mine have removed the WeChat ID, name, etc., although the screenshots were used when writing the article without any user's general account for testing .


#For more asp.net development WeChat public platform (7) first 6 articles on the overall framework demo source code, please pay attention to the PHP Chinese website!


Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template