php微信公众号开发之校园图书馆
程序员文章站
2023-12-06 08:39:46
本文实例为大家分享了php微信公众号图书馆的具体代码,供大家参考,具体内容如下
图书来源:山东理工大学图书馆书目检索系统
搜索书名返回是xml格式数据:...
本文实例为大家分享了php微信公众号图书馆的具体代码,供大家参考,具体内容如下
图书来源:山东理工大学图书馆书目检索系统
搜索书名返回是xml格式数据:
核心代码如下:
$postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata); $fromusername = $postobj->fromusername; $tousername = $postobj->tousername; $keyword = trim($postobj->content); $time = time(); $texttpl = "<xml> <tousername><![cdata[%s]]></tousername> <fromusername><![cdata[%s]]></fromusername> <createtime>%s</createtime> <msgtype><![cdata[news]]></msgtype> <articlecount>3</articlecount> <articles> <item> <title><![cdata[%s]]></title> <description><![cdata[s]]></description> <picurl><![cdata[url]]></picurl> <url><![cdata[url]]></url> </item> <item> <title><![cdata[%s]]></title> <description><![cdata[s]]></description> <picurl><![cdata[url]]></picurl> <url><![cdata[url]]></url> </item> <item> <title><![cdata[%s]]></title> <description><![cdata[s]]></description> <picurl><![cdata[url]]></picurl> <url><![cdata[url]]></url> </item> </articles> <funcflag>1</funcflag> </xml>"; $url="http://222.206.65.12/opac/search_rss.php?dept=all&title={$keyword}&doctype=all&lang_code=all&match_flag=forward&displaypg=20&showmode=list&orderby=desc&sort=cata_date&onlylendable=no"; $fa=file_get_contents($url); $f=simplexml_load_string($fa); $da1=$f->channel->item[0]->title; $da2=$f->channel->item[1]->title; $da3=$f->channel->item[2]->title; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time,$da1,$da2,$da3); echo $resultstr;
index.php整体代码如下:
<?php /** * wechat php test */ //define your token define("token", "weixin"); $wechatobj = new wechatcallbackapitest(); $wechatobj->responsemsg(); class wechatcallbackapitest { public function valid() { $echostr = $_get["echostr"]; //valid signature , option if($this->checksignature()){ echo $echostr; exit; } } public function responsemsg() { //get post data, may be due to the different environments $poststr = $globals["http_raw_post_data"]; //extract post data if (!empty($poststr)){ $postobj = simplexml_load_string($poststr, 'simplexmlelement', libxml_nocdata); $fromusername = $postobj->fromusername; $tousername = $postobj->tousername; $keyword = trim($postobj->content); $time = time(); $texttpl = "<xml> <tousername><![cdata[%s]]></tousername> <fromusername><![cdata[%s]]></fromusername> <createtime>%s</createtime> <msgtype><![cdata[news]]></msgtype> <articlecount>3</articlecount> <articles> <item> <title><![cdata[%s]]></title> <description><![cdata[s]]></description> <picurl><![cdata[url]]></picurl> <url><![cdata[url]]></url> </item> <item> <title><![cdata[%s]]></title> <description><![cdata[s]]></description> <picurl><![cdata[url]]></picurl> <url><![cdata[url]]></url> </item> <item> <title><![cdata[%s]]></title> <description><![cdata[s]]></description> <picurl><![cdata[url]]></picurl> <url><![cdata[url]]></url> </item> </articles> <funcflag>1</funcflag> </xml>"; $url="http://222.206.65.12/opac/search_rss.php?dept=all&title={$keyword}&doctype=all&lang_code=all&match_flag=forward&displaypg=20&showmode=list&orderby=desc&sort=cata_date&onlylendable=no"; $fa=file_get_contents($url); $f=simplexml_load_string($fa); $da1=$f->channel->item[0]->title; $da2=$f->channel->item[1]->title; $da3=$f->channel->item[2]->title; $resultstr = sprintf($texttpl, $fromusername, $tousername, $time,$da1,$da2,$da3); echo $resultstr; }else { echo ""; exit; } } private function checksignature() { $signature = $_get["signature"]; $timestamp = $_get["timestamp"]; $nonce = $_get["nonce"]; $token = token; $tmparr = array($token, $timestamp, $nonce); sort($tmparr); $tmpstr = implode( $tmparr ); $tmpstr = sha1( $tmpstr ); if( $tmpstr == $signature ){ return true; }else{ return false; } } } ?>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。