php调用小冰,微软小冰非Api冰聊天接口PHP

//此处新浪微博SUB

define('SUB','SUB=******************************************************');

//end

//临时cookies

$cookie = dirname(__FILE__) . '/weibo.tmp';

//去除特殊字符

$contents=htmlspecialchars($_GET[msg]);

$contents=preg_replace("/\s/","",$contents);

//post数据

$post = array (

'content'=>"$contents",

'rl'=>'2',

'uid'=>'5175429989',

'send'=>'发送'

);

//curl模拟发送消息

if($_GET[msg]){}else{

echo '你提交的内容为空!';

exit;

}

$curl = curl_init();//初始化curl模块

curl_setopt($curl, CURLOPT_URL, 'http://weibo.cn/msg/do/post?st=7b1272');//登录提交的地址

curl_setopt($curl, CURLOPT_HEADER, 0);//是否显示头信息

curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);//是否自动显示返回的信息

curl_setopt($curl, CURLOPT_COOKIE, SUB);

curl_setopt($curl, CURLOPT_COOKIEJAR, $cookie); //设置Cookie信息保存在指定的文件中

curl_setopt($curl, CURLOPT_POST, 1);//post方式提交

curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($post));//要提交的信息

curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);

curl_exec($curl);//执行cURL

curl_close($curl);//关闭cURL资源,并且释放系统资源

sleep(1);

//读取回复

$ch = curl_init();

curl_setopt($ch, CURLOPT_URL, 'http://m.weibo.cn/msg/messages?uid=5175429989&page=1');

curl_setopt($ch, CURLOPT_HEADER, 0);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);

curl_setopt($ch, CURLOPT_COOKIE, SUB);

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, 1);

$ct = curl_exec($ch);

curl_close($ch);

$ct=json_decode($ct,1);

//print_r($ct);

$m=$ct[data][0][text];

//替换

$m=str_replace("分享语音","对方给你发送了一段语音。暂时无法显示",$m);

$m=str_replace("分享图片","对方给你发送了图片音。暂时无法显示",$m);

//返回的结果

echo $m;

?>

本文原创发布php中文网,转载请注明出处,感谢您的尊重!

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值