WeChat public platform development (7) Chat Robot function development

Source: Internet
Author: User

The previous article introduced the development of the translation function of the public platform, achieving Chinese, English, and Japanese language translation, which can also be used in real life. In the next article, we will complete an interesting feature, that is, chatbot, which can chat with you to make you happy when you are bored.

In this experiment, we will retrieve the API provided by the little yellow chicken official (http://www.simsimi.com/), combined with crawling the pages of the little 9 robot (http://www.xiaojo.com/), complement each other. Simsimi is charged, but you can try a 7-day test and use 100 replies for free each day. You can use a 9th robot for unlimited use, provided that it is not officially blocked.

3.1 API & URL

Official API address: http://developer.simsimi.com/api

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

The free version is used for testing. The paid version is similar, but the URL address is different.

3.2 request example and parameter description

Request example:

http://sandbox.api.simsimi.com/request.p?key=your_trial_key=en=1.0=hi

Parameter description:

3.3 Return Value Analysis

  • 400-Bad Request.
  • 401-Unauthorized.
  • 404-Not found.
  • 500-Server Error.

4.1 register a simsimi account

URL: http://developer.simsimi.com/signUp

4.2 activate an account

4.3 obtain the API Key

5.1 call the xiaohuang chicken API

Call the simsim ($ keyword) function for processing. Replace "Your API Key" with the applied API Key.

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 = json_decode (, // encode the string in JSON format = ['response '(! (= (1: "I am tired today. I will chat with you tomorrow. "2:" The chicken goes to bed ~~ "3:" Call ~~ Call ~~ "4:" You have a lot to talk about. Don't talk to you. "5:" Thank you for your attention [Zhuo Jin Suzhou ]". "\ n ". "No.: zhuojinsz ". "\ n ". "Excellent splendid, immortal": "Thank you for your attention [zhuojin Suzhou ]". "\ n ". "No.: zhuojinsz ". "\ n ". "Excellent splendid, immortal"

Note:

Sometimes the yellow Rooster does not reply, so a judgment is added to the simsim () function. If $ response is not empty, $ response is returned. If $ response is empty, then a small code is added to randomly reply to the custom message, so that the user can be responsive.

5.2 call xiaojiu robot implementation

Xiaojiu robot does not provide APIs, so it can only crawl through webpages. The Code is as follows:

Xiaojo (= ("chat" = >= curl_init (); curl_setopt (, CURLOPT_URL, 'HTTP: // expires); 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: "I am tired today. I will chat with you tomorrow. "2:" The chicken goes to bed ~~ "3:" Call ~~ Call ~~ "4:" You have a lot to talk about. Don't talk to you. "5:" Thank you for your attention [Zhuo Jin Suzhou ]". "\ n ". "No.: zhuojinsz ". "\ n ". "Excellent splendid, immortal": "Thank you for your attention [zhuojin Suzhou ]". "\ n ". "No.: zhuojinsz ". "\ n ". "Excellent splendid, immortal"

5.3 shuanglong opera Feng

We can also integrate the preceding xiaohuang chicken and xiaojiu robot. The specific code is as follows:

Chatter (= ("chat" = >= curl_init (); curl_setopt (, CURLOPT_URL, 'HTTP: // optional); 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 ((! (. "[/: :) Xiaojiu]"-> simsim (). "[simsim/: D]"

 

Go to QQ Group 213260412 sharing to download and use it.

Please follow Zhuo Jin SuzhouPublic Account, Zhuo Jin SuzhouDeveloped and tested based on the SAE platform for mainstream features.

You can follow Zhuo Jin SuzhouThe public account performs function tests and obtains new application development.

1. log on to the client, and choose "add friend"> "Search number"> "zhuojinsz "..

2. Scan the QR code:

Zhuo Jin SuzhouMenu function:

At present, the menu functions are still under development and will be updated one after another...

 

    We Believe, Great People Share Knowledge...

    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.