SimSimi is a cute intelligent chatbot that can have interesting conversations with users. This article mainly introduces examples of using the simsimi API for php.
SimSimi is a cute intelligent chatbot that can have interesting conversations with users. This article mainly introduces examples of using the simsimi API for php.
The Code is as follows:
Function simsimi ($ keyword ){
$ Keyword = urlencode ($ keyword ));
// ----------- Get COOKIE ----------//
$ Url = "http://www.simsimi.com /";
$ Ch = curl_init ($ url );
Curl_setopt ($ ch, CURLOPT_HEADER, 1 );
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
$ Content = curl_exec ($ ch );
List ($ header, $ body) = explode ("\ r \ n", $ content );
Preg_match ("/set \-cookie :( [^ \ r \ n] *);/iU", $ header, $ matches );
$ Cookie = $ matches [1];
Curl_close ($ ch );
// ----------- Capture and restore ----------//
$ Url = "http://www.simsimi.com/func/req? Lc = ch & msg = $ keyword & ft = 0.0 ";
$ Ch = curl_init ($ url );
Curl_setopt ($ ch, CURLOPT_REFERER, "http://www.simsimi.com/talk.htm? Lc = ch ");
Curl_setopt ($ ch, CURLOPT_RETURNTRANSFER, 1 );
Curl_setopt ($ ch, CURLOPT_COOKIE, $ cookie );
$ Content = json_decode (curl_exec ($ ch), 1 );
Curl_close ($ ch );
If ($ content ['result'] = '000000 '){
$ Content ['response'];
Return $ content ['response'];
} Else {
Return 'I will not answer this question ...';
}
}
?>
,