events.py 6.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245
  1. # -*- coding: utf-8 -*-
  2. from werobot.messages.entries import StringEntry, IntEntry, FloatEntry
  3. from werobot.messages.base import WeRoBotMetaClass
  4. class EventMetaClass(WeRoBotMetaClass):
  5. pass
  6. class WeChatEvent(object, metaclass=EventMetaClass):
  7. target = StringEntry('ToUserName')
  8. source = StringEntry('FromUserName')
  9. time = IntEntry('CreateTime')
  10. message_id = IntEntry('MsgID', 0)
  11. def __init__(self, message):
  12. self.__dict__.update(message)
  13. class SimpleEvent(WeChatEvent):
  14. key = StringEntry('EventKey')
  15. class TicketEvent(WeChatEvent):
  16. key = StringEntry('EventKey')
  17. ticket = StringEntry('Ticket')
  18. class SubscribeEvent(TicketEvent):
  19. __type__ = 'subscribe_event'
  20. class UnSubscribeEvent(WeChatEvent):
  21. __type__ = 'unsubscribe_event'
  22. class ScanEvent(TicketEvent):
  23. __type__ = 'scan_event'
  24. class ScanCodePushEvent(SimpleEvent):
  25. __type__ = 'scancode_push_event'
  26. scan_type = StringEntry('ScanCodeInfo.ScanType')
  27. scan_result = StringEntry('ScanCodeInfo.ScanResult')
  28. class ScanCodeWaitMsgEvent(ScanCodePushEvent):
  29. __type__ = 'scancode_waitmsg_event'
  30. scan_type = StringEntry('ScanCodeInfo.ScanType')
  31. scan_result = StringEntry('ScanCodeInfo.ScanResult')
  32. class BasePicEvent(SimpleEvent):
  33. count = IntEntry('SendPicsInfo.Count')
  34. def __init__(self, message):
  35. super(BasePicEvent, self).__init__(message)
  36. self.pic_list = list()
  37. if self.count > 1:
  38. for item in message['SendPicsInfo']['PicList'].pop('item'):
  39. self.pic_list.append({'pic_md5_sum': item['PicMd5Sum']})
  40. else:
  41. self.pic_list.append(
  42. {
  43. 'pic_md5_sum': message['SendPicsInfo']
  44. ['PicList'].pop('item')['PicMd5Sum']
  45. }
  46. )
  47. class PicSysphotoEvent(BasePicEvent):
  48. __type__ = 'pic_sysphoto_event'
  49. class PicPhotoOrAlbumEvent(BasePicEvent):
  50. __type__ = 'pic_photo_or_album_event'
  51. class PicWeixinEvent(BasePicEvent):
  52. __type__ = 'pic_weixin_event'
  53. class LocationSelectEvent(SimpleEvent):
  54. __type__ = 'location_select_event'
  55. location_x = StringEntry('SendLocationInfo.Location_X')
  56. location_y = StringEntry('SendLocationInfo.Location_Y')
  57. scale = StringEntry('SendLocationInfo.Scale')
  58. label = StringEntry('SendLocationInfo.Label')
  59. poi_name = StringEntry('SendLocationInfo.Poiname')
  60. class ClickEvent(SimpleEvent):
  61. __type__ = 'click_event'
  62. class ViewEvent(SimpleEvent):
  63. __type__ = 'view_event'
  64. class LocationEvent(WeChatEvent):
  65. __type__ = 'location_event'
  66. latitude = FloatEntry('Latitude')
  67. longitude = FloatEntry('Longitude')
  68. precision = FloatEntry('Precision')
  69. class TemplateSendJobFinishEvent(WeChatEvent):
  70. __type__ = 'templatesendjobfinish_event'
  71. status = StringEntry('Status')
  72. class BaseProductEvent(WeChatEvent):
  73. key_standard = StringEntry('KeyStandard')
  74. key_str = StringEntry('KeyStr')
  75. ext_info = StringEntry('ExtInfo')
  76. class UserScanProductEvent(BaseProductEvent):
  77. __type__ = 'user_scan_product_event'
  78. country = StringEntry('Country')
  79. province = StringEntry('Province')
  80. city = StringEntry('City')
  81. sex = IntEntry('Sex')
  82. scene = IntEntry('Scene')
  83. class UserScanProductEnterSessionEvent(BaseProductEvent):
  84. __type__ = 'user_scan_product_enter_session_event'
  85. class UserScanProductAsyncEvent(BaseProductEvent):
  86. __type__ = 'user_scan_product_async_event'
  87. region_code = StringEntry('RegionCode')
  88. class UserScanProductVerifyActionEvent(WeChatEvent):
  89. __type__ = 'user_scan_product_verify_action_event'
  90. key_standard = StringEntry('KeyStandard')
  91. key_str = StringEntry('KeyStr')
  92. result = StringEntry('Result')
  93. reason_msg = StringEntry('ReasonMsg')
  94. class BaseCardCheckEvent(WeChatEvent):
  95. card_id = StringEntry('CardId')
  96. refuse_reason = StringEntry('RefuseReason')
  97. class CardPassCheckEvent(BaseCardCheckEvent):
  98. __type__ = 'card_pass_check_event'
  99. class CardNotPassCheckEvent(BaseCardCheckEvent):
  100. __type__ = 'card_not_pass_check_event'
  101. class BaseCardEvent(WeChatEvent):
  102. card_id = StringEntry('CardId')
  103. user_card_code = StringEntry('UserCardCode')
  104. class UserGetCardEvent(BaseCardEvent):
  105. __type__ = 'user_get_card_event'
  106. is_give_by_friend = IntEntry('IsGiveByFriend')
  107. friend_user_name = StringEntry('FriendUserName')
  108. outer_id = IntEntry('OuterId')
  109. old_user_card_code = StringEntry('OldUserCardCode')
  110. outer_str = StringEntry('OuterStr')
  111. is_restore_member_card = IntEntry('IsRestoreMemberCard')
  112. is_recommend_by_friend = IntEntry('IsRecommendByFriend')
  113. class UserGiftingCardEvent(BaseCardEvent):
  114. __type__ = 'user_gifting_card_event'
  115. is_return_back = IntEntry('IsReturnBack')
  116. friend_user_name = StringEntry('FriendUserName')
  117. is_chat_room = IntEntry('IsChatRoom')
  118. class UserDelCardEvent(BaseCardEvent):
  119. __type__ = 'user_del_card_event'
  120. class UserConsumeCardEvent(BaseCardEvent):
  121. __type__ = 'user_consume_card_event'
  122. consume_source = StringEntry('ConsumeSource')
  123. location_name = StringEntry('LocationName')
  124. staff_open_id = StringEntry('StaffOpenId')
  125. verify_code = StringEntry('VerifyCode')
  126. remark_amount = StringEntry('RemarkAmount')
  127. outer_str = StringEntry('OuterStr')
  128. class UserPayFromPayCellEvent(BaseCardEvent):
  129. __type__ = 'user_pay_from_pay_cell_event'
  130. trans_id = StringEntry('TransId')
  131. location_id = IntEntry('LocationId')
  132. fee = StringEntry('Fee')
  133. original_fee = StringEntry('OriginalFee')
  134. class UserViewCardEvent(BaseCardEvent):
  135. __type__ = 'user_view_card_event'
  136. outer_str = StringEntry('OuterStr')
  137. class UserEnterSessionFromCardEvent(BaseCardEvent):
  138. __type__ = 'user_enter_session_from_card_event'
  139. class UpdateMemberCardEvent(BaseCardEvent):
  140. __type__ = 'update_member_card_event'
  141. modify_bonus = IntEntry('ModifyBonus')
  142. modify_balance = IntEntry('ModifyBalance')
  143. class CardSkuRemindEvent(WeChatEvent):
  144. __type__ = 'card_sku_remind_event'
  145. card_id = StringEntry('CardId')
  146. detail = StringEntry('Detail')
  147. class CardPayOrderEvent(WeChatEvent):
  148. __type__ = 'card_pay_order_event'
  149. order_id = StringEntry('OrderId')
  150. status = StringEntry('Status')
  151. create_order_time = IntEntry('CreateOrderTime')
  152. pay_finish_time = IntEntry('PayFinishTime')
  153. desc = StringEntry('Desc')
  154. free_coin_count = StringEntry('FreeCoinCount')
  155. pay_coin_count = StringEntry('PayCoinCount')
  156. refund_free_coin_count = StringEntry('RefundFreeCoinCount')
  157. refund_pay_coin_count = StringEntry('RefundPayCoinCount')
  158. order_type = StringEntry('OrderType')
  159. memo = StringEntry('Memo')
  160. receipt_info = StringEntry('ReceiptInfo')
  161. class SubmitMembercardUserInfoEvent(BaseCardEvent):
  162. __type__ = 'submit_membercard_user_info_event'
  163. class UnknownEvent(WeChatEvent):
  164. __type__ = 'unknown_event'