示例代码无法在python3通过测试
发布于 5 年前 作者 nahao 10324 次浏览 来自 问答

https://developers.weixin.qq.com/doc/offiaccount/Getting_Started/Getting_Started_Guide.html

[@app](/user/app).get("/")
def verify(signature,timestamp,nonce,echostr):
    print(signature,timestamp,',',nonce,',',echostr)

    signature = signature.strip()
    timestamp = timestamp.strip()
    nonce = nonce.strip()
    echostr = echostr.strip()

    token = 'zhangboyi'
    li = [token, timestamp, nonce]
    li.sort()
    sha1 = hashlib.sha1()
    list(map(sha1.update, [x.encode('utf-8') for x in li]))
    hashcode = sha1.hexdigest()
    print("handle/GET func: hashcode, signature: ", hashcode, signature)
    if hashcode == signature:
        return echostr
    else:
        return ''
代码更换之后,能够成功返回enchostr的信息,但是却还是提示token验证失败


回到顶部