Tutorial 2: reply to simple text messages and reply to text messages

Source: Internet
Author: 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:

<? Php/*** example file of the public platform php sdk * // import the wechat php class library require ('wechat/wechat. php ');/*** demonstration class of the public platform * // inherit the Wechat class, here we implement the basic function class TestWechat extends Wechat {/*** triggered when a text message is received, reply to the received text message ** @ return void * // step 2 // This function is called when the user receives the text message sent to the Public Account () {// $ this-> 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 (); copy the code

 

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...

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.