一、获取数据
方倍工作室开发出周公解梦查询接口 API,欢迎大家试用.
使用方式为直接在URL中提交内容名称即可,名称需要先做urlencode
调用url方法:以下是调用周公解梦方法,提交内容为“食物”
http://api2.sinaapp.com/search/dream/?appkey=0020130430&appsecert=fa6095e113cd28fd&reqtype=text&keyword=%e9%a3%9f%e7%89%a9
返回格式如下:
{ "errcode": 0, "msgtype": "text", "text": { "content": "梦见大量食物,会灰心失望。梦见没有食物,会赚大钱。女人梦见大量食物,经济会拮据。" }}
一个完整的请求类似如下:
if(substr($keyword,0,6) == "梦见"){ $entityName = trim(substr($keyword,6,strlen($keyword))); if ($entityName == ""){ $contentStr = "发送“梦见”加上内容,如“梦见初恋情人”"; $resultStr = $this->transmitText($object, $contentStr, $funcFlag); return $resultStr; } $apihost = "http://api2.sinaapp.com/"; $apimethod = "search/dream/?"; $apiparams = array('appkey'=>"0020130430", 'appsecert'=>"fa6095e113cd28fd", 'reqtype'=>"text"); $apikeyword = "&keyword=".urlencode($entityName); $apicallurl = $apihost.$apimethod.http_build_query($apiparams).$apikeyword; $api2str = file_get_contents($apicallurl); $api2json = json_decode($api2str, true); $contentStr = $api2json['text']['content']; $resultStr = $this->transmitText($object, $contentStr, $funcFlag); return $resultStr;}
剩余代码请参考本博客其他文章。http://www.cnblogs.com/txw1958/
二,效果演示
三、试用账号