class DeviceEventReply(BaseReply): type = 'device_event' event = StringField('Event') device_type = StringField('DeviceType') device_id = StringField('DeviceID') session_id = StringField('SessionID') content = Base64EncodeField('Content')
class WiFiConnectedEvent(BaseEvent): event = 'wificconnected' connect_time = IntegerField('ConnectTime') expire_time = IntegerField('ExpireTime') vendor_id = StringField('VendorId') shop_id = StringField('PlaceId') bssid = StringField('DeviceNo')
class DeviceUnbindEvent(BaseEvent): event = 'unbind' device_type = StringField('DeviceType') device_id = StringField('DeviceID') session_id = StringField('SessionID') content = Base64DecodeField('Content') open_id = StringField('OpenID')
class ImageMessage(BaseMessage): """ 图片消息 详情请参阅 http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html """ type = 'image' media_id = StringField('MediaId') image = StringField('PicUrl')
class VideoMessage(BaseMessage): """ 视频消息 详情请参阅 http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html """ type = 'video' media_id = StringField('MediaId') thumb_media_id = StringField('ThumbMediaId')
class VoiceMessage(BaseMessage): """ 语音消息 详情请参阅 http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html """ type = 'voice' media_id = StringField('MediaId') format = StringField('Format') recognition = StringField('Recognition')
class UserScanProductEnterSessionEvent(BaseEvent): """ 进入公众号事件 详情请参考 http://mp.weixin.qq.com/wiki/15/f4109a5e44b4bfbc7eb1337eb739f3e3.html """ event = 'user_scan_product_enter_session' standard = StringField('KeyStandard') key = StringField('KeyStr')
class ScanEvent(BaseEvent): """ 用户扫描二维码事件 详情请参阅 http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html """ event = 'scan' scene_id = StringField('EventKey') ticket = StringField('Ticket')
class LinkMessage(BaseMessage): """ 链接消息 详情请参阅 http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html """ type = 'link' title = StringField('Title') description = StringField('Description') url = StringField('Url')
class UserDeleteCardEvent(BaseEvent): """ 卡券删除事件推送 详情请参阅 http://mp.weixin.qq.com/wiki/16/28b34ee91675a04cb24853768debded4.html#.E5.88.A0.E9.99.A4.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81 """ event = 'user_del_card' card_id = StringField('CardId') code = StringField('UserCardCode')
class UserScanProductAsyncEvent(BaseEvent): """ 地理位置信息异步推送事件 详情请参考 http://mp.weixin.qq.com/wiki/15/f4109a5e44b4bfbc7eb1337eb739f3e3.html """ event = 'user_scan_product_async' standard = StringField('KeyStandard') key = StringField('KeyStr') region_code = StringField('RegionCode')
class UserScanProductVerifyActionEvent(BaseEvent): """ 商品审核结果事件 详情请参考 http://mp.weixin.qq.com/wiki/15/f4109a5e44b4bfbc7eb1337eb739f3e3.html """ event = 'user_scan_product_verify_action' standard = StringField('KeyStandard') key = StringField('KeyStr') result = StringField('Result') reason = StringField('ReasonMsg')
class UserConsumeCardEvent(BaseEvent): """ 卡券核销事件推送 详情请参阅 http://mp.weixin.qq.com/wiki/16/28b34ee91675a04cb24853768debded4.html#.E6.A0.B8.E9.94.80.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81 """ event = 'user_consume_card' card_id = StringField('CardId') code = StringField('UserCardCode') consume_source = StringField('ConsumeSource') location_id = StringField('LocationId') staff = StringField('StaffOpenId')
class UserGetCardEvent(BaseEvent): """ 领取事件推送 详情请参阅 http://mp.weixin.qq.com/wiki/16/28b34ee91675a04cb24853768debded4.html#.E9.A2.86.E5.8F.96.E4.BA.8B.E4.BB.B6.E6.8E.A8.E9.80.81 """ event = 'user_get_card' card_id = StringField('CardId') is_given_by_friend = IntegerField('IsGiveByFriend') friend = StringField('FriendUserName') code = StringField('UserCardCode') old_code = StringField('OldUserCardCode') outer_id = StringField('OuterId')
class LocationMessage(BaseMessage): """ 地理位置消息 详情请参阅 http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html """ type = 'location' location_x = StringField('Location_X') location_y = StringField('Location_Y') scale = StringField('Scale') label = StringField('Label') @property def location(self): return self.location_x, self.location_y
class UserScanProductEvent(BaseEvent): """ 打开商品主页事件 详情请参考 http://mp.weixin.qq.com/wiki/15/f4109a5e44b4bfbc7eb1337eb739f3e3.html """ event = 'user_scan_product' standard = StringField('KeyStandard') key = StringField('KeyStr') country = StringField('Country') province = StringField('Province') city = StringField('City') sex = IntegerField('Sex') scene = IntegerField('Scene')
class TextReply(BaseReply): """ 文本回复 详情请参阅 http://mp.weixin.qq.com/wiki/9/2c15b20a16019ae613d413e30cac8ea1.html """ type = 'text' content = StringField('Content')
class LocationSelectEvent(BaseEvent): """ 弹出地理位置选择器的事件 详情请参阅 http://mp.weixin.qq.com/wiki/9/981d772286d10d153a3dc4286c1ee5b5.html """ event = 'location_select' key = StringField('EventKey') location_info = BaseField('SendLocationInfo', {}) @property def location_x(self): return self.location_info['Location_X'] @property def location_y(self): return self.location_info['Location_Y'] @property def location(self): return self.location_x, self.location_y @property def scale(self): return self.location_info['Scale'] @property def label(self): return self.location_info['Label'] @property def poiname(self): return self.location_info['Poiname']
class TextMessage(BaseMessage): """ 文本消息 详情请参阅 http://mp.weixin.qq.com/wiki/10/79502792eef98d6e0c6e1739da387346.html """ type = 'text' content = StringField('Content')
class BaseReply(six.with_metaclass(MessageMetaClass)): """Base class for all replies""" source = StringField('FromUserName') target = StringField('ToUserName') time = IntegerField('CreateTime', time.time()) type = 'unknown' def __init__(self, **kwargs): self._data = {} message = kwargs.pop('message', None) if message and isinstance(message, BaseMessage): if 'source' not in kwargs: kwargs['source'] = message.target if 'target' not in kwargs: kwargs['target'] = message.source if hasattr(message, 'agent') and 'agent' not in kwargs: kwargs['agent'] = message.agent if 'time' not in kwargs: kwargs['time'] = time.time() for name, value in kwargs.items(): field = self._fields.get(name) if field: self._data[field.name] = value else: setattr(self, name, value) def render(self): """Render reply from Python object to XML string""" tpl = '<xml>\n{data}\n</xml>' nodes = [] msg_type = '<MsgType><![CDATA[{msg_type}]]></MsgType>'.format( msg_type=self.type) nodes.append(msg_type) for name, field in self._fields.items(): value = getattr(self, name, field.default) node_xml = field.to_xml(value) nodes.append(node_xml) data = '\n'.join(nodes) return tpl.format(data=data) def __str__(self): if six.PY2: return to_binary(self.render()) else: return to_text(self.render())
class ViewEvent(BaseEvent): """ 点击菜单跳转链接事件 详情请参阅 http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html """ event = 'view' url = StringField('EventKey')
class ClickEvent(BaseEvent): """ 点击菜单拉取消息事件 详情请参阅 http://mp.weixin.qq.com/wiki/2/5baf56ce4947d35003b86a9805634b1e.html """ event = 'click' key = StringField('EventKey')
class TemplateSendJobFinishEvent(BaseEvent): """ 模板消息任务完成事件 详情请参阅 http://mp.weixin.qq.com/wiki/17/304c1885ea66dbedf7dc170d84999a9d.html """ id = IntegerField('MsgID') event = 'templatesendjobfinish' status = StringField('Status')
class QualificationVerifyFailEvent(BaseEvent): """ 资质认证失败事件 详情请参阅 http://mp.weixin.qq.com/wiki/1/7f81dec16b801b34629091094c099439.html """ event = 'qualification_verify_fail' fail_time = DateTimeField('FailTime') fail_reason = StringField('FailReason')
class NamingVerifyFailEvent(BaseEvent): """ 名称认证失败事件 客户端不打勾,但仍有接口权限。详情请参阅 http://mp.weixin.qq.com/wiki/1/7f81dec16b801b34629091094c099439.html """ event = 'naming_verify_fail' fail_time = DateTimeField('FailTime') fail_reason = StringField('FailReason')
class BaseMessage(six.with_metaclass(MessageMetaClass)): """Base class for all messages and events""" type = 'unknown' id = IntegerField('MsgId', 0) source = StringField('FromUserName') target = StringField('ToUserName') create_time = DateTimeField('CreateTime') time = IntegerField('CreateTime') def __init__(self, message): self._data = message def __repr__(self): _repr = "{klass}({msg})".format(klass=self.__class__.__name__, msg=repr(self._data)) if six.PY2: return to_binary(_repr) else: return to_text(_repr)
class BaseScanCodeEvent(BaseEvent): key = StringField('EventKey') scan_code_info = BaseField('ScanCodeInfo', {}) @property def scan_type(self): return self.scan_code_info['ScanType'] @property def scan_result(self): return self.scan_code_info['ScanResult']
class MassSendJobFinishEvent(BaseEvent): """ 群发消息任务完成事件 详情请参阅 http://mp.weixin.qq.com/wiki/15/5380a4e6f02f2ffdc7981a8ed7a40753.html """ id = IntegerField('MsgID', 0) event = 'masssendjobfinish' status = StringField('Status') total_count = IntegerField('TotalCount', 0) filter_count = IntegerField('FilterCount', 0) sent_count = IntegerField('SentCount', 0) error_count = IntegerField('ErrorCount', 0)
class BaseComponentMessage(six.with_metaclass(MessageMetaClass)): """Base class for all component messages and events""" type = 'unknown' appid = StringField('AppId') create_time = DateTimeField('CreateTime') def __init__(self, message): self._data = message def __repr__(self): _repr = "{klass}({msg})".format(klass=self.__class__.__name__, msg=repr(self._data)) if six.PY2: return to_binary(_repr) else: return to_text(_repr)
class BasePictureEvent(BaseEvent): key = StringField('EventKey') pictures_info = BaseField('SendPicsInfo', {}) @property def count(self): return int(self.pictures_info['Count']) @property def pictures(self): if self.pictures_info['PicList']: items = self.pictures_info['PicList']['item'] if self.count > 1: return items return [items] return []