商标查询接口php,Notepad++

/**

* 发送post请求

* @param string $url 请求地址

* @param array $param post键值对数据或者urlencode数据

* @return string

*/

function send_post($url = '', $param = '')

{

$param = is_array($param) ? http_build_query($param) : $param;

if (empty($url) || empty($param)) {

return false;

}

$postUrl = $url;

$curlPost = $param;

$ch = curl_init();//初始化curl

curl_setopt($ch, CURLOPT_URL, $postUrl);//抓取指定网页

curl_setopt($ch, CURLOPT_HTTPHEADER, array("Content-type:application/x-www-form-urlencoded"));

curl_setopt($ch, CURLOPT_HEADER, 0);//设置header

curl_setopt($ch, CURLOPT_TIMEOUT, 60*15);

curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);//要求结果为字符串且输出到屏幕上

curl_setopt($ch, CURLOPT_POST, 1);//post提交方式

curl_setopt($ch, CURLOPT_POSTFIELDS, $curlPost);

$data = curl_exec($ch);//运行curl

curl_close($ch);

return $data;

}

$t1 = microtime(true);

$listurl="http://sbgg.saic.gov.cn:9080/tmann/annInfoView/annSearchDG.html";

//page=页数,rows每次查询行数,annNum=期数

$listdata='page=2&rows=20&annNum=1593&annType=&tmType=&coowner=&recUserName=&allowUserName=&byAllowUserName=&appId=&appIdZhiquan=&bfchangedAgengedName=&changeLastName=&transferUserName=&acceptUserName=&regName=&tmName=&intCls=&fileType=&totalYOrN=false&appDateBegin=&appDateEnd=';

$selbycodeurl="http://sbgg.saic.gov.cn:9080/tmann/annInfoView/selectInfoidBycode.html";

//annNum=期数

$selbycodedata="annNum=1593&annTypecode=TMZCSQ";

$imgcode=send_post($selbycodeurl, $selbycodedata);

$imgviewurl="http://sbgg.saic.gov.cn:9080/tmann/annInfoView/imageView.html";

$result=json_decode(send_post($listurl, $listdata), true);

foreach ($result['rows'] as $key => $value) {

$imgviewdata="id={$imgcode}&pageNum={$value['page_no']}&flag=1";

//id是根据期数查询接口返回的数据,pageNum是单个商标数据中的page_no字段,组合查询所在图片列表

$imgdata=json_decode(send_post($imgviewurl, $imgviewdata), true);

$result['rows'][$key]['pic']=$imgdata['imaglist'][3];  //图像来自于接口列表第4张图

var_dump($result['rows'][$key]);

}

$t2 = microtime(true);

echo '耗时'.round($t2-$t1, 3).'秒';

运行结果如下,受接口限制,因为每个商标数据需要单独请求图片接口获取数据,平均每20个商标数据,需要80秒,用服务器估计会快一点。

6247b9e31a78b3d859eea060be3b07f8.png

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值