Tutorial two: Replying to a simple text message, replying to a text message _php tutorial

Source: Internet
Author: User

Tutorial Two: Reply to a simple text message, reply to a text message


We completed the "server Configuration" of the public number and completed token verification.
Now we try to reply to the text message that the user sent to the public number.

1. First we determine ' configure ' as ' enabled ' status.

2. We then enter the ' sandbox test account ' on the public platform, because in this state the restrictions on the various excuses are relatively small, and
This is an independent public number, has a separate ' appID ' ' appsecret ' url ' token ', does not affect the online environment!
This is an independent public number, has a separate ' appID ' ' appsecret ' url ' token ', does not affect the online environment!
This is an independent public number, has a separate ' appID ' ' appsecret ' url ' token ', does not affect the online environment!
(important thing to say three times)

3. Enter the ' sandbox test account ' when prompted to use their own code to scan the corresponding QR code, the completion of the test account configuration information will appear,
Modify the ' URL ' and ' Token ' according to your needs
I still use the URL and token of our SAE before, respectively:
Url:http://weixinshow001.sinaapp.com
Token:weixin

4. Next, we will revise our previous ' index.php ' file,
Because the previous feature only provides token validation,
Did not implement any message reply function,
Now we use the already written a WeChat PHP library, to achieve the text message reply.
The valid code is as follows:

 Php/** * Public platform PHP SDK sample file*/  //Import the WeChat PHP class library  require(' wechat/wechat.php '); /** * Public platform Demo class*/  //inherits the WeChat class, here realizes the message reply and accepts the basic function  classTestwechatextendsWechat {/** * Triggered when a text message is received, reply to received text message content * * @return void*/    //This function is called when you receive a text message from a user to the public number in step 2//    protected functionOntext () {//$this->getrequest (' content ') returns the text that the user sent to the public number      $this->responsetext (' received a text message: '.$this->getrequest (' content ')); }  }  //Step 1//Create a new instance of WeChat to handle the information sent by the user//aeskey can write freely, the test account is not using the message encryption//token and AppID and the "Test number Management" page of the same information, not the public number of information// Token and AppID are the same as the ' Test Number Management ' page, not the public information//token and AppID the same information as the ' Test Number Management ' page, not the public number.(important thing to say three times)$wechat=NewTestwechat (Array(    ' token ' = ' weixin ', ' aeskey ' = ' xxx ', ' appid ' and ' Wx5d1fb434a1652ae8 ', ' debug ' + =true    )); $wechat-run (); Copy Code

The process of code processing is that
Step 1: Create an instance of Testwechat to write various configuration data.
Step 2: When the user sends a message to the public, reads the text content sent by the user and replies to the user as a text message.

The final code structure is:

Our communication with the test number is as follows:

WeChat PHP in the attachment,
We will describe the use of wechat-php in more detail later.

Thank you for reading, please feel the heart! Hope can help the beginner of you!! Sharing is also a pleasure!!! Please relay ...

http://www.bkjia.com/PHPjc/1130145.html www.bkjia.com true http://www.bkjia.com/PHPjc/1130145.html techarticle Tutorial Two: Reply to a simple text message, reply to a text message before we completed the "server Configuration" of the public number, and completed token verification. Now we try to reply to the user send ...

  • Related Article

    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.