isbn书号查询php代码,eoLinker-API Shop ISBN书号查询 PHP调用示例代码

= "POST";$url

= "https://api.apishop.net/common/ISBN/queryISBN";$headers

= NULL;$params

= array("ISBN"=>"" //ISBN书号,如“9787530212837”);$result

= apishop_curl($method, $url, $headers, $params);If

($result) {$body = json_decode($result["body"], TRUE);$status_code = $body["statusCode"];If ($status_code == "000000") {//状态码为000000,说明请求成功echo "请求成功:" .

$result["body"];} else {//状态码非000000,说明请求失败echo "请求失败:" .

$result["body"];}}

else {//返回内容异常,发送请求失败,以下可根据业务逻辑自行修改echo "发送请求失败";}/***转发请求到目的主机* @param $method string请求方法* @param $URL string请求地址* @param null $headers请求头* @param null $param请求参数* @return array|bool*/function

apishop_curl(&$method, &$URL, &$headers = NULL, &$param = NULL){//初始化请求$require = curl_init($URL);//判断是否HTTPS$isHttps = substr($URL, 0, 8) == "https://" ? TRUE : FALSE;//设置请求方式switch ($method) {case "GET":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "GET");break;case "POST":curl_setopt($require, CURLOPT_CUSTOMREQUEST, "POST");break;default:return FALSE;}if ($param) {curl_setopt($require, CURLOPT_POSTFIELDS, $param);}if ($isHttps) {//跳过证书检查curl_setopt($require, CURLOPT_SSL_VERIFYPEER, FALSE);//检查证书中是否设置域名curl_setopt($require, CURLOPT_SSL_VERIFYHOST, 2);}if ($headers) {//设置请求头curl_setopt($require, CURLOPT_HTTPHEADER, $headers);}//返回结果不直接输出curl_setopt($require, CURLOPT_RETURNTRANSFER, TRUE);//重定向curl_setopt($require, CURLOPT_FOLLOWLOCATION, TRUE);//把返回头包含再输出中curl_setopt($require, CURLOPT_HEADER, TRUE);//发送请求$response = curl_exec($require);//获取头部长度$headerSize = curl_getinfo($require, CURLINFO_HEADER_SIZE);//关闭请求curl_close($require);if ($response) {//返回头部字符串$header = substr($response, 0, $headerSize);//返回体$body = substr($response, $headerSize);//过滤隐藏非法字符$bodyTemp = json_encode(array(0 => $body));$bodyTemp = str_replace("", "", $bodyTemp);$bodyTemp = json_decode($bodyTemp, TRUE);$body = trim($bodyTemp[0]);//将返回结果头部转成数组$respondHeaders = array();$header_rows = array_filter(explode(PHP_EOL, $header), "trim");foreach ($header_rows as $row) {$keylen = strpos($row, ":");if ($keylen) {$respondHeaders[] = array("key" => substr($row, 0, $keylen),"value" => trim(substr($row, $keylen + 1)));}}return array("headers" => $respondHeaders,"body" => $body);} else {return FALSE;}}

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值