Last active
January 14, 2017 06:25
-
-
Save 1c7/b8e7b7f39e1d02d3db26a05908bef683 to your computer and use it in GitHub Desktop.
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
| # -*- coding: utf-8 -*- | |
| # filename: handle.py | |
| ''' | |
| ### 环境 | |
| python 2.7 + web.py | |
| web.py 安装方法是: pip install web.py | |
| ### 说明 | |
| 微信公众平台 -> 基本配置 -> 服务器配置 | |
| 有一个服务器验证的步骤,用这个脚本可以解决 | |
| ### 使用方法 | |
| sudo python handle.py 80 # 如果用 http | |
| sudo python handle.py 443 # 如果用 https | |
| ''' | |
| print('https wx') | |
| from web.wsgiserver import CherryPyWSGIServer | |
| import hashlib | |
| import web | |
| urls = ( | |
| '/wx', 'Handle', | |
| '/', 'root', | |
| ) | |
| app = web.application(urls, globals()) | |
| class root(object): | |
| def GET(self): | |
| return "hello, this is a test" | |
| class Handle(object): | |
| def GET(self): | |
| try: | |
| data = web.input() | |
| if len(data) == 0: | |
| return "yo, wx." | |
| signature = data.signature | |
| timestamp = data.timestamp | |
| nonce = data.nonce | |
| echostr = data.echostr | |
| token = "herego_with_herego" #请按照公众平台官网\基本配置中信息填写 | |
| list = [token, timestamp, nonce] | |
| list.sort() | |
| sha1 = hashlib.sha1() | |
| map(sha1.update, list) | |
| hashcode = sha1.hexdigest() | |
| print "handle/GET func: hashcode, signature: ", hashcode, signature | |
| if hashcode == signature: | |
| return echostr | |
| else: | |
| return "" | |
| except Exception, Argument: | |
| return Argument | |
| if __name__ == '__main__': | |
| ssl_cert = '/var/www/myherego.com/shared/myherego.com.crt' | |
| ssl_key = '/var/www/myherego.com/shared/myherego.com.key' | |
| CherryPyWSGIServer.ssl_certificate = ssl_cert | |
| CherryPyWSGIServer.ssl_private_key = ssl_key | |
| app.run() |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment