脚本宝典收集整理的这篇文章主要介绍了PHP技术开发微信公众平台,脚本宝典觉得挺不错的,现在分享给大家,也给大家做个参考。
下面通过图文并茂的方式介绍微信公众平台开发过程,具体内容如下:
普通的功能可以通过编辑模式来搞定。开发模式具有更多的功能。让我们来使用开发模式开发helloword吧
步骤如下:
开始吧:
注册完以后要记得进行实名认证,不然绑定到公众平台的时候,会有永远的“无法获取token”的提示。(实名认证需要3个工作日才能成功)
然后可以点击创建应用。创建后可以在下面看到。
进入自己创建的应用。然后点击代码管理。
查看开发文档并下载官方提供的demo。
打开后是如下的代码:
PHP;"> valid(); 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)){ /* libxml_disable_entity_loader is to prevent XML eXternal Entity Injection,the best way is to check the validity of xml by yourself */ libxml_disable_entity_loader(true); $postObj = simplexml_load_string($postStr,'SimpleXMLElement',LIBXML_NOCDATA); $fromUsername = $postObj->FromUserName; $toUsername = $postObj->ToUserName; $keyword = trim($postObj->Content); $time = time(); $textTpl = ""; if(!empty( $keyword )) { $msgTyPE = "text"; $contentStr = "Welcome to wechat world!"; $resultStr = sPRintf($textTpl,$fromUsername,$toUsername,$time,$msgType,$contentStr); echo $resultStr; }else{ echo "Input something..."; } }else { echo ""; exIT; } } private function checkSignature() { // you must define TOKEN by yourself if (!defined("TOKEN")) { throw new Exception('TOKEN is not defined!'); } $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $token = TOKEN; $tmpArr = array($token,$timestamp,$nonce); // use SORT_STRING rule sort($tmpArr,SORT_STRING); $tmpStr = implode( $tmpArr ); $tmpStr = sha1( $tmpStr ); if( $tmpStr == $signature ){ return true; }else{ return false; } } } ?> %s 0
以上是脚本宝典为你收集整理的PHP技术开发微信公众平台全部内容,希望文章能够帮你解决PHP技术开发微信公众平台所遇到的问题。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。