本文實例為大家分享了php微信公眾號二級菜單的具體代碼,供大家參考,具體內容如下核心代碼:$poObj=implexml_load_ig($poS,'SimpleXMLEleme',LIBXML_NOCDATA);$fomUeame=$poObj-&g;F......
以下是【金聰采編】分享的內容全文:
以下是【金聰采編】分享的內容全文:
本文實例為大家分享了php微信公眾號二級菜單的具體代碼,供大家參考,具體內容如下

核心代碼:
$postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $MsgType=$postObj->MsgType; $keyword = trim($postObj->Content); $time = time(); $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content>%s</Content> <FuncFlag>0</FuncFlag> </xml>"; //用 戶 名 : $user //密 碼 : $pwd //主庫域名 : $host //從庫域名 : SAE_MYSQL_HOST_S //端 口 : $port //數據庫名 : $dbname $dbname = "app_dq095"; $host = "w.rdc.sae.sina.com.cn"; $port = "3306"; $user = "4k514n103z"; $pwd = "2402314li2j1i5im1xy2xizj5y332w2x41k2z203"; /*接著調用mysql_connect()連接服務器*/ // 連主庫 $db = mysql_connect($host,$user,$pwd); if(!$db){ die("Connect Server Failed: " . mysql_error($db)); } /*連接成功后立即調用mysql_select_db()選中需要連接的數據庫*/ if (!mysql_select_db($dbname)) { die("Select Database Failed: " . mysql_error($db)); } mysql_query("set names utf-8",$db); /*至此連接已完全建立,就可對當前數據庫進行相應的操作了*/ /*!!!注意,無法再通過本次連接調用mysql_select_db來切換到其它數據庫了!!!*/ /* 需要再連接其它數據庫,請再使用mysql_connect+mysql_select_db啟動另一個連接*/ /** * 接下來就可以使用其它標準php mysql函數操作進行數據庫操作 */ if($keyword=="天氣") { $content="請輸入地區"; $sql="INSERT INTO `weather`(`id`,`user`,`keyword`) VALUES (NULL,'{$fromUsername}','{$keyword}')"; mysql_query($sql); } else { $sql="SELECT `keyword` FROM `weather` WHERE `user`= '" . $fromUsername . "'"; $query=mysql_query($sql); $rs=mysql_fetch_array($query); $c= $rs['keyword']; echo $c; if($c=="天氣") { $url="http://api.map.baidu.com/telematics/v2/weather?location={$keyword}&ak=1a3cde429f38434f1811a75e1a90310c"; $fa=file_get_contents($url); $f=simplexml_load_string($fa); $city=$f->currentCity; $da1=$f->results->result[0]->date; $da2=$f->results->result[1]->date; $da3=$f->results->result[2]->date; $w1=$f->results->result[0]->weather; $w2=$f->results->result[1]->weather; $w3=$f->results->result[2]->weather; $p1=$f->results->result[0]->wind; $p2=$f->results->result[1]->wind; $p3=$f->results->result[2]->wind; $q1=$f->results->result[0]->temperature; $q2=$f->results->result[1]->temperature; $q3=$f->results->result[2]->temperature; $d1=$city.$da1.$w1.$p1.$q1; $d2=$city.$da2.$w2.$p2.$q2; $d3=$city.$da3.$w3.$p3.$q3; $content=$d1.$d2.$d3; if (empty($content)) { $content="你輸入的地區有誤";} } else{ $content="請先輸入天氣"; } } $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time,$content);echo $resultStr;index.php 整體代碼如下:
<?php/** * wechat php test *///define your tokendefine("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; $MsgType=$postObj->MsgType; $keyword = trim($postObj->Content); $time = time(); $textTpl = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[text]]></MsgType> <Content>%s</Content> <FuncFlag>0</FuncFlag> </xml>"; //用 戶 名 : $user //密 碼 : $pwd //主庫域名 : $host //從庫域名 : SAE_MYSQL_HOST_S //端 口 : $port //數據庫名 : $dbname $dbname = "app_dq095"; $host = "w.rdc.sae.sina.com.cn"; $port = "3306"; $user = "4k514n103z"; $pwd = "2402314li2j1i5im1xy2xizj5y332w2x41k2z203"; /*接著調用mysql_connect()連接服務器*/ // 連主庫 $db = mysql_connect($host,$user,$pwd); if(!$db){ die("Connect Server Failed: " . mysql_error($db)); } /*連接成功后立即調用mysql_select_db()選中需要連接的數據庫*/ if (!mysql_select_db($dbname)) { die("Select Database Failed: " . mysql_error($db)); } mysql_query("set names utf-8",$db); /*至此連接已完全建立,就可對當前數據庫進行相應的操作了*/ /*!!!注意,無法再通過本次連接調用mysql_select_db來切換到其它數據庫了!!!*/ /* 需要再連接其它數據庫,請再使用mysql_connect+mysql_select_db啟動另一個連接*/ /** * 接下來就可以使用其它標準php mysql函數操作進行數據庫操作 */ if($keyword=="天氣") { $content="請輸入地區"; $sql="INSERT INTO `weather`(`id`,`user`,`keyword`) VALUES (NULL,'{$fromUsername}','{$keyword}')"; mysql_query($sql); } else { $sql="SELECT `keyword` FROM `weather` WHERE `user`= '" . $fromUsername . "'"; $query=mysql_query($sql); $rs=mysql_fetch_array($query); $c= $rs['keyword']; echo $c; if($c=="天氣") { $url="http://api.map.baidu.com/telematics/v2/weather?location={$keyword}&ak=1a3cde429f38434f1811a75e1a90310c"; $fa=file_get_contents($url); $f=simplexml_load_string($fa); $city=$f->currentCity; $da1=$f->results->result[0]->date; $da2=$f->results->result[1]->date; $da3=$f->results->result[2]->date; $w1=$f->results->result[0]->weather; $w2=$f->results->result[1]->weather; $w3=$f->results->result[2]->weather; $p1=$f->results->result[0]->wind; $p2=$f->results->result[1]->wind; $p3=$f->results->result[2]->wind; $q1=$f->results->result[0]->temperature; $q2=$f->results->result[1]->temperature; $q3=$f->results->result[2]->temperature; $d1=$city.$da1.$w1.$p1.$q1; $d2=$city.$da2.$w2.$p2.$q2; $d3=$city.$da3.$w3.$p3.$q3; $content=$d1.$d2.$d3; if (empty($content)) { $content="你輸入的地區有誤";} } else{ $content="請先輸入天氣"; } } $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time,$content); 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; } }}?>以上就是本文的全部內容,希望對大家的學習有所幫助,也希望大家多多支持金聰精品。
金聰線報提示:[ php微信公眾號開發之二級菜單 ] 僅為會員分享,分享目的如下:
1.軟件源碼推廣展示:目的展示軟件相關功能,接收技術學習者測試、測評;
2.教程課程信息展示:展示課程信息,傳授課程各階段內容;
3.設計素材圖片展示:展示素材設計理念、思維方式、傳播設計理念;
4.福利優惠信息展示:分享各類最新的福利信息,各種優惠信息展示;
以上分享目的僅供學習、參考使用,請勿用于其他用途,如果想商業使用或者代理,請自行聯系版權方獲取授權。任何未獲取授權的商業使用與本站無關,請自行承擔相應責任。
本站不存儲任何資源文件,敬請周知!
本網站采用 BY-NC-SA 協議進行授權 轉載請注明原文鏈接:php微信公眾號開發之二級菜單
1.軟件源碼推廣展示:目的展示軟件相關功能,接收技術學習者測試、測評;
2.教程課程信息展示:展示課程信息,傳授課程各階段內容;
3.設計素材圖片展示:展示素材設計理念、思維方式、傳播設計理念;
4.福利優惠信息展示:分享各類最新的福利信息,各種優惠信息展示;
以上分享目的僅供學習、參考使用,請勿用于其他用途,如果想商業使用或者代理,請自行聯系版權方獲取授權。任何未獲取授權的商業使用與本站無關,請自行承擔相應責任。
本站不存儲任何資源文件,敬請周知!
此資源僅供個人學習、研究使用,禁止非法轉播或商業用途,請在獲取后24小時內刪除,如果你覺得滿意,請尋求購買正版或獲取授權!
如果您認為本頁信息內容侵犯了您的相關權益(包含但不限于:著作權、首發權、隱私權等權利),或者您認為自己是此信息的權利人但是此信息不是自己發布的,可以直接版權舉報投訴,我們會根據網站注冊協議、資源分享協議等協議處理,以保護您的合法權益。
免責申明:本站僅提供學習的平臺,所有資料均來自于網絡分享線索,版權歸原創者所有!本站不提供任何保證,并不承擔任何法律責任,如果對您的版權或者利益造成損害,請提供相應的資質證明,我們將于3個工作日內予以處理。版權申訴相關說明如果您認為本頁信息內容侵犯了您的相關權益(包含但不限于:著作權、首發權、隱私權等權利),或者您認為自己是此信息的權利人但是此信息不是自己發布的,可以直接版權舉報投訴,我們會根據網站注冊協議、資源分享協議等協議處理,以保護您的合法權益。
本網站采用 BY-NC-SA 協議進行授權 轉載請注明原文鏈接:php微信公眾號開發之二級菜單
上一篇:php微信公眾號開發之音樂信息
下一篇:php微信公眾號開發之校園圖書館

侵權舉報/版權申訴



