Asp.net development of WeChat public platform (4) follow events, user records, reply to text messages

Source: Internet
Author: User
Tags openid
In the previous article, all messages have been encapsulated and each has its own method for processing. This article starts from the first step-follow, and then records the messages and replies the text message to the user. follow the method: doSub, in addition, the method for new users to scan the QR code with parameters: DoCodeNotSub. In the previous article, all messages have been encapsulated and each has its own method for processing. This article starts from the first step-follow, and then records the messages and replies the text message to the user. follow the method: doSub, in addition, the method for new users to scan the QR code with parameters: DoCodeNotSub.

1. text messages and user records returned by the user concerned public accounts:

Assign a value to the message model based on the parsed XML reflection. now you can determine the value:

Tb_User mUser = DALWei. InfoEntities
 
  
(DbHome, u => u. OpenId = mSub. FromUserName); if (mUser! = Null) {// indicates that this user has previously followed and has canceled} else {// brand new user, add}
 

The Complete Method code is as follows:

Tb_User mUser = DALWei. InfoEntities
 
  
(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 = "Sorry, you have been rejected by the system. if you have any questions, please contact us"; 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 );}
 

If a user already exists, modify the user's last Follow time. if the user does not exist, add a new user. if the user already exists, consider the case where the user state is 0, that is, the user is disabled, directly return a text message, prompting that the message has been disabled.

2. reply to text messages

The encapsulated text message model SText is assigned a value 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));

The ReadXml. Menu () method returns a default segment of characters and is used as a normal text Menu (custom menus will be available later ).

The text is as follows:

Public static string Menu () {string Content = ""; Content + = "welcome/Smile \ n"; Content + = "enter the following serial number to obtain the latest information: \ n "; Content + =" 1, Enterprise express \ ue102 \ n "; Content + =" 2, industry overview \ n "; Content ++ =" 3, market news \ n "; Content + =" 4, focal point Interview \ n "; Content + =" 5, downstream information \ n "; Content + =" 6, information center \ ue135 \ n "; Content + =" 7, procurement \ ue42f \ n "; Content + =" 8, market report-VIP \ ue035 exclusive \ n "; content + = "enter other keywords to search for \ ue114 \ n"; Content + = "enter the serial number @ keyword to search for the specified category, for example, 1 @ Ma Hang \ n "; Content + = "input? Or help to display this menu "; return Content ;}

Effect:

More articles about events, user records, and reply to text messages on asp.net public platform (4!

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.