记录微信各种校验问题

公众平台申请测试账号提交token验证

file

//直接调用
$this->valid()

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 = 'xxxx';//注意这里改成你填的token
    $tmpArr = array($token, $timestamp, $nonce);
    sort($tmpArr);      //进行字典序排序
    //sha1加密后与签名对比
    if (sha1(implode($tmpArr)) == $signature) {
        return true;
    } else {
        return false;
    }
}

微信支付的错误文档