WeChat Public platform Development (12) Send customer service message _php Tutorial

Source: Internet
Author: User
< span="">

When the user unsolicited message to the public number (including sending messages, click on the custom menu, subscribe to events, scan QR code events, payment success events, user rights), will send the message data to the developer, the developer for a period of time (currently modified to 48 hours) can call the customer service message interface, Post a JSON packet to send a message to a normal user without limiting the number of times it is sent within 48 hours. This interface is mainly used for customer service, such as the function of human message processing, to facilitate the developers to provide users with better quality service.

< span="">

The official documentation only provides an interface for sending customer service messages, and developers can reply to messages by post a specific JSON packet. Here, we are going to make a simple platform that can record user messages and display them in the form of a Web page, and then reply to the message.

First, we use the database to record the user's unsolicited message, and then extract it to display the page, for the message, to reply. Here we only discuss text messages, and for other types of messages, we do our own research.

< span="">

3.1 Creating a data table

Create a data table Tbl_customer to record user messages.

 () unsigned</strong></strong>  auto_increment COMMENT 
                 
                  ()   COMMENT < Span ' Span>
                       
                         ()   COMMENT 
                               
                                   COMMENT 
                                      
                                        Span key< span> MyISAM  charsetutf8;        
                                        
                               
                        
                

3.2 Creating a sql.func.php file

Create the _query ($_sql) {} function to perform the insert operation.

< span="">_query< span="">(< span="">  (!< span=""> < span=""> (' SQL execution failed '.< span="">< span="">  < span=""> < span="">< span="">< span="">< span="">< span="">< span="">

< span="">

< span="">< span="">< span="">' sql.func.php '  < span="">    < span="">  _record_message (< span="">  , < span="">   ,< span="">    < span="">  _query ( "INSERT< span="">    < span="">  Into Tbl_customer (from_user,message,time_stamp) VALUES ('< span="">',< span="">' ', '  < span="">')"< span="">

3.4 Processing and recording text messages

A. Introducing a function file that responds to text, introducing a function file that logs messages

< span="">< span="">< span=""> < span="">  < span=""> ' responseText.func.inc.php '  < span="">  < span=""> ' record_message.func.inc.php ';

B. Log messages into the database and return to the user just sent the message, here, you can modify the other text, such as: "Hello, the message has been received, 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 ..." span; }}< span>    
                                            
                                            
                                   
                                 
                        
                      

< span="">

Our final effect is probably as follows, the main work in the "Information Management Center" this piece, other page layout and so on, do not repeat here, only to explain the message show this piece.

4.1 Concrete Implementation

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

< span="">< span="">< span=""> < span="">  < span=""> ' includes/sql.func.php '  < span="">  < span=""> < span="">,< span="">< span="">< span="">< span=""> < span="">< span="">,< span="">");

Iterate through the $_result and insert the table in turn.

     <Message ID<Sent by<Message body<Message time<Operation
                            <<<  <      
                                                   
                                                     <    <  < span href< Span>&message="!--? php echo $_h tml[' message '?--'   <     !--  !-- !--     
                                                                    
                                                                           " /span>   
                                                                                 
                                                  

Note: after each message, there is a "Reply" action, click on the button, to the reply.php file in the Fromusername and the user sent messages, to reply to the user message to prepare.

< span="">

5.1 Create customer service message reply function file customer.php

The interface URL for sending a customer service message is as follows:

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

The JSON packet format that requires post is as follows:

< span="">

So, according to the above hint, we write the processing function _reply_customer ($touser, $content), when the call, incoming Touser and the content that needs to reply, can send the customer service message.

_reply_customer (, = "WXEF78F22F877DB4C2"= "3f3aa6ea961b6284057b8170d50e2048"= "Https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=".." &secret= ".=(=json_decode (=</strong>-= ''..''..''= "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
                                                               
                                                                < Span $curl span>, curlopt_postfields, 
                                                                
                                                                 
                                                                  , Curlopt_ Returntransfer, 1
                                                                   
                                                                     = curl_exec (
                                                                       
                                                                        (Curl_errno (
                                                                         
                                                                           ' errno '. Curl_error ( 
                                                                            
                                                                             
                                                                              
                                                                                < span;} span>   
                                                                               
                                                                              
                                                                           
                                                                        
                                                                    
                                                                  
                                                                
                                                               
                                                            /span> 
                                                                   

Below, we will introduce the function written above to the message reply page, and implement the function of sending the customer service message.

5.2 Click the "Reply" button and go to reply.php with the Fromusername and message parameters.

5.3 reply.php page display

5.4 reply.php File Analysis

< span="">< span="">< span="">'.. /customer.php ';

The form form is submitted to the relpy.php itself, with action=relpy.

  <Recipient:<
                        " 
                        <Original message:<
                                      " 
                                      <  <     content:   
                                                 <    !--  !--      <  
                                                            
                                                             < span = "Reply Message" "span>  "!--                 
                                                             

Action=reply action handling.

< span="">(< span="">[' action '] = = "Reply< span="">< span="">< span="">" [' Tousername '   [' < span=""> content '  < span="">  < span="">  < span="">  < span=""> =< span="">< span="">_reply_customer ((< span="">< span=""> ->errcode = = "0< span="">" message reply success!  < span=""> ', ' index.php '< span="">

Description: Post method gets touser, content, and then calls _reply_customer ($touser, $content) method processing, processing succeeds, then pops up "message reply succeeded!" , and then jump to the index.php page to complete the process of sending the customer service message.

< span="">

6.1 Users send messages

6.2 Platform Messaging Management

6.3 Send a drop-off service message

Send a customer service message again

Send customer service message Test success!

< span="">

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

< span="">

Sending the customer service message itself is simple, just post a JSON packet to the specified interface URL. Here we have expanded to write a simple platform that facilitates enterprise management. There are many areas that need to be supplemented and improved, for example, to record messages sent by customer service, to record messages of the same user as a collection, to implement other forms of message reply, etc., to be developed by the reader.

David Camp

    • For business cooperation, please contact the author qq:562866602
    • My number: Mchina_tang
    • Write to me: mchina_tang@qq.com

we always believe that sharing is a virtue | We believe, great people Share knowledge ...

http://www.bkjia.com/PHPjc/765825.html www.bkjia.com true http://www.bkjia.com/PHPjc/765825.html techarticle When the user unsolicited message to the public number (including the sending of information, click on the custom menu, subscribe to events, scan QR code events, payment success events, user rights), will ...

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