1.一步一步来的版本
def wx(request):
try:
signature = request.GET.get('signature')
timestamp = request.GET.get('timestamp')
nonce = request.GET.get('nonce')
echostr = request.GET.get('echostr')
token = "fenghaojie" #请按照公众平台官网\基本配置中信息填写
list = [ nonce,timestamp,token]
list.sort()
sha1 = hashlib.sha1()
new=(''.join(str(i) for i in list))
print(new)
sha1.update(new.encode('utf-8'))
hashcode = sha1.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)
2. 简化版本: 直接返回echostr
def wx(request):
try:
echostr = request.GET.get('echostr')
return HttpResponse(echostr)