微信后台服务器地址验证的逻辑

时间:2018-03-04 13:00:40   收藏:0   阅读:210

不说废话了,直接上py3 django代码:

    token = "-----------------------------"#自己填到微信设置里面的token
    nonce = request.GET["nonce"]
    timestamp = request.GET["timestamp"]
    msg_sign = request.GET["signature"]
    arr1 = [token,timestamp,nonce]
    arr1.sort()
    tempstr = "".join(arr1)
    sha1 = hashlib.sha1()
    sha1.update(tempstr.encode(utf-8))
    compute_sign = sha1.hexdigest()
    if msg_sign == compute_sign:
        return HttpResponse(request.GET["echostr"])

 

评论(0
© 2014 mamicode.com 版权所有 京ICP备13008772号-2  联系我们:gaon5@hotmail.com
迷上了代码!