zoukankan      html  css  js  c++  java
  • 小i机器人

        //机器人回复
        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);
        }
    

      

  • 相关阅读:
    no-return-assign (Rules) – Eslint 中文开发手册
    CSS 字体图标
    CSS 元素的显示与隐藏
    CSS 定位
    CSS 清除浮动
    CSS 浮动
    java 运算符
    Java 初识
    CSS3 完善盒模型
    CSS 盒子模型
  • 原文地址:https://www.cnblogs.com/txw1958/p/11189267.html
Copyright © 2011-2022 走看看