


asp.net develops WeChat public platform (4) follow events, user records, and reply to text messages
Feb 23, 2017 pm 02:13 PMThe 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) ????????????{ ??????????????????//說明此用戶以前關(guān)注過后來取消了 ????????????} ????????????else ????????????{ ?????????????????//全新的用戶,添加 ????????????}</tb_user>
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?=?"很抱歉,您已經(jīng)被系統(tǒng)拒絕服務(wù),若有疑問請(qǐng)聯(lián)系我們"; ????????????????????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>
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));
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?+=?"輸入以下序號(hào)開始獲取最新信息:\n"; ????????????Content?+=?"1,企業(yè)快報(bào)\ue102\n"; ????????????Content?+=?"2,行業(yè)要覽\n"; ????????????Content?+=?"3,行情動(dòng)態(tài)\n"; ????????????Content?+=?"4,焦點(diǎn)訪談\n"; ????????????Content?+=?"5,下游資訊\n"; ????????????Content?+=?"6,資訊中心\ue135\n"; ????????????Content?+=?"7,采購\ue42f\n"; ????????????Content?+=?"8,市場(chǎng)報(bào)告--VIP\ue035專屬\n\n"; ????????????Content?+=?"輸入其他關(guān)鍵字可以搜索\ue114\n"; ????????????Content?+=?"輸入序號(hào)@關(guān)鍵字可以在指定類別下搜索,比如?1@馬航\n"; ????????????Content?+=?"輸入?或幫助?可以顯示此菜單"; ????????????return?Content; ????????}
Effect:

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

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

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)
