微信公众号Token验证 signature验证

    xiaoxiao2022-06-27  221

    首先去公众号的后台配置  URL,然后在 代码 的页面验证Token

    代码为

    $signature = $_GET["signature"]; $timestamp = $_GET["timestamp"]; $nonce = $_GET["nonce"]; $echostr = $_GET["echostr"]; $token = "jia7777777"; $tmpArr = array($nonce,$token,$timestamp); sort($tmpArr,SORT_STRING); $str = implode($tmpArr); $sign = sha1($str); if ($sign == $signature) { ob_clean(); //加了这个,省得老是配置失败; echo $echostr; }

     

    第三方授权认证的 signature代码为

    function make_signature($nonceStr,$timestamp,$jsapi_ticket,$url) { $tmpArr = array( 'noncestr' => $nonceStr, 'timestamp' => $timestamp, 'jsapi_ticket' => $jsapi_ticket, 'url' => $url ); ksort($tmpArr, SORT_STRING); $string1 = http_build_query( $tmpArr ); $string1 = urldecode( $string1 ); $signature = sha1( $string1 ); return $signature; }

     


    最新回复(0)