微信公众号测试号申请及访问(图详解)

1.微信公众号测试号申请地址,先去申请
http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index

2.然后进入测试号管理,你会得到一个APPID和APPSECRET  

微信公众号测试号申请及访问(图详解)_第1张图片

3.配置接口信息需要你自己的服务器,你可以申请云服务器去弄,自己可以百度,也可以用NATAPP把内网映射出去,具体的可以看 我自己写的  http://blog.csdn.net/m0_37987521/article/details/79525515

4.配置URL和TOKEN,TOKEN你可以随便的写

5.在本地服务器上运行代码,接收微信服务器发来的参数,具体的可以参考文档:https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319

微信公众号测试号申请及访问(图详解)_第2张图片

这里我找了一个demo

//define your token
define("TOKEN", "weixin");
$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)){

            $postObj = simplexml_load_string($postStr, 'SimpleXMLElement', LIBXML_NOCDATA);
            $fromUsername = $postObj->FromUserName;
            $toUsername = $postObj->ToUserName;
            $keyword = trim($postObj->Content);
            $time = time();
            $textTpl = "  
                              
                              
                            %s  
                              
                              
                            0  
                            ";
            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()
    {
        $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;
        }
    }
}
 
  

你在服务器运行就可以了,然后在配置URL哪里写好你的路径,然后点击提交。如果现实配置错误,那你就检测你的路径是不是对的。微信公众号测试号申请及访问(图详解)_第3张图片




你可能感兴趣的:(微信公众号测试号申请及访问(图详解))