Skip to content

Commit

Permalink
Weixin修改为继承所有类
Browse files Browse the repository at this point in the history
  • Loading branch information
zwczou committed Feb 3, 2017
1 parent 43ee985 commit cf50b21
Show file tree
Hide file tree
Showing 3 changed files with 26 additions and 6 deletions.
10 changes: 5 additions & 5 deletions weixin/__init__.py
Original file line number Diff line number Diff line change
Expand Up @@ -17,7 +17,7 @@
StandaloneApplication = namedtuple("StandaloneApplication", ["config"])


class Weixin(object):
class Weixin(WeixinMP, WeixinPay, WeixinLogin, WeixinMsg):
"""
微信SDK
Expand All @@ -42,9 +42,9 @@ def init_app(self, app):
app_id = app.config.get("WEIXIN_APP_ID")
app_secret = app.config.get("WEIXIN_APP_SECRET")
if token:
self.msg = WeixinMsg(token, sender, expires_in)
WeixinMsg.__init__(self, token, sender, expires_in)
if app_id and mch_id and mch_key and notify_url:
self.pay = WeixinPay(app_id, mch_id, mch_key, notify_url, mch_key_file, mch_cert_file)
WeixinPay.__init__(self, app_id, mch_id, mch_key, notify_url, mch_key_file, mch_cert_file)
if app_id and app_secret:
self.login = WeixinLogin(app_id, app_secret)
self.mp = WeixinMP(app_id, app_secret)
WeixinLogin.__init__(self, app_id, app_secret)
WeixinMP.__init__(self, app_id, app_secret)
10 changes: 10 additions & 0 deletions weixin/base.py
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,16 @@
__all__ = ("Map", "WeixinError")


try:
unicode = unicode
except NameError:
# python 3
basestring = (str, bytes)
else:
# python 2
bytes = str


class WeixinError(Exception):

def __init__(self, msg):
Expand Down
12 changes: 11 additions & 1 deletion weixin/msg.py
Original file line number Diff line number Diff line change
Expand Up @@ -199,9 +199,19 @@ def text(self, key='*'):
return self.register('text', key)

def __getattr__(self, key):
key = key.lower()
if key in ['image', 'video', 'voice', 'shortvideo', 'location', 'link', 'event']:
return self.register(key)
return self.register('event', key)
if key in ['subscribe', 'unsubscribe', 'location', 'click', 'view', 'scan', \
'scancode_push', 'scancode_waitmsg', 'pic_sysphoto', \
'pic_photo_or_album', 'pic_weixin', 'location_select', \
'qualification_verify_success', 'qualification_verify_fail', 'naming_verify_success', \
'naming_verify_fail', 'annual_renew', 'verify_expired', \
'card_pass_check', 'user_get_card', 'user_del_card', 'user_consume_card', \
'user_pay_from_pay_cell', 'user_view_card', 'user_enter_session_from_card', \
'card_sku_remind']:
return self.register('event', key)
raise AttributeError('invalid attribute "' + key + '"')

def view_func(self):
if request is None:
Expand Down

0 comments on commit cf50b21

Please sign in to comment.