小i机器人

匿名 (未验证) 提交于 2019-12-02 23:48:02

    //机器人回复     function xiaoirobot($openid, $content)     {         //定义app         $app_key = "";         $app_secret = "";          //签名算法         $realm = "xiaoi.com";         $method = "POST";         $uri = "/robot/ask.do";         $nonce = "";         $chars = "abcdefghijklmnopqrstuvwxyz0123456789";         for ($i = 0; $i < 40; $i++) {             $nonce .= $chars[ mt_rand(0, strlen($chars) - 1) ];         }         $HA1 = sha1($app_key.":".$realm.":".$app_secret);         $HA2 = sha1($method.":".$uri);         $sign = sha1($HA1.":".$nonce.":".$HA2);          //接口调用         $url = "http://nlp.xiaoi.com/robot/ask.do";         $ch = curl_init();         curl_setopt($ch, CURLOPT_URL, $url);         curl_setopt($ch, CURLOPT_HTTPHEADER, array('X-Auth:	app_key="'.$app_key.'", nonce="'.$nonce.'", signature="'.$sign.'"'));         curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);         curl_setopt($ch, CURLOPT_POST, 1);         curl_setopt($ch, CURLOPT_POSTFIELDS, "question=".urlencode($content)."&userId=".$openid."&platform=custom&type=0");         $output = curl_exec($ch);         if ($output === FALSE){             return "cURL Error: ". curl_error($ch);         }         return trim($output);     } 

  

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!