WeChat public platform development (12) send customer service message _ PHP Tutorial

Source: Internet
Author: User
Public platform development (12) sends customer service messages. When a user actively sends a message to the public account (including sending information, clicking the custom menu, subscribing to events, scanning QR code events, successful payment events, and defending rights ),

When a user actively sends a message to the public account (including sending information, clicking a custom menu, subscribing to events, scanning QR code events, successful payment events, and defending rights ), message data will be pushed to developers. developers can call the customer service message interface within a period of time (currently changed to 48 hours) and send messages to common users by posting a JSON data packet, the number of sending Times is not limited within 48 hours. This interface is mainly used for customer service and other features with manual message processing links, so that developers can provide users with better services.

The official documentation provides only one interface for sending customer service messages. developers only need to POST a specific JSON data packet to implement message reply. Here, we plan to build a simple platform to record user messages and display them in the form of a web table. then we can reply to the messages.

First, we use the database to record the messages actively sent by the user, and then extract them to the page to reply to the message. Here we only discuss text messages. we will study other types of messages on our own.

3.1 create a data table

Create a data table tbl_customer to record user messages.

 () unsigned   AUTO_INCREMENT COMMENT ()   COMMENT ()   COMMENT    COMMENT  MyISAM   CHARSETutf8 ;

3.2 Create an SQL. func. php file

Create the _ query ($ _ SQL) {} function to execute the INSERT operation.

_ Query ((! = ('SQL execution failed '.

 'sql.func.php' _record_message(,,    _query("INSERT INTO tbl_customer(from_user,message,time_stamp) VALUES('','','')"

3.4 process and record text messages

A. introduce the function file that replies to text and the function file that records messages.

 'responseText.func.inc.php' 'record_message.func.inc.php';

B. record the message to the database and return it to the user. here, you can modify it to another text, for example, "Hello, the message has been received, and we will reply to you as soon as possible!" And so on.

          handleText(         = -> = (-> = ('Y-m-d H:i:s'(!(             _record_message(,, =              = _response_text(,  "Input something..."

Our final results are as follows. we mainly work on the "information management center" and other page la S. we will not repeat them here, but will only explain the message display.

4.1 Implementation

Introduce the database operation file, execute the paging module, execute the database query, and assign the query result to $ _ result for use below.

 'includes/sql.func.php' ,"SELECT id FROM tbl_customer",15);         = _query("SELECT * FROM tbl_customer ORDER BY id DESC LIMIT ,");

Traverse $ _ result and insert it into the table in sequence.

            
 <消息id<发送者<消息体<消息时间<操作< <<<<<<&message="
  
"<
  
  

Note:After each message, there is a "reply" operation. click this button to input the fromusername and the message sent by the user to the reply. php file to prepare for replying to the user message.

5.1 create customer service message reply function file customer. php

The interface URL for sending customer service messages is as follows:

https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=ACCESS_TOKEN

The JSON data packet format to be POST is as follows:


  

Therefore, according to the above prompt, we write the processing function _ reply_customer ($ touser, $ content). when calling the function, we can send a customer service message by passing in the touser and the content to be replied.

 _reply_customer(,    ="wxef78f22f877db4c2"="3f3aa6ea961b6284057b8170d50e2048"="https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".."&secret=".=(=json_decode(=-> = ''..''..'' = "https://api.weixin.qq.com/cgi-bin/message/custom/send?access_token=". = https_post(, = json_decode(  https_post(, =, CURLOPT_URL, , CURLOPT_SSL_VERIFYPEER, , CURLOPT_SSL_VERIFYHOST, , CURLOPT_POST, 1, CURLOPT_POSTFIELDS, , CURLOPT_RETURNTRANSFER, 1 = curl_exec( (curl_errno( 'Errno'.curl_error( 

Next, we will introduce the previously written function to the message reply page to implement the function of sending customer service messages.

5.2 click "reply" and bring the fromusername and message parameters to jump to reply. php.

5.3 reply. php page display

5.4 reply. php file analysis

 '../customer.php';

Form submitted to relpy. php, with action = relpy.

            
   <收件人:<" < <原消息:<" <<内 容:< << pre>
    

Action = reply action processing.

(['Action'] = "reply" = ['tousername' = ['content' = _ reply_customer (, (-> errcode = "0" ') the message is successfully replied! ', 'Index. php'

Note:Get touser and content in POST mode, and then call the _ reply_customer ($ touser, $ content) method for processing. if the processing is successful, "message reply successful!" is displayed !", Go to the index. php page to complete the process of sending the customer service message.

6.1 users send messages

6.2 platform message management

6.3 send customer service messages

Send customer service message again

Customer service message sent for test successful!

Http://files.cnblogs.com/mchina/customer.rar

Sending a customer service message is simple. you only need to POST a JSON data packet to the specified interface URL. Here we have extended and written it into a simple platform to facilitate enterprise management. There are also many areas to be supplemented and improved, such as recording messages sent by customer service, recording messages of the same user into a collection, and implementing message reply in other formats, readers need to think about development on their own.

David Camp

  • For business cooperation, contact the author QQ: 562866602
  • My ID: mchina_tang
  • Write to me: mchina_tang@qq.com

We always believe that sharing is a virtue |We Believe, Great People Share Knowledge...

Users (including sending information, clicking custom menu, subscribing to events, scanning QR code events, payment success events, and user rights protection) will...

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.