Heim  >  Artikel  >  php教程  >  微软小冰非Api冰聊天接口PHP

微软小冰非Api冰聊天接口PHP

大家讲道理
大家讲道理Original
2016-11-08 11:40:401308Durchsuche

使用前需要获取微博的SUB值,什么是SUB呢?sub也就是你的微博账号登录状态下的cookies。和百度的bduss是同意类型的东西
如何获取SUB呢?
打开电脑版weibo.com登录您的帐号。登录成功后打开浏览器开发者工具(审查元素)。

如图所示,查看微博的所有cookies。把sub后面的value值就是SUB.
图片http://7xrn7f.com1.z0.glb.clouddn.com/16-5-16/77590312.jpg
把sub粘贴到下面的代码中,注意是SUB要大写
格式:SUB=******************************************************
到现在还没有结束,打开http://weibo.com/weiruanxiaobing,关注一下小冰的微博。
然后再给她发一条私信。
他会回复你让你领取她,绑定你的手机号,即可领取成功。

领取成功后,即可使用上面的接口进行聊天、

<?php
    //此处新浪微博SUB
    
    
     define(&#39;SUB&#39;,&#39;SUB=******************************************************&#39;);
    
    
    //end
    //临时cookies
    $cookie = dirname(__FILE__) . &#39;/weibo.tmp&#39;;
    //去除特殊字符
    $contents=htmlspecialchars($_GET[msg]);
    $contents=preg_replace("/\s/","",$contents);
    //post数据
    $post = array (
    &#39;content&#39;=>"$contents",
    &#39;rl&#39;=>&#39;2&#39;,
    &#39;uid&#39;=>&#39;5175429989&#39;,
    &#39;send&#39;=>&#39;发送&#39;
     );
     //curl模拟发送消息
     if($_GET[msg]){}else{
         echo &#39;你提交的内容为空!&#39;;
         exit;
     }
    $curl = curl_init();//初始化curl模块
    curl_setopt($curl, CURLOPT_URL, &#39;http://weibo.cn/msg/do/post?st=7b1272&#39;);//登录提交的地址
    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, &#39;http://m.weibo.cn/msg/messages?uid=5175429989&page=1&#39;);
    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;
?>


Stellungnahme:
Der Inhalt dieses Artikels wird freiwillig von Internetnutzern beigesteuert und das Urheberrecht liegt beim ursprünglichen Autor. Diese Website übernimmt keine entsprechende rechtliche Verantwortung. Wenn Sie Inhalte finden, bei denen der Verdacht eines Plagiats oder einer Rechtsverletzung besteht, wenden Sie sich bitte an admin@php.cn