Tutorial 2: reply to simple text messages and reply to text messages. Tutorial 2: reply to a simple text message. before replying to the text message, we have completed the 'server configuration' of the public account and completed token verification. now let's try to reply to the user. tutorial 2: reply to simple text messages and reply to text messages.
We have completed 'server configuration' for the public account and completed token verification.
Now we try to reply to the text message sent by the user to the public account.
1. first, confirm that 'configuration' is 'enabled.
2. then we enter the 'sandbox test account' on the public platform, because in this status, we have little permission restrictions on various excuses, and
This is an independent public account with an independent 'appid ''' appsecret ''url' token', which does not affect the online environment!
This is an independent public account with an independent 'appid ''' appsecret ''url' token', which does not affect the online environment!
This is an independent public account with an independent 'appid ''' appsecret ''url' token', which does not affect the online environment!
(Three important events)
3. when you enter the 'sandbox test account', follow the prompts to scan the corresponding QR code. after that, the test account configuration information will appear,
Modify 'URL' and 'token' as needed'
Here we still use the previous sae url and Token, respectively:
URL: http://weixinshow001.sinaapp.com
Token: weixin
4. Next, we need to modify our previous 'index. php' file,
Because the previous functions only provide token verification,
No message reply function is implemented,
Now we use a wechat php library to reply to text information.
The valid code is as follows:
GetRequest ('content') returns the text $ this-> responseText ('received text message :'. $ this-> getRequest ('content') ;}// step 1 // Create a Wechat instance to process the information sent by the user. // aeskey can be written as needed, the test account does not use message encryption // token and the appid is the same as the information on the 'test number management' page, information that is not a public account // token and the appid is the same as that on the 'test account management' page, not the public account information // token, and the appid is the same as the information on the 'test account management' page, not the public account information (the important thing is to say three times) $ wechat = new TestWechat (array ('token' => 'weixin', 'aeskey' => 'XXX', 'appid '=> 'wx5d1fb434a1652ae8 ', 'debug' => true); $ wechat-> run ();
The code processing process is,
Step 1: Create a TestWechat instance to write configuration data.
Step 2: When a user sends a message to the public account, the user reads the text content sent by the user and replies it to the user as text information.
The final code structure is:
Our communication with the Test number is as follows:
Wechat php is in the attachment,
We will introduce wechat-php in more detail later.
Thank you for reading this article! Hope you can help beginners !! Sharing is also a pleasure !!! Please relay...
Before the token, we have completed the 'server configuration' of the public account and completed token verification. now we try to reply to the user...