import hashlib
class wx_check(View):
def get(self, request):
try:
data = request.GET
if len(data) == 0:
return HttpResponse("hello, this is handle view")
signature = data.get("signature")
timestamp = data.get("timestamp")
nonce = data.get("nonce")
echostr = data.get("echostr")
token = "ciyuemumhcygoodjob" # 请按照公众平台官网\基本配置中信息填写
new_list = [token, timestamp, nonce]
new_list.sort()
new_str = "".join(new_list)
sha = hashlib.sha1(new_str.encode("utf-8"))
hashcode = sha.hexdigest()
print("handle/GET func: hashcode, signature: ", hashcode, signature)
if hashcode == signature:
return HttpResponse(echostr)
else:
return HttpResponse("")
except Exception as Argument:
return HttpResponse(Argument)
微信官方有公布一套,是python2.7的demo,有些方法python3不适用了,这个是基于Django的,在views目录下复制后别忘记把url配置一下,确保微信服务器能够访问。