【php-demo-关键词触发】图灵调取demo,可直接使用

【关键词触发】图灵调取demo,保存为 test1.php 可直接调用

$s['wxuin']=trim($_POST['wxuin']);
$s['gid']=trim($_POST['groupid']);
$s['gname']=unicode2utf8(trim($_POST['groupnickname']));
$s['as']=trim($_POST['as']);
$s['nickname']=str_replace("\"","",$_POST['usernickname']);
$s['nickname']=str_replace("?","",$s['nickname']);
$s['nickname']=str_replace("&","&",$s['nickname']);
$s['nickname'] =unicode2utf8(trim($s['nickname']));
$s['skw']=trim($_POST['skw']);
$s['content']=unicode2utf8(trim($_POST['content']));
$time=time();


if(strpos($s['content'],'#')===0){

    $url = 'http://www.tuling123.com/openapi/api';
	//下面输入图灵key
    $post_data['key']       = '';
    $post_data['info']      = $s['content'];
    $post_data['userid'] = $s['as'];
    $res =request_post($url, $post_data);     
    $ress = json_decode($res,true);
    echo '{"rs":1,"tip":"@'.$s['nickname'].' '.$ress['text'].'","end":0}';
}

function unicode2utf8($str){
$t = preg_replace("#\\\u([0-9a-f]{4})#ie", "iconv('UCS-2BE', 'UTF-8', pack('H4', '\\1'))", $str);
return $t;
}
/**
     * 模拟post进行url请求
     * @param string $url
     * @param array $post_data
     */
    function request_post($url = '', $post_data = array()) {
        if (empty($url) || empty($post_data)) {
            return false;
        }
        
        $o = "";
        foreach ( $post_data as $k => $v ) 
        { 
            $o.= "$k=" . urlencode( $v ). "&" ;
        }
        $post_data = substr($o,0,-1);

        $postUrl = $url;
        $curlPost = $post_data;
        $ch = curl_init();//初始化curl
        curl_setopt($ch, CURLOPT_URL,$postUrl);//抓取指定网页
        curl_setopt($ch, CURLOPT_HEADER, 0);//设置header
        curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上
        curl_setopt($ch, CURLOPT_POST, 1);//post提交方式
        curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);
        $data = curl_exec($ch);//运行curl
        curl_close($ch);
        
        return $data;
    }


白俊遥博客
请先登录后发表评论
  • 最新评论
  • 总共0条评论