微信公衆平臺 接口設置出現“你的服務器沒有正確響應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值就行。


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