Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

第三个关于python3支持的pull request #28

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
2 changes: 1 addition & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -193,7 +193,7 @@ on_xxx函数需要返回一个WxResponse的子类实例。WxResponse的子类及
from flask import Flask
app = Flask(__name__)

@app.route('/wechat')
@app.route('/wechat', methods=['GET', 'POST'])
def wechat():
app = WxApp()
return app.process(request.args, request.data)
Expand Down
7 changes: 5 additions & 2 deletions wechat/crypt.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,8 +10,11 @@
import xml.etree.cElementTree as ET
import sys
import socket
reload(sys)
sys.setdefaultencoding('utf-8')
try:
reload(sys)
sys.setdefaultencoding('utf-8')
except:
pass

WXBizMsgCrypt_OK = 0
WXBizMsgCrypt_ValidateSignature_Error = -40001
Expand Down
11 changes: 10 additions & 1 deletion wechat/models.py
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,12 @@

def kv2element(key, value, doc):
ele = doc.createElement(key)

try: # python3 compatible
unicode
except:
unicode = str

if isinstance(value, str) or isinstance(value, unicode):
data = doc.createCDATASection(value)
ele.appendChild(data)
Expand Down Expand Up @@ -47,7 +53,10 @@ def __init__(self, xml=None):
class WxResponse(object):

def __init__(self, request):
self.CreateTime = long(time.time())
try:
self.CreateTime = long(time.time())
except:
self.CreateTime = int(time.time())
self.ToUserName = request.FromUserName
self.FromUserName = request.ToUserName
self.Extra = {}
Expand Down
2 changes: 1 addition & 1 deletion wechat/official.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,7 +36,7 @@ def is_valid_params(self, params):

sign_ele = [self.token, timestamp, nonce]
sign_ele.sort()
if(signature == sha1(''.join(sign_ele)).hexdigest()):
if(signature == sha1(''.join(sign_ele).encode('utf-8')).hexdigest()):
return True, echostr
else:
return None
Expand Down