php如何查询星座运势

发布时间:2022-10-24 17:32:45 作者:iii
来源:亿速云 阅读:126

本篇内容介绍了“php如何查询星座运势”的有关知识,在实际案例的操作过程中,不少人都会遇到这样的困境,接下来就让小编带领大家学习一下如何处理这些情况吧!希望大家仔细阅读,能够学有所成!

php查询星座运势的方法:1、开通星座运势API接口;2、创建PHP示例文件;3、请求接口URL;4、配置申请的appkey;5、发起接口网络请求;6、通过“function juhecurl($url,$params=false,$ispost=0){...}”方式请求接口返回内容,再根据业务实际逻辑调整修改即可。

php怎么查询星座运势?

1、开通星座运势API接口:

通过https://www.juhe.cn/docs/api/id/58?s=cpphpcn注册及开通

接口说明:(十二星座的今日运势)

2、基于php的星座运势接口调用示例

代码示例:

// 星座运势调用示例代码 

header('Content-type:text/html;charset=utf-8');

//配置您申请的appkey

$appkey = "*********************";

//************1.运势查询************

$url = "http://web.juhe.cn:8080/constellation/getAll";

$params = array(

"key" => $appkey,//应用APPKEY(应用详细页查询)

"consName" => "",//星座名称,如:白羊座

"type" => "",//运势类型:today,tomorrow,week,nextweek,month,year

);

$paramstring = http_build_query($params);

$content = juhecurl($url,$paramstring);

$result = json_decode($content,true);

if($result){

if($result['error_code']=='0'){

print_r($result);

}else{

echo $result['error_code'].":".$result['reason'];

}

}else{

echo "请求失败";

}

//**************************************************

/**

* 请求接口返回内容

* @param string $url [请求的URL地址]

* @param string $params [请求的参数]

* @param int $ipost [是否采用POST形式]

* @return string

*/

function juhecurl($url,$params=false,$ispost=0){

$httpInfo = array();

$ch = curl_init();

curl_setopt( $ch, CURLOPT_HTTP_VERSION , CURL_HTTP_VERSION_1_1 );

curl_setopt( $ch, CURLOPT_USERAGENT , 'JuheData' );

curl_setopt( $ch, CURLOPT_CONNECTTIMEOUT , 60 );

curl_setopt( $ch, CURLOPT_TIMEOUT , 60);

curl_setopt( $ch, CURLOPT_RETURNTRANSFER , true );

curl_setopt($ch, CURLOPT_FOLLOWLOCATION, true);

if( $ispost )

{

curl_setopt( $ch , CURLOPT_POST , true );

curl_setopt( $ch , CURLOPT_POSTFIELDS , $params );

curl_setopt( $ch , CURLOPT_URL , $url );

}

else

{

if($params){

curl_setopt( $ch , CURLOPT_URL , $url.'?'.$params );

}else{

curl_setopt( $ch , CURLOPT_URL , $url);

}

}

$response = curl_exec( $ch );

if ($response === FALSE) {

//echo "cURL Error: " . curl_error($ch);

return false;

}

$httpCode = curl_getinfo( $ch , CURLINFO_HTTP_CODE );

$httpInfo = array_merge( $httpInfo , curl_getinfo( $ch ) );

curl_close( $ch );

return $response;

}

“php如何查询星座运势”的内容就介绍到这里了,感谢大家的阅读。如果想了解更多行业相关的知识可以关注亿速云网站,小编将为大家输出更多高质量的实用文章!

推荐阅读:
  1. 根据日期计算星座
  2. 利用python输出星座的方法

免责声明:本站发布的内容(图片、视频和文字)以原创、转载和分享为主,文章观点不代表本网站立场,如果涉及侵权请联系站长邮箱:is@yisu.com进行举报,并提供相关证据,一经查实,将立刻删除涉嫌侵权内容。

php

上一篇:require是不是es6语法

下一篇:提高开发效率的Vue3常用插件有哪些

相关阅读

您好,登录后才能下订单哦!

密码登录
登录注册
其他方式登录
点击 登录注册 即表示同意《亿速云用户服务条款》