php微信公众号开发之音乐信息
程序员文章站
2023-11-17 09:43:40
本文实例为大家分享了php微信公众号音乐信息的具体代码,供大家参考,具体内容如下
高品质—-hqmusicurl
低品质—-musicurl &n...
本文实例为大家分享了php微信公众号音乐信息的具体代码,供大家参考,具体内容如下
- 高品质—-hqmusicurl
- 低品质—-musicurl
核心代码如下:
$texttpl = "<xml> <tousername><![cdata[%s]]></tousername> <fromusername><![cdata[%s]]></fromusername> <createtime>%s</createtime> <msgtype><![cdata[music]]></msgtype> <music> <title><![cdata[欢乐颂]]></title> <description><![cdata[贝多芬]]></description> <musicurl><![cdata[http://1.dq095.applinzi.com/欢乐颂.mp3]]></musicurl> <hqmusicurl><![cdata[http://1.dq095.applinzi.com/欢乐颂.mp3]]></hqmusicurl> </music> <funcflag>0</funcflag> </xml>"; if(!empty( $keyword )) { $resultstr = sprintf($texttpl, $fromusername, $tousername, $time); echo $resultstr; }else{ echo "input something..."; }
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[music]]></msgtype> <music> <title><![cdata[欢乐颂]]></title> <description><![cdata[贝多芬]]></description> <musicurl><![cdata[http://1.dq095.applinzi.com/欢乐颂.mp3]]></musicurl> <hqmusicurl><![cdata[http://1.dq095.applinzi.com/欢乐颂.mp3]]></hqmusicurl> </music> <funcflag>0</funcflag> </xml>"; if(!empty( $keyword )) { $resultstr = sprintf($texttpl, $fromusername, $tousername, $time); echo $resultstr; }else{ echo "input something..."; } }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; } } } ?>
以上就是本文的全部内容,希望对大家的学习有所帮助,也希望大家多多支持。