# TODO: 微信校验消息推送接口
def get_request(request):
try:
wechat_data = request.GET
signature = wechat_data['signature']
timestamp = wechat_data['timestamp']
nonce = wechat_data['nonce']
echostr = wechat_data['echostr']
token = 'xxxx' # 这个token要和微信后台配置token一致
hashlist = [token, timestamp, nonce]
hashlist.sort()
sha1 = hashlib.sha1()
sha1.update(hashlist[0].encode('utf-8'))
sha1.update(hashlist[1].encode('utf-8'))
sha1.update(hashlist[2].encode('utf-8'))
hashcode = sha1.hexdigest()
if hashcode == signature:
return HttpResponse(echostr)
else:
print('异常')
return HttpResponse('error')
except Exception as e:
print(e)
return HttpResponse(str(e))
微信校验消息推送接口
最新推荐文章于 2023-03-17 22:59:00 发布