[PHP] 基于php的周公解梦接口调用代码实例 →→→→→进入此内容的聊天室

来自 , 2021-03-03, 写在 PHP, 查看 148 次.
URL http://www.code666.cn/view/ca793d8b
  1. <!--?php
  2. // +----------------------------------------------------------------------
  3. // | JuhePHP [ NO ZUO NO DIE ]
  4. // +----------------------------------------------------------------------
  5. // | Copyright (c) 2010-2015 http://juhe.cn All rights reserved.
  6. // +----------------------------------------------------------------------
  7. // | Author: Juhedata <info@juhe.cn-->
  8. // +----------------------------------------------------------------------
  9.  
  10. //----------------------------------
  11. // 周公解梦调用示例代码 - 聚合数据
  12. // 在线接口文档:http://www.juhe.cn/docs/64
  13. //----------------------------------
  14.  
  15. header('Content-type:text/html;charset=utf-8');
  16.  
  17.  
  18. //配置您申请的appkey
  19. $appkey = "*********************";
  20.  
  21.  
  22.  
  23.  
  24. //************1.类型************
  25. $url = "http://v.juhe.cn/dream/category";
  26. $params = array(
  27.       "key" => $appkey,//应用APPKEY(应用详细页查询)
  28.       "fid" => "",//所属分类,默认全部,0:一级分类
  29. );
  30. $paramstring = http_build_query($params);
  31. $content = juhecurl($url,$paramstring);
  32. $result = json_decode($content,true);
  33. if($result){
  34.     if($result['error_code']=='0'){
  35.         print_r($result);
  36.     }else{
  37.         echo $result['error_code'].":".$result['reason'];
  38.     }
  39. }else{
  40.     echo "请求失败";
  41. }
  42. //**************************************************
  43.  
  44.  
  45.  
  46.  
  47. //************2.解梦查询************
  48. $url = " http://v.juhe.cn/dream/query";
  49. $params = array(
  50.       "key" => $appkey,//应用APPKEY(应用详细页查询)
  51.       "q" => "",//梦境关键字,如:黄金 需要utf8 urlencode
  52.       "cid" => "",//指定分类,默认全部
  53.       "full" => "",//是否显示详细信息,1:是 0:否,默认0
  54. );
  55. $paramstring = http_build_query($params);
  56. $content = juhecurl($url,$paramstring);
  57. $result = json_decode($content,true);
  58. if($result){
  59.     if($result['error_code']=='0'){
  60.         print_r($result);
  61.     }else{
  62.         echo $result['error_code'].":".$result['reason'];
  63.     }
  64. }else{
  65.     echo "请求失败";
  66. }
  67. //**************************************************
  68.  
  69.  
  70.  
  71.  
  72. //************3.根据ID查询解梦信息************
  73. $url = "http://v.juhe.cn/dream/queryid";
  74. $params = array(
  75.       "key" => $appkey,//应用APPKEY(应用详细页查询)
  76.       "id" => "",//解梦ID
  77. );
  78. $paramstring = http_build_query($params);
  79. $content = juhecurl($url,$paramstring);
  80. $result = json_decode($content,true);
  81. if($result){
  82.     if($result['error_code']=='0'){
  83.         print_r($result);
  84.     }else{
  85.         echo $result['error_code'].":".$result['reason'];
  86.     }
  87. }else{
  88.     echo "请求失败";
  89. }
  90. //**************************************************
  91.  
  92.  
  93.  
  94.  
  95.  
  96. /**
  97.  * 请求接口返回内容
  98.  * @param  string $url [请求的URL地址]
  99.  * @param  string $params [请求的参数]
  100.  * @param  int $ipost [是否采用POST形式]
  101.  * @return  string
  102.  */
  103. function juhecurl($url,$params=false,$ispost=0){
  104.     $httpInfo = array();
  105.     $ch = curl_init();
  106.  
  107.     curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );
  108.     curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );
  109.     curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );
  110.     curl_setopt( $ch, CURLOPT_TIMEOUT , 60);
  111.     curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );
  112.     curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);
  113.     if( $ispost )
  114.     {
  115.         curl_setopt( $ch , CURLOPT_POST , true );
  116.         curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );
  117.         curl_setopt( $ch , CURLOPT_URL , $url );
  118.     }
  119.     else
  120.     {
  121.         if($params){
  122.             curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );
  123.         }else{
  124.             curl_setopt( $ch , CURLOPT_URL , $url);
  125.         }
  126.     }
  127.     $response = curl_exec( $ch );
  128.     if ($response === FALSE) {
  129.         //echo "cURL Error: " . curl_error($ch);
  130.         return false;
  131.     }
  132.     $httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );
  133.     $httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );
  134.     curl_close( $ch );
  135.     return $response;
  136. }

回复 "基于php的周公解梦接口调用代码实例"

这儿你可以回复上面这条便签

captcha