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

核心代碼:
$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 //數(shù)據(jù)庫名 : $dbname $dbname = "app_dq095"; $host = "w.rdc.sae.sina.com.cn"; $port = "3306"; $user = "4k514n103z"; $pwd = "2402314li2j1i5im1xy2xizj5y332w2x41k2z203"; /*接著調(diào)用mysql_connect()連接服務(wù)器*/ // 連主庫 $db = mysql_connect($host,$user,$pwd); if(!$db){ die("Connect Server Failed: " . mysql_error($db)); } /*連接成功后立即調(diào)用mysql_select_db()選中需要連接的數(shù)據(jù)庫*/ if (!mysql_select_db($dbname)) { die("Select Database Failed: " . mysql_error($db)); } mysql_query("set names utf-8",$db); /*至此連接已完全建立,就可對當(dāng)前數(shù)據(jù)庫進(jìn)行相應(yīng)的操作了*/ /*?。?!注意,無法再通過本次連接調(diào)用mysql_select_db來切換到其它數(shù)據(jù)庫了!??!*/ /* 需要再連接其它數(shù)據(jù)庫,請再使用mysql_connect+mysql_select_db啟動另一個連接*/ /** * 接下來就可以使用其它標(biāo)準(zhǔn)php mysql函數(shù)操作進(jìn)行數(shù)據(jù)庫操作 */ if($keyword=="天氣") { $content="請輸入地區(qū)"; $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="你輸入的地區(qū)有誤";} } 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 //數(shù)據(jù)庫名 : $dbname $dbname = "app_dq095"; $host = "w.rdc.sae.sina.com.cn"; $port = "3306"; $user = "4k514n103z"; $pwd = "2402314li2j1i5im1xy2xizj5y332w2x41k2z203"; /*接著調(diào)用mysql_connect()連接服務(wù)器*/ // 連主庫 $db = mysql_connect($host,$user,$pwd); if(!$db){ die("Connect Server Failed: " . mysql_error($db)); } /*連接成功后立即調(diào)用mysql_select_db()選中需要連接的數(shù)據(jù)庫*/ if (!mysql_select_db($dbname)) { die("Select Database Failed: " . mysql_error($db)); } mysql_query("set names utf-8",$db); /*至此連接已完全建立,就可對當(dāng)前數(shù)據(jù)庫進(jìn)行相應(yīng)的操作了*/ /*?。?!注意,無法再通過本次連接調(diào)用mysql_select_db來切換到其它數(shù)據(jù)庫了!?。?/ /* 需要再連接其它數(shù)據(jù)庫,請再使用mysql_connect+mysql_select_db啟動另一個連接*/ /** * 接下來就可以使用其它標(biāo)準(zhǔn)php mysql函數(shù)操作進(jìn)行數(shù)據(jù)庫操作 */ if($keyword=="天氣") { $content="請輸入地區(qū)"; $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="你輸入的地區(qū)有誤";} } 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; } }}?>以上就是本文的全部內(nèi)容,希望對大家的學(xué)習(xí)有所幫助,也希望大家多多支持金聰精品。
金聰線報提示:[ php微信公眾號開發(fā)之二級菜單 ] 僅為會員分享,分享目的如下:
1.軟件源碼推廣展示:目的展示軟件相關(guān)功能,接收技術(shù)學(xué)習(xí)者測試、測評;
2.教程課程信息展示:展示課程信息,傳授課程各階段內(nèi)容;
3.設(shè)計素材圖片展示:展示素材設(shè)計理念、思維方式、傳播設(shè)計理念;
4.福利優(yōu)惠信息展示:分享各類最新的福利信息,各種優(yōu)惠信息展示;
以上分享目的僅供學(xué)習(xí)、參考使用,請勿用于其他用途,如果想商業(yè)使用或者代理,請自行聯(lián)系版權(quán)方獲取授權(quán)。任何未獲取授權(quán)的商業(yè)使用與本站無關(guān),請自行承擔(dān)相應(yīng)責(zé)任。
本站不存儲任何資源文件,敬請周知!
本網(wǎng)站采用 BY-NC-SA 協(xié)議進(jìn)行授權(quán) 轉(zhuǎn)載請注明原文鏈接:php微信公眾號開發(fā)之二級菜單
1.軟件源碼推廣展示:目的展示軟件相關(guān)功能,接收技術(shù)學(xué)習(xí)者測試、測評;
2.教程課程信息展示:展示課程信息,傳授課程各階段內(nèi)容;
3.設(shè)計素材圖片展示:展示素材設(shè)計理念、思維方式、傳播設(shè)計理念;
4.福利優(yōu)惠信息展示:分享各類最新的福利信息,各種優(yōu)惠信息展示;
以上分享目的僅供學(xué)習(xí)、參考使用,請勿用于其他用途,如果想商業(yè)使用或者代理,請自行聯(lián)系版權(quán)方獲取授權(quán)。任何未獲取授權(quán)的商業(yè)使用與本站無關(guān),請自行承擔(dān)相應(yīng)責(zé)任。
本站不存儲任何資源文件,敬請周知!
此資源僅供個人學(xué)習(xí)、研究使用,禁止非法轉(zhuǎn)播或商業(yè)用途,請在獲取后24小時內(nèi)刪除,如果你覺得滿意,請尋求購買正版或獲取授權(quán)!
如果您認(rèn)為本頁信息內(nèi)容侵犯了您的相關(guān)權(quán)益(包含但不限于:著作權(quán)、首發(fā)權(quán)、隱私權(quán)等權(quán)利),或者您認(rèn)為自己是此信息的權(quán)利人但是此信息不是自己發(fā)布的,可以直接版權(quán)舉報投訴,我們會根據(jù)網(wǎng)站注冊協(xié)議、資源分享協(xié)議等協(xié)議處理,以保護(hù)您的合法權(quán)益。
免責(zé)申明:本站僅提供學(xué)習(xí)的平臺,所有資料均來自于網(wǎng)絡(luò)分享線索,版權(quán)歸原創(chuàng)者所有!本站不提供任何保證,并不承擔(dān)任何法律責(zé)任,如果對您的版權(quán)或者利益造成損害,請?zhí)峁┫鄳?yīng)的資質(zhì)證明,我們將于3個工作日內(nèi)予以處理。版權(quán)申訴相關(guān)說明如果您認(rèn)為本頁信息內(nèi)容侵犯了您的相關(guān)權(quán)益(包含但不限于:著作權(quán)、首發(fā)權(quán)、隱私權(quán)等權(quán)利),或者您認(rèn)為自己是此信息的權(quán)利人但是此信息不是自己發(fā)布的,可以直接版權(quán)舉報投訴,我們會根據(jù)網(wǎng)站注冊協(xié)議、資源分享協(xié)議等協(xié)議處理,以保護(hù)您的合法權(quán)益。
本網(wǎng)站采用 BY-NC-SA 協(xié)議進(jìn)行授權(quán) 轉(zhuǎn)載請注明原文鏈接:php微信公眾號開發(fā)之二級菜單

侵權(quán)舉報/版權(quán)申訴



