WeChat Public Platform Development (vii) Chat robot function Development _php Tutorial

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

The previous article introduced the development of the translation function of the public platform, which realized the translation of Chinese, English and Japanese languages, and could be used in real life. In the next article, we will complete a more interesting feature, that is, chat robot, you can be bored when you chat with you to make you happy.

< span="">

In this experiment, we will pick up the API provided by the http://www.simsimi.com/, which is supplemented by the Web pages that crawl the small nine robots (http://www.xiaojo.com/). Simsimi is charged, but you can try the 7-day Test and use 100 replies a day for free; the small nine robots can be used without restrictions, but only if the official is not shielded.

< span="">

3.1 API & URL

Official API Address: HTTP://DEVELOPER.SIMSIMI.COM/API

Request URL:http://sandbox.api.simsimi.com/request.p

Here is the free version of the test, similar to the paid version, but the URL address is different.

3.2 Sample Request and parameter description

Sample Request:

Http://sandbox.api.simsimi.com/request.p?key=your_trial_key< span="">=en< span="">=1.0   < span=""> =hi

Parameter description:

< p="">

Language code, supported languages, Simplified Chinese with ch, Traditional Chinese en, English with en, please refer to for more details: http://developer.simsimi.com/lclist

< p="">

0.0: Unfiltered (contains curse, sexual content);

1.0: Filter uncivilized words (only Korean is supported temporarily)

< p="">

3.3 Return value analysis

Result: Execution results return code

      • < span="">
  • 400-bad Request.
  • 401-unauthorized.
  • 404-not found.
  • 500-server Error.

ID: The message ID of the reply (only if result=100 is available)

Response: Reply Message (This is only available when result=100)

< p="">

< span="">

4.1 Register Simsimi Account

Url:http://developer.simsimi.com/signup

4.2 Activating your Account

4.3 Get API Key

< span="">

5.1 Call small yellow chicken API implementation

Call the Simsim ($keyword) function and replace the "Your API Key" with the API key you requested.

         Simsim (="41250a68-3cb5-43c8-9aa2-d7b3caf519b1"= "http://sandbox.api.simsimi.com/request.p?key=".." &lc=ch&ft=0.0&text= ".=(   //Read the entire file into a string  < span="">=json_decode (,</strong></strong>< span="">//  encode a string in JSON format =[' Response '(!( =(1,5
                                   
                                     (
                                      
                                        1:  The chicken is tired today, will accompany you to chat again tomorrow. "
                                         
                                          
                                           
                                             2: " the chicken sleeps. 
                                              
                                               
                                                
                                                  3:  "whistling ~ ~ ~" 
                                                   
                                                    
                                                     
                                                       4:  "You talk so much, you're not talking." 
                                                        
                                                         
                                                          
                                                            5:  "Thank you for your interest in" Zhuo Jin Suzhou "." \ n "." Number: Zhuojinsz "." \ n "." Excellent splendid, Bandai Immortal "
                                                             
                                                              
                                                               
                                                                :  "Thank you for your interest in" Zhuo Jin Suzhou " "." \ n "." Number: Zhuojinsz "." \ n "." Brilliant Splendid, Bandai Immortal "
                                                                  
                                                                   
                                                                     
                                                                     
                                                                    
                                                                
                                                               
                                                           
                                                        
                                                     
                                                   
                                                
                                              
                                           
                                         
                                       
                                   

Description

Because sometimes the small yellow chicken does not reply, so in the Simsim () function added a judgment, if $response is not empty, then return $response; If $response is empty, add a small code to randomly reply to the custom message, So you can do whatever you like.

5.2 Call small nine robot implementation

Small nine robots do not provide APIs, it can only be crawled through web pages, the code is as follows:

         Xiaojo (=("Chat" == Curl_init ();curl_setopt (, Curlopt_url, ' http://www.xiaojo.com/bot/chata.php ');curl_setopt (, Curlopt_httpheader,, Curlopt_header, 0);curl_setopt (, Curlopt_returntransfer, 1);curl_setopt (, Curlopt_post, 1);curl_setopt (, Curlopt_postfields,= Curl_exec ();Curl_close ((!( =(1,5</strong>
                                                   
                                                     (
                                                      
                                                        1:  The chicken is tired today, will accompany you to chat again tomorrow. "
                                                         
                                                          
                                                           
                                                             2: " the chicken sleeps. 
                                                              
                                                               
                                                                
                                                                  3:  "whistling ~ ~ ~" 
                                                                   
                                                                    
                                                                     
                                                                       4:  "You talk so much, you're not talking." 
                                                                        
                                                                         
                                                                          
                                                                            5:  "Thank you for your interest in" Zhuo Jin Suzhou "." \ n "." Number: Zhuojinsz "." \ n "." Excellent splendid, Bandai Immortal "
                                                                             
                                                                              
                                                                               
                                                                                :  "Thank you for your interest in" Zhuo Jin Suzhou " "." \ n "." Number: Zhuojinsz "." \ n "." Brilliant Splendid, Bandai Immortal "
                                                                                  
                                                                                   
                                                                                     
                                                                                     
                                                                                    
                                                                                
                                                                               
                                                                           
                                                                        
                                                                     
                                                                   
                                                                
                                                              
                                                           
                                                         
                                                       
                                                   

5.3 Double Dragon Play Phoenix

We can also integrate the small yellow chicken and the small nine robots, the code is as follows:

         Chatter=("Chat" == Curl_init ();curl_setopt (, Curlopt_url, ' http://www.xiaojo.com/bot/chata.php ');curl_setopt (, Curlopt_httpheader,
                     
                      , Curlopt_header, 0);  curl_setopt (, Curlopt_returntransfer, 1);  curl_setopt (, Curlopt_post, 1);  curl_setopt (, Curlopt_postfields, 
                                 
                                   = curl_exec ();  curl_close (
                                       
                                         (! (
                                           
                                             . " [/::) small nine] "
                                              
                                                ->simsim ( Span $keyword span>). " [simsim/::D] "
                                                    
                                                       
                                                
                                              
                                          
                                  
                     

< span="">

< strong="">

< strong="">Please go to QQ group 213260412 share download use.

< strong="">< span="">

Please pay attention to Zhuo Kam Suzhou public account, Zhuo Kam Suzhou based on the development of SAE platform, for the mainstream function of the development test.

You can take A look at the Suzhou public account to perform functional testing and get new application development.

1. Login client, friends, add friends --Search number---Zhuojinsz, find and follow.

2. Scan QR Code:

Zhuo Jin Suzhou menu features:

The current menu features are still under development, will be updated in succession, please look forward to ...

< strong="">

    • < li="">

    < p="">

    < p="">

      • < li="">
      • < li="">
      • < li="">

      < strong="">We believe, great people Share knowledge ...

      http://www.bkjia.com/PHPjc/440165.html www.bkjia.com true http://www.bkjia.com/PHPjc/440165.html techarticle The previous article introduced the development of the translation function of the public platform, which realized the translation of Chinese, English and Japanese languages, and could be used in real life. In this next article, we ...

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