微信开发基础篇

验证的代码实现

public function index()
    {

        //将timestamp,nonce,token按字典序排序
        $timestamp = $_GET['timestamp'];
        $nonce = $_GET['nonce'];
        $token = 'weixin';
        $signature = $_GET['signature'];
        //将排序之后的三个参数拼接之后用sha1加密
        $array = array($timestamp, $nonce, $token);
        sort($array);
        $tmpstr = implode('', $array);
        $tmpstr = sha1($tmpstr);
        //将加密后的字符串与sianature进行对比,判断请求是否来自于微信
        if ($tmpstr == $signature) {
            echo $_GET['echostr'];
            exit;
        }
    }

接口写好之后,点击提交,如果提示token验证失败,检查代码,确认代码没错的话,可能是网络等原因的问题,多点几次就行
这里写图片描述

發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章