网站备案审核实在太慢了, 并且程序太复杂,就简单学习测试下也不必整个备案空间。 而后就用了之前申请的sina sae空间+域名 配置了微信公众号我的测试沙箱环境。 php
而后是手机微信扫码受权后,就有以下界面 html
这一步能够参照微信接入说明 ,该页提供一个php的实例下载,很简单基本上修改一下自定义的TOKEN就行了,而后把验证页面放到本身的服务器上。
api
这里我提供我作的一个例子: 安全
准备资源:
服务器
域名+空间(个人是sae空间+万网域名)、仅做验证的php文件
微信
域名指向的空间根目录我建立了一个index.php dom
index.php
post
<?php /** * wechat php test */ //define your token define("TOKEN", "weixin_freddon");//只用改这一个TOKEN、任意名称,好比weixin_freddon $wechatObj = new wechatCallbackapiTest(); $wechatObj->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 = "<xml> <ToUserName><![CDATA[%s]]></ToUserName> <FromUserName><![CDATA[%s]]></FromUserName> <CreateTime>%s</CreateTime> <MsgType><![CDATA[%s]]></MsgType> <Content><![CDATA[%s]]></Content> <FuncFlag>0</FuncFlag> </xml>"; 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; } } } ?>
而后填写配置信息Token (必定要与上面的index.php中的token一致)、URL(index.php的地址)
学习
而后提交就能够了 测试
若是提示失败,请检查Token与URL【若是是本身的域名和空间,请备案; 百度sae、新浪sae的须要本身申请并且认证经过(就是本身拍一个手握证件照上传,很简单的 最短2天就o了),这一步必须必】
这一步其实也很简单的,可是不少人在这一步浪费很长时间,
填这个域名是必定不要带protocol的,好比说 http://www.sagosoft.com/ 这样是不对的,这是URL不是域名
域名应该是相似 www.sagosoft.com这样的 【不然在微信js-sdk接入时会提示invalid url domain】
域名填微信受权回调页面域名,若是是同一个域名跟上面的接口配置URL填同样便可
转载请注明:内容来自 http://my.oschina.net/freddon/blog/513449