豆瓣isbn查询api接口制作教程【源码已开源】
之前腾讯出了个私房书柜项目的云开发教程,所用的接口就是豆瓣的isbn查询接口,然后它就一下大火了,但是大概在四月份左右,它的接口就失效了,顺便连带的开放平台都关闭了,不知道其原因,反正就是用不了了。
因为最近在做的一个二手书项目,其中发布书籍需要使用isbn查询功能,首先想到的就是豆瓣,因为之前我也看过那个私房书柜教程,所以对它印象深刻。
原接口是这样的:
https://api.douban.com/v2/book/isbn/9787543632608
但是现在却返回说无效密钥,也就是不公开提供了
{"msg":"invalid_apikey","code":104,"request":"GET /v2/book/isbn/9787543632608"}
办法是有的,分析了一下豆瓣官网isbn的查询方法: 地址: https://book.douban.com/
然后利用php进行重定向和curl,取出关键内容,详情代码:
<?php
function cut($content,$start,$end) {
$r = explode($start, $content);
if (isset($r[1])) {
$r = explode($end, $r[1]);
return $r[0];
return '';
//模拟get请求
function get($url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_USERAGENT, 'Mozilla/5.0 (Windows NT 6.1) AppleWebKit/536.7 (KHTML, like Gecko) Chrome/20.0.1099.0 Safari/536.7 QQBrowser/6.14.15493.201');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
$result = curl_exec($ch);
curl_close($ch);
return $result;
$isbn = @$_GET['isbn'];
$surl = 'https://book.douban.com/isbn/'.$isbn.'/';
$headers = json_encode(get_headers($surl),true);
$headers = json_encode($headers,true);
$surl = cut($headers,'Location: ','"');
$surl = str_replace('\\','' ,$surl);//302地址
$data = get($surl);
$data_1=cut($data,'application/ld+json">','</script>');
$data_1 = json_decode($data_1,true);
$res['title'] = $data_1['name'];//书名
$author = $data_1['author'];
if($author[0]==''){
$author[0]['name'] = '未知';
$res['author'] =$author;//作者
$res['logo'] = cut($data,'data-pic="','"');//图标
$publisher = cut($data,'出版社:</span>','<br/>');
if($publisher==''){
$publisher ='未知';
$res['publisher'] =$publisher;//出版社
$published = cut($data,'出版年:</span>','<br/>');
if($published==''){
$published ='未知';
$res['published'] =$published;//出版年
$page = cut($data,'页数:</span>','<br/>');
if($page==''){
$page ='未知';
$res['page'] =$page;//页数
$price = cut($data,'定价:</span>','<br/>');
if($price==''){
$price ='未知';
$res['price'] =$price;//定价
$designed = cut($data,'装帧:</span>','<br/>');
if($designed==''){
$designed ='未知';
$res['designed'] =$designed;//装帧
$description = cut($data,'class="intro">','</p>');
$description = explode('<p>',$description)[1];
if($description==''){
$description ='未知';