问答详情
源自:4-6 提交验证接口

如何判断是微信服务发送的Get,返回的参数呢?如何对比?

还是没讲述明白我们如何判断是否是微信服务器向我们发送的Get请求

提问者:晓风z 2016-05-22 16:15

个回答

  • 慕圣5050932
    2016-05-22 20:16:39

    <?php


    //获得参数 signature nonce token timestamp echostr

    $nonce     = $_GET['nonce'];

    $token     = 'imooc';

    $timestamp = $_GET['timestamp'];

    $echostr   = $_GET['echostr'];

    $signature = $_GET['signature'];

    //形成数组,然后按字典序排序

    $array = array();

    $array = array($nonce, $timestamp, $token);

    sort($array);

    //拼接成字符串,sha1加密 ,然后与signature进行校验

    $str = sha1( implode( $array ) );

    if( $str  == $signature && $echostr ){

    //第一次接入weixin api接口的时候

    echo  $echostr;

    exit;

    }