{“base_resp”:{“err_msg”:“verify token fail”,“ret”:200302}}
我把微信调用的请求信息打印出来,手动发送命令,返回的就是echostr的值,是字符串的
python连接,同问
我甚至跳过验证,都提示失败??????
import web import hashlib urls = ( '/wx' , 'Handle' , ) class Handle( object ): def GET( self ): try : data = web. input () if len (data) = = 0 : return "hello, this is handle view" return data.echostr except Exception as Argument: return Argument if __name__ = = '__main__' : app = web.application(urls, globals ()) app.run() |
{“base_resp”:{“ret”:200302,“err_msg”:“verify token fail”}}
请问官方到底是什么情况啊?你们文档是我看到现在写的最模糊的,各种问题
经测试,文档中 “ 开发者通过检验signature对请求进行校验(下面有校验方式)。若确认此次GET请求来自微信服务器,请原样返回echostr参数内容,则接入生效,成为开发者成功,否则接入失败。” (https://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421135319) ,所谓“原样返回echostr参数内容”,就是说直接把echostr写到应答包体中即可,不带任何格式即可成功,文档原文表述不清晰。成功的校验抓包如下:
GET /shwx/api/callback?signature=67e14d2ed1f32698bab9ed7b673fab3f8ab7f902&echostr=382485513798135407×tamp=1552460909&nonce=583572733 HTTP/1.0
Host: gzh
Connection: close
User-Agent: Mozilla/4.0
Accept: */*
Pragma: no-cache
HTTP/1.1 200 OK
Date: Wed, 13 Mar 2019 07:08:29 GMT
X-Application-Context: application:8083
Content-Type: text/plain;charset=iso-8859-1
Content-Length: 18
382485513798135407
我python3.5
# -*- coding: utf-8 -*- # filename: handle.py import hashlib import web class Handle( object ): def GET( self ): try : data = web. input () if len (data) = = 0 : return "hello, this is handle view" signature = data.signature timestamp = data.timestamp nonce = data.nonce echostr = data.echostr token = "123" #请按照公众平台官网\基本配置中信息填写 list = [token, timestamp, nonce] list .sort() list = [token, timestamp, nonce] list .sort() # python2.7 # sha1 = hashlib.sha1() # map(sha1.update, list) # hashcode = sha1.hexdigest() # python3.x sha1 = hashlib.sha1() sha1.update( list [ 0 ].encode( "utf-8" )) sha1.update( list [ 1 ].encode( "utf-8" )) sha1.update( list [ 2 ].encode( "utf-8" )) hashcode = sha1.hexdigest() # 获取加密串 # python3.x # temp = ''.join(list) # sha1 = hashlib.sha1(temp.encode('utf-8')) # map(sha1.update, list) # hashcode = sha1.hexdigest() # print("handle/GET func: hashcode, signature: ", hashcode, signature) if hashcode = = signature: # print(echostr) return echostr else : return '' except Exception: return Exception |
后台看见200 ok,echostr也return了,依旧token验证失败