教程集 www.jiaochengji.com
教程集 >  脚本编程  >  php  >  正文 微信开发Token验证失败或请求URL超时问题解决办法

微信开发Token验证失败或请求URL超时问题解决办法

发布时间:2017-10-25   编辑:jiaochengji.com
教程集为您提供微信开发Token验证失败或请求URL超时问题解决办法等资源,欢迎您收藏本站,我们将为您提供最新的微信开发Token验证失败或请求URL超时问题解决办法资源

1.Token验证失败

这个就是要检查配置文件了,最基本的就是

define("TOKEN", "weixin");  weixin 是你的微信开发后台的ID

微信开发Token验证失败或请求URL超时问题解决办法
2.请求URL超时

这个没什么办法多提交几次了,这个还有就是服务器安装了安全狗之类的软件把微信IP给拦截了,可以检查一下。

3.官方下载一个wechatCallbackapiTest类然后进行一下操作即可

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy1677')"><textarea id="copy1677" rows="10" cols="40" style="display: none;"></textarea></td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy1677>

define("TOKEN", "weixin");
$wechatObj = new wechatCallbackapiTest();
if (isset($_GET['echostr'])) {
    $wechatObj->valid();
}else{
    $wechatObj->responseMsg();
}

</td></tr></table>

wechatCallbackapiTest类就代码如下

<table width="620" align="center" border="0" cellpadding="1" cellspacing="1" style="background:#FB7"> <tr> <td width="464" height="27" bgcolor="#FFE7CE"> 代码如下</td> <td width="109" align="center" bgcolor="#FFE7CE" style="cursor:pointer;" onclick="doCopy('copy7317')"><textarea id="copy7317" rows="10" cols="40" style="display: none;"></textarea></td> </tr> <tr> <td height="auto" colspan="2" valign="top" bgcolor="#FFFFFF" style="padding:10px;" class="copyclass" id=copy7317>

class wechatCallbackapiTest
{
    public function valid()
    {
        $echoStr = $_GET["echostr"];
        if($this->checkSignature()){
            echo $echoStr;
            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;
        }
    }

    public function responseMsg()
    {
        $postStr = $GLOBALS["HTTP_RAW_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 = "<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($keyword != " " || !empty( $keyword ) )
            {
    msgType = "text";
    //$contentStr .= date("Y-m-d H:i:s",time());
    $resultStr = sprintf($textTpl, $fromUsername, $toUsername, $time, $msgType, $contentStr);
    echo $resultStr;
            }
        }else{
            echo "";
            exit;
        }
    }
}

</td></tr></table>

您可能感兴趣的文章:
微信开发Token验证失败或请求URL超时问题解决办法
Golang 实现Thrift客户端连接池
API接口之安全篇
flask怎么实现公众号开发
Go语言基础之单元测试
Golang之goroutine(协程)与channel(管道)
golang sync.Mutex互斥锁的实现原理
nsqd解析:nsqd-channel
利用go特性实现高并发接口
go-discovery服务注册与发现

[关闭]
~ ~