您好,登錄后才能下訂單哦!
小編給大家分享一下php微信公眾號開發(fā)之音樂信息的示例分析,希望大家閱讀完這篇文章之后都有所收獲,下面讓我們一起去探討吧!
高品質—-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; } } } ?>
看完了這篇文章,相信你對“php微信公眾號開發(fā)之音樂信息的示例分析”有了一定的了解,如果想了解更多相關知識,歡迎關注億速云行業(yè)資訊頻道,感謝各位的閱讀!
免責聲明:本站發(fā)布的內容(圖片、視頻和文字)以原創(chuàng)、轉載和分享為主,文章觀點不代表本網站立場,如果涉及侵權請聯(lián)系站長郵箱:is@yisu.com進行舉報,并提供相關證據,一經查實,將立刻刪除涉嫌侵權內容。