开源 nginx linux命令 Windows Python HTML5 mysql wordpress java shell php Ubuntu google centos 程序员 linux Android apache 微软 Firefox

PHP微信开发:周公解梦

使用方式为直接在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;
}

延伸阅读

评论

暂无评论

写评论