微信公众平台 接口设置出现“你的服务器没有正确响应Token验证,请阅读消息接口使用指南”解决方案 Python

设置接口信息的时候出现这种情况:

你的服务器没有正确响应Token验证,请阅读消息接口使用指南

这是因为在设置的时候微信服务器对你的服务器响应进行测试,你可以这样子,我的实在SAE上的,代码如下:

index.wsgi

# -*- coding: UTF-8 -*
'''
Created on 2013-8-31

@author: RobinTang
'''

import hashlib
import re

# 修改wxtoken为你公共帐号设置的Token值
wxtoken = 'youtoken'

def checksignature(pams):
    global wxtoken
    signature = pams['signature']
    timestamp = pams['timestamp']
    nonce = pams["nonce"];
    tmparr = [wxtoken, timestamp, nonce]
    tmparr.sort()
    tmpstr = ''.join(tmparr)
    tmpstr = hashlib.sha1(tmpstr).hexdigest()
    return tmpstr == signature

def checksignatureresponse(pams):
    if checksignature(pams):
        return pams['echostr']
    else:
        return ''

def app(environ, start_response):
    status = '200 OK'
    response_headers = [('Content-type', 'text/html; charset=utf-8')]
    start_response(status, response_headers)
    s = environ['QUERY_STRING']
    pams = dict(re.findall('([^=, ^&, ^?]*)=([^=, ^&]*)', s))
    return [checksignatureresponse(pams)]

try:
    import sae
    application = sae.create_wsgi_app(app)
except:
    pass

记得设置一下你的Token值就行。


發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章