微信图书馆查询php

来源:互联网 发布:什么时候统一台湾 知乎 编辑:程序博客网 时间:2024/05/01 03:05

用的新浪sae微信基本框架,用南理工图书馆查询书籍。

以下是sever.php中直接回复文本消息的函数


 protected function onText() {                 $reqInfo = $this->getRequest('content');//书名<span style="white-space:pre"></span>$url="http://202.119.83.14:8080/uopac/opac/search_adv_result.php?sType0=02&q0=$reqInfo&pageSize=20&sort=score&desc=on&with_ebook=on";$curl=curl_init();curl_setopt($curl, CURLOPT_URL, $url);curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);curl_setopt($curl, CURLOPT_HEADER, 0);//  执行并获取HTML文档内容$output = curl_exec($curl);//  释放curl句柄curl_close($curl);$pattern = '/<table.*?>(.+?)<\/table>/is';//正则表达式preg_match($pattern, $output, $match);//$match[0]为<table></table>之间代码//提取<tr></tr>之间的内容$pattern = '/<tr.*?>(.+?)<\/tr>/is';preg_match_all($pattern, $match[0], $results,PREG_SET_ORDER);$s=$results;for ($i=1; $i<=5; $i++)//取前5条结果{  $pattern = '/<a.*?>(.+?)<\/a>/is';//书名preg_match_all($pattern, $s[$i][1], $results,PREG_SET_ORDER);  $arr_title[$i]= $results[0][1];  $preg='/<a .*?href="(.*?)".*?>/is';//提取链接  preg_match_all($preg, $s[$i][1], $results,PREG_SET_ORDER);  $arr_url[$i]=$results[0][1];}$items = array(    new NewsResponseItem($arr_title[1], '描述','http://b.hiphotos.baidu.com/image/w%3D230/sign=e449d2c2b0fb43161a1f7d7910a44642/342ac65c1038534322d635289113b07eca80889a.jpg ', 'http://202.119.83.14:8080/uopac/opac/'.$arr_url[1]),    new NewsResponseItem($arr_title[2], '描述','http://b.hiphotos.baidu.com/image/w%3D230/sign=e449d2c2b0fb43161a1f7d7910a44642/342ac65c1038534322d635289113b07eca80889a.jpg' ,'http://202.119.83.14:8080/uopac/opac/'.$arr_url[2]),    new NewsResponseItem($arr_title[3], '描述','http://b.hiphotos.baidu.com/image/w%3D230/sign=e449d2c2b0fb43161a1f7d7910a44642/342ac65c1038534322d635289113b07eca80889a.jpg' ,'http://202.119.83.14:8080/uopac/opac/'.$arr_url[3]),    new NewsResponseItem($arr_title[4], '描述','http://b.hiphotos.baidu.com/image/w%3D230/sign=e449d2c2b0fb43161a1f7d7910a44642/342ac65c1038534322d635289113b07eca80889a.jpg ', 'http://202.119.83.14:8080/uopac/opac/'.$arr_url[4]),    new NewsResponseItem($arr_title[5], '描述','http://b.hiphotos.baidu.com/image/w%3D230/sign=e449d2c2b0fb43161a1f7d7910a44642/342ac65c1038534322d635289113b07eca80889a.jpg' ,'http://202.119.83.14:8080/uopac/opac/'.$arr_url[5]),    new NewsResponseItem('more', '描述','http://b.hiphotos.baidu.com/image/w%3D230/sign=e449d2c2b0fb43161a1f7d7910a44642/342ac65c1038534322d635289113b07eca80889a.jpg' ,$url),);      $this->responseNews($items);//图片链接为汪星人      }

0 0
原创粉丝点击