海南中立科技 旗下:|||
網站首頁home 網站建設web Const 系統開發System Dev 微信開發wx Dev 網站推廣Website SEO 網站超市Website SM 客戶案例Client case 網站模板Web template 關于我們About us
微信開發
微信系統開發 微信開發功能 公眾號基礎教程 開發技術資訊 公眾號推廣營銷 客戶案例
聯系我們
QQ服務群:28519571 工作時間:86-0898-31568080 傳真號碼:86-0898-31568085 24小時服務:0138-07590485
 您現在的位置: 首頁 >> 微信開發 >> 開發技術資訊 開發技術資訊
使用PHP在微信公共平臺實現24點游戲
海南中立科技 | 2018-01-26 23:30:43 | 閱讀:5940
使用PHP在微信公共平臺實現24點游戲,搭建服務器為SAE,所以很多語句和MYSQL不太一樣,24點的數據庫存儲在24data里面,先用python計算出結果然后存儲在本地的txt文件最后倒入SAE的MYSQL,記錄了所有有解的4個數字。可以添加微信號:24點。//defineyourtokendefine("TOKEN","ddwm");define("INPUT_NAME","1");define("START_GAME","2");define("TIMING_START","3");define("TIMING_END","4");$wechatObj=newWhy24Point();if($_GET["echostr"])$wechatObj--->valid();else$wechatObj->responseMsg();classWhy24Point{publicfunctionresponseMsg(){//getpostdata,Maybeduetothedifferentenvironments$postStr=$GLOBALS["HTTP_RAW_POST_DATA"];//extractpostdataif(!empty($postStr)){$postObj=simplexml_load_string($postStr,'SimpleXMLElement',LIBXML_NOCDATA);$fromUsername=$postObj->FromUserName;$toUsername=$postObj->ToUserName;if($postObj->Event=="subscribe"){$time=time();$textTpl="%s";$msgType="text";$contentStr="喲你好親愛的小伙伴,歡迎來到24點~\n游戲規則:使用+-*/四則運算得出結果為24即可。\n任何時候輸入主頁返回主菜單,\n輸入排名查看當前排名喲~\n如果有情況反饋請發送語音信息!\n請輸入任意內容,開始我們的24點職業生涯!";$resultStr=sprintf($textTpl,$fromUsername,$toUsername,$time,$msgType,$contentStr);echo$resultStr;}$keyword=trim($postObj->Content);$time=time();$textTpl="%s";if(!empty($keyword)){$msgType="text";$contentStr=$this->getData($fromUsername,$keyword);$resultStr=sprintf($textTpl,$fromUsername,$toUsername,$time,$msgType,$contentStr);echo$resultStr;}else{echo"輸入點東西吧。。";}}else{echo"";exit;}}privatefunctiongetData($fromUsername,$keyword){if($keyword=="主頁"){$this->setStep($fromUsername,constant("START_GAME"));return"歡迎來到24點的決戰現場。請輸入任意內容,開始我們的24點職業生涯!任何時候輸入主頁返回主菜單,輸入排名查看當前排名~";}if($keyword=="排名"){return"您的目前排名是:".$this->getRank($fromUsername);}if($this->isFirst($fromUsername)){return"這是你第一次參加游戲,請輸入你的用戶昵稱:";}if($this->getStep($fromUsername)==constant("INPUT_NAME")){$this->setName($fromUsername,$keyword);$this->setStep($fromUsername,constant("START_GAME"));return"你好,".$keyword."同學。請輸入任意內容,開始我們的24點職業生涯!任何時候輸入主頁返回主菜單,輸入排名查看當前排名~";}if($this->getStep($fromUsername)==constant("START_GAME")){$numbers=$this->getNumbers();$this->setStep($fromUsername,constant("TIMING_START"));return"游戲規則:使用+-*/四則運算得出結果為24即可。\n請聽題!".$this->getNumbers();}if($this->getStep($fromUsername)==constant("TIMING_START")){if($this->calcStr($keyword)){//$this->setStep($fromUsername,constant("TIMING_END"));$this->setGrade($fromUsername,5);$this->setStep($fromUsername,constant("START_GAME"));return"結果等于24!你現在的分數是:".$this->getGrade($fromUsername);}return"結果錯誤!騙子,根本就不等于24!";//$this->setStep($fromUsername,constant("TIMING_END"));}return"我擦,系統出問題了。抱了個歉哈!";}//計算排名privatefunctiongetRank($fromUsername){$mysql=newSaeMysql();$grade=$this->getGrade($fromUsername);$sql="SELECTCOUNT(*)FROM`24points`WHERE`grade`>".$grade."";$mysql->closeDb();returnintval($mysql->getVar($sql))+1;}//計算成績privatefunctionsetGrade($fromUsername,$add){$mysql=newSaeMysql();$sql="SELECTgradeFROM`24points`WHERE`userid`='".$fromUsername."'";$grade=intval($mysql->getVar($sql))+$add;$sql="UPDATE`24points`SET`grade`='".$grade."'WHERE`userid`='".$fromUsername."';";$mysql->runSql($sql);$mysql->closeDb();}//獲得成績privatefunctiongetGrade($fromUsername){$mysql=newSaeMysql();$sql="SELECTgradeFROM`24points`WHERE`userid`='".$fromUsername."'";$mysql->closeDb();returnintval($mysql->getVar($sql));}//計算等式,返回正確或者錯誤privatefunctioncalcStr($keyword){$keyword=str_replace("(","(",$keyword);$keyword=str_replace(")",")",$keyword);$keyword=str_replace("÷","/",$keyword);$keyword=str_replace("/","/",$keyword);$keyword=str_replace("×","*",$keyword);$atr_arr=str_split($keyword);$new_atr='';for($i=0;$i<strlen($keyword);$i++){$new_atr=$new_atr.$atr_arr[$i];}$s=eval("return$new_atr;");if($s==24){returntrue;}returnfalse;}//是否是第一次privatefunctionisFirst($fromUsername){$mysql=newSaeMysql();$sql="SELECT*FROM`24points`WHERE`userid`='".$fromUsername."'";$data=$mysql->getData($sql);if(count($data)==0){$sql="INSERTINTO`24points`(`userid`,`step`)VALUES('".$fromUsername."','".constant("INPUT_NAME")."');";$mysql->runSql($sql);$mysql->closeDb();returntrue;}returnfalse;}//獲取當前的步驟privatefunctiongetStep($fromUsername){$mysql=newSaeMysql();$sql="SELECTstepFROM`24points`WHERE`userid`='".$fromUsername."'";$mysql->closeDb();return$mysql->getVar($sql);}//獲取隨機的四個數字用空格隔開privatefunctiongetNumbers(){$rand_id=rand(1,1362);$mysql=newSaeMysql();$sql="SELECTnum1FROM`24data`WHERE`id`='".$rand_id."'";$num1=$mysql->getVar($sql);$sql="SELECTnum2FROM`24data`WHERE`id`='".$rand_id."'";$num2=$mysql->getVar($sql);$sql="SELECTnum3FROM`24data`WHERE`id`='".$rand_id."'";$num3=$mysql->getVar($sql);$sql="SELECTnum4FROM`24data`WHERE`id`='".$rand_id."'";$num4=$mysql->getVar($sql);$mysql->closeDb();$numbers=$num1."".$num2."".$num3."".$num4;return$numbers;}//設置當前操作的步數privatefunctionsetStep($fromUsername,$step){$mysql=newSaeMysql();$sql="UPDATE`24points`SET`step`='".$step."'WHERE`userid`='".$fromUsername."';";$mysql->runSql($sql);$mysql->closeDb();}//設置用戶昵稱privatefunctionsetName($fromUsername,$username){$mysql=newSaeMysql();$sql="UPDATE`24points`SET`username`='".$username."'WHERE`userid`='".$fromUsername."';";$mysql->runSql($sql);$mysql->closeDb();}//驗證微信publicfunctionvalid(){$echoStr=$_GET["echostr"];//validsignature,optionif($this->checkSignature()){echo$echoStr;exit;}}//檢查簽名privatefunctioncheckSignature(){$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){returntrue;}else{returnfalse;}}}111811111111121111311261127112811291121011211112121121311341135113611371138113911310113111131211313114411451146114711481149114101141211551156115711581166116811691161211710118811913111012111013111111111112111113111212111213111313122412251226122712281229122101221112212122131233123412351236123712381239123101231112312123131244124512461247124812491241012411124121241312551256125712581259125101251212513126612671268126912610126111261212613127712781279127101271112712128812891281012813129111291212913121011121012121013121111121112121113121212121213121313133313341335133613371338133913310133111331213441345134613471348134913410134111341213413135613571358135913510135111351213513136613671368136913610136111361213613137713781379137101371213713138813891381013811138121381313991391013911139121391313101013101113101213111113111213121213121313131314441445144614471448144914410144111441214551456145714581459145101451114512145131466146714681469146101461114612146131477147814791471114712147131488148914811148121481314910149111491214913141010141011141012141212155515561559155101551115512155131566156715681569156101561115612156131578157915710157111571215713158815891581015811158121581315991591015911159121591315101015101115101215101315111115111215121216661668166916610166111661216613167916710167111671216881689168101681116812168131699169101691216913161012161013161112161113161212161213177917710177111771217881789178101781117812179917910179111791217913171012171013171212171213171313188818891881018811188121891118912189131810111810121810131811121811131812121991219101219101319111119111219111319121211010121101112110121211012131111112111111311112121111213111131311212121121213112131322232224222522272228222922210222112221222213223322342235223622372238223922310223112231222313224422452246224722482249224102241122412224132255225622572258225922510225112251222662267226822692261022611226122261322772278227102271222713228822892281022812229102291122912221010221011221013221111221112221113221212221213221313233323352336233723382339233102331123312233132344234523462347234823492341023411234122341323552356235723582359235102351123512235132366236723682369236102361123612236132377237823792371023711237122371323882389238102381123812238132399239102391223913231010231012231013231111231112231113231212231213231313244424452446244724482449244102441124412244132455245624572458245924510245112451224513246624672468246924610246112461224613247724782479247102471124712248824892481024811248122481324992491024912249132410102410112410122410132411112411122412122413132557255825592551025511255122551325662567256825692561025611256122561325772578257925710257112571325882589258102581125812258132591025911259122510102510112510122510132511122512122512132666266726682669266102661126612266132678267926710267112671226713268826892681026811268122681326992691026911269122610102610112610122610132611122611132612122612132778277102771127712277132788278927811278122781327910279112791327101027101127101227111227121227121328882889288102881128812288132899289102891128912289132810102810112810122810132811112811122812122812132813132991129912299132910102910112910122910132911112911132912132913132101011210101221010132101111210111221011132101213211111121111122111113211121221112132111313212121221212132121313213131333333334333533363337333833393331033311333123344334533463347334833493341133412334133355335633573359335103351233513336633673368336933610336113361233613337733783379337113371233713338833893381033812338133399339103391133912339133310133311123311133312123312133444344534463447344834493441034411344123441334553456345734583459345103451134512345133466346834693461034611346123461334773478347934710347113471234893481034811348123481334993491134912349133410103410123410133411123411133412123412133556355735583559355113551235663567356835693561035611356123561335783579357103571135712357133588358935811358123581335993591035912359133510103510113510123510133511113511123512123512133513133666366736683669366103661136612366133677367836793671036712367133688368936810368123681336993691036911369123691336101036101136101236111136111236111336121236121336131337773778377937710377123771337883789378113781237813379937910379113791237913371010371011371013371111371112371212371213371313388838893881038811388123899389103891138912389133810103810113810123811113811123812123812133813133999399103991139912399133910103910113910123910133911113911123911133912123912133913133101012310111231011133111112311121231212123121213312131344444445444644474448444944410444114441244554456445744584451044511445124451344684469446104461144612446134477447844794471044712447134488448944810448114481244813449114491244101044101244101344111244111344121244121345554556455745584559455104566456745684569456104561145612456134577457845794571045711457124571345884589458104581145812458134599459104591245913451010451011451012451013451111451112451113451212451213451313466646674668466946610466124677467846794671046712468846894681046812468134699469104691246913461010461011461012461111461112461212461213461313477747784771147884789478104781147812478134799479104791147912479134710104710114710124711114711124711134712124712134713134888488948810488114881248813489948910489114891248913481010481011481012481111481112481113481212481213481313499104991249101149101249101349111149111249121241010114101012410111241011134101212410121341112134121212555555565559555125566556755685561155775578557105571155885589558105581155812558135599559105591155101055101155101355111155111255111355121255121355131356665667566856695661056612567756785679567125671356885689568105681256813569956910569115691256913561010561011561012561013561111561112561113561212561213561313577957710577115788578957810579105791157912579135710105710115710125710135711115711135712125713135888588958810588135891158912589135810115810125811125811135812125991159912591010591011591013591113591212591213510101151010125101013510111151012135101313511121266666668666966610666116661266796671066711667126688668966810668116681266813669106691166912669136610126610136611126611136612126612136771067711678967810678116781267996791267101067101267101367111167111267111367121267121368886889688106881168812689968910689116891268913681011681012681013681111681112681113681212681313699106991169912691011691012691112691113691212691213610101061010136101112610121261012136111112611121261112136121212612121361213137771277811779107710137711127711137712127712137889788107881178812788137891078912789137810107810117810137811127811137812127812137991379101179101279111179111279121279131371010117101012710111371012127101213712121388810888118881288813889118891288913881012881013881112881113881212881213899128910128910138911118911128911138912128912138101012810111181012128101213810131381112129991299101399111299111399121299121391010139101112910111391012129101213911111191112129111213911131391212121010101210101013101011121010111310101212101012131011111210111113101112121011121310121212101212131012131310131313111111121111111311111212111112131112121211121213111213131113131312121212121212131212131312131313
||||||||||||||||
合作伙伴 企業發展 企業文化 聯系我們 在線訂購 網站地圖 返回首頁手機版
海南中立科技有限公司2020版權所有 24小時服務熱線:13807590485   歡迎來電咨詢
地址:海南省.海口市.海甸二東路環惠大廈6樓(南寶路明都大廈107#) 公司電話:0898-31568080 31568060 QQ:85398489
全國合作聯盟分布:海南海口 四川成都 湖北武漢 湖南長沙 安徽合肥 廣東深圳 山西太原 西藏拉薩
技術服務: E_mail:zlkj_2008@126.com 服務訂購:E_mail:server@web0898.net 在線客服邀請 備案/經營許可號:瓊ICP備10201086號-9
推廣關鍵字:海南網站建設公司,海南網站制作公司,海南網站開發公司,海南微信開發公司,海南微信公眾號開發公司,海南微信公眾號代運營公司,海南模板網站制作公司,海南網頁設計公司,海南網絡公司

在線客服
掃描直接聯系
亚洲 色 欧美 爱 视频 日韩_亚洲国产a在线观看免费视频_亚洲 欧美 中文字幕 在线