微信公众平台周公解梦接口开发代码
昌江中立科技 | 2018-01-26 23:25:03 | 阅读:39768
获取数据使用方式为直接在URL中提交内容名称即可,名称需要先做urlencode调用url方法:以下是调用周公解梦方法,提交内容为“食物”http://api2.sinaapp.com/search/d...=%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;}复制代码