小i机器人

php;gutter:true; //机器人回复 function xiaoirobot($openid, $content) { //定义app $app_key = ""; $app_secret = "";</p> <pre><code> //签名算法 $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); } </code></pre> <p>

Original: https://www.cnblogs.com/txw1958/p/11189267.html
Author: 方倍工作室
Title: 小i机器人

原创文章受到原创版权保护。转载请注明出处:https://www.johngo689.com/547017/

转载文章受原作者版权保护。转载请注明原作者出处!

(0)

大家都在看

亲爱的 Coder【最近整理,可免费获取】👉 最新必读书单  | 👏 面试题下载  | 🌎 免费的AI知识星球