Home WeChat Applet WeChat Development asp.net develops WeChat public platform (4) follow events, user records, and reply to text messages

asp.net develops WeChat public platform (4) follow events, user records, and reply to text messages

Feb 23, 2017 pm 02:13 PM

The previous article has encapsulated all the messages and processed them in their own ways. This article starts with the first step of using - following. After following, the message will be recorded and text messages will be replied to the user. The following method: DoSub. In addition New users scan the QR code with parameters to follow the method: DoCodeNotSub.

1. Users follow the official account and return text messages and user records:

Assign values ​​to the message model based on the parsed XML reflection. Now make user judgment:

tb_User mUser =DALWei.InfoEntities<tb_user>(dbHome,u=>u.OpenId==mSub.FromUserName);
            if (mUser != null)
            {
                  //说明此用户以前关注过后来取消了
            }
            else
            {
                 //全新的用户,添加
            }</tb_user>
Copy after login

The complete method code is as follows:

tb_User mUser =DALWei.InfoEntities<tb_user>(dbHome,u=>u.OpenId==mSub.FromUserName);
            if (mUser != null)
            {

                if (mUser.State == 0)
                {
                    SText mStxt = new SText();
                    mStxt.ToUserName = mSub.FromUserName;
                    mStxt.FromUserName = mSub.ToUserName;
                    mStxt.CreateTime = mSub.CreateTime;
                    mStxt.Content = "很抱歉,您已经被系统拒绝服务,若有疑问请联系我们";
                    DALWei.SendText(mStxt);
                    return;
                }
                else
                {
                    mUser.SubTime = DateTime.Now;
                    DALWei.UpdateEntity(dbHome, mUser);
                }
            }
            else
            {
                mUser = new tb_User();
                mUser.InId = 0;
                mUser.OpenId = mSub.FromUserName;
                mUser.GroupId = 0;
                mUser.NickName = "";
                mUser.CreateTime = System.DateTime.Now;
                mUser.State = 1;
                mUser.PreFirst = "";
                mUser.SubTime = DateTime.Now;
                DALWei.AddEntity(dbHome,mUser);
            
            }</tb_user>
Copy after login

Modify the user's last attention time if it already exists, and add a new user if it does not exist; where the user needs to be considered if the user already exists In the case of state=0, that is, the user is disabled, a text message will be returned directly, indicating that the user has been disabled.

2. Reply to text message

The encapsulated sending text message model SText can be assigned and output :

SText mStxtA = new SText();
            mStxtA.ToUserName = mSub.FromUserName;
            mStxtA.FromUserName = mSub.ToUserName;
            mStxtA.CreateTime = mSub.CreateTime;
            mStxtA.Content =ReadXml.Menu();
            Often.ResponseToEnd(DALWei.SendText(mStxtA));
Copy after login

Among them, the ReadXml.Menu() method returns a default segment of characters, which is used as a normal text menu (there will be a custom menu later).

The text is as follows:

public static string  Menu()
        {
            string Content = "";
            Content += "欢迎使用/微笑\n\n";
            Content += "输入以下序号开始获取最新信息:\n";
            Content += "1,企业快报\ue102\n";
            Content += "2,行业要览\n";
            Content += "3,行情动态\n";
            Content += "4,焦点访谈\n";
            Content += "5,下游资讯\n";
            Content += "6,资讯中心\ue135\n";
            Content += "7,采购\ue42f\n";
            Content += "8,市场报告--VIP\ue035专属\n\n";
            Content += "输入其他关键字可以搜索\ue114\n";
            Content += "输入序号@关键字可以在指定类别下搜索,比如 1@马航\n";
            Content += "输入?或帮助 可以显示此菜单";
            return Content;
        }
Copy after login

Effect:

asp.net develops WeChat public platform (4) follow events, user records, and reply to text messages


##More Asp.net develops WeChat public platform (4) Follow events, user records, and reply to text messages. For related articles, please pay attention to the PHP Chinese website!



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

Hot AI Tools

Undresser.AI Undress

Undresser.AI Undress

AI-powered app for creating realistic nude photos

AI Clothes Remover

AI Clothes Remover

Online AI tool for removing clothes from photos.

Undress AI Tool

Undress AI Tool

Undress images for free

Clothoff.io

Clothoff.io

AI clothes remover

Video Face Swap

Video Face Swap

Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Tools

Notepad++7.3.1

Notepad++7.3.1

Easy-to-use and free code editor

SublimeText3 Chinese version

SublimeText3 Chinese version

Chinese version, very easy to use

Zend Studio 13.0.1

Zend Studio 13.0.1

Powerful PHP integrated development environment

Dreamweaver CS6

Dreamweaver CS6

Visual web development tools

SublimeText3 Mac version

SublimeText3 Mac version

God-level code editing software (SublimeText3)