Class: WeixinPam::PublicAccountReply
- Inherits:
-
Object
- Object
- WeixinPam::PublicAccountReply
- Includes:
- KeyEventMethods, WeixinRailsMiddleware::ReplyWeixinMessageHelper
- Defined in:
- lib/weixin_pam/public_account_reply.rb
Defined Under Namespace
Modules: KeyEventMethods Classes: KeyEventCallback
Constant Summary collapse
- NO_CONTENT =
:no_content
Instance Attribute Summary collapse
-
#keyword ⇒ Object
readonly
Returns the value of attribute keyword.
-
#weixin_message ⇒ Object
readonly
Returns the value of attribute weixin_message.
-
#weixin_public_account ⇒ Object
readonly
Returns the value of attribute weixin_public_account.
-
#weixin_user_account ⇒ Object
readonly
Returns the value of attribute weixin_user_account.
Instance Method Summary collapse
-
#handle_click_event ⇒ Object
点击菜单拉取消息时的事件推送.
-
#handle_location_event ⇒ Object
上报地理位置事件.
-
#handle_masssendjobfinish_event ⇒ Object
<xml> <ToUserName><![CDATA]></ToUserName> <FromUserName><![CDATA]></FromUserName> <CreateTime>1394524295</CreateTime> <MsgType><![CDATA]></MsgType> <Event><![CDATA]></Event> <MsgID>1988</MsgID> <Status><![CDATA]></Status> <TotalCount>100</TotalCount> <FilterCount>80</FilterCount> <SentCount>75</SentCount> <ErrorCount>5</ErrorCount> </xml>.
-
#handle_pic_photo_or_album_event ⇒ Object
弹出拍照或者相册发图的事件推送.
-
#handle_pic_sysphoto_event ⇒ Object
弹出系统拍照发图.
-
#handle_scan_event ⇒ Object
扫描带参数二维码事件: 2.
-
#handle_scancode_push_event ⇒ Object
扫码事件.
-
#handle_subscribe_event ⇒ Object
关注公众账号.
- #handle_templatesendjobfinish_event ⇒ Object
-
#handle_unsubscribe_event ⇒ Object
取消关注.
-
#handle_view_event ⇒ Object
点击菜单跳转链接时的事件推送.
-
#initialize(public_account, message, keyword) ⇒ PublicAccountReply
constructor
A new instance of PublicAccountReply.
- #reply ⇒ Object
- #reply_with_dev_message(msg) ⇒ Object
- #response_event_message ⇒ Object
-
#response_image_message ⇒ Object
<PicUrl><![CDATA[this is a url]]></PicUrl> <MediaId><![CDATA]></MediaId>.
-
#response_link_message ⇒ Object
<Title><![CDATA]></Title> <Description><![CDATA]></Description> <Url><![CDATA]></Url>.
-
#response_location_message ⇒ Object
<Location_X>23.134521</Location_X> <Location_Y>113.358803</Location_Y> <Scale>20</Scale> <Label><![CDATA]></Label>.
-
#response_shortvideo_message ⇒ Object
<MediaId><![CDATA]></MediaId> <ThumbMediaId><![CDATA]></ThumbMediaId>.
- #response_text_message ⇒ Object
-
#response_video_message ⇒ Object
<MediaId><![CDATA]></MediaId> <ThumbMediaId><![CDATA]></ThumbMediaId>.
-
#response_voice_message ⇒ Object
<MediaId><![CDATA]></MediaId> <Format><![CDATA]></Format>.
Methods included from KeyEventMethods
Constructor Details
#initialize(public_account, message, keyword) ⇒ PublicAccountReply
Returns a new instance of PublicAccountReply.
47 48 49 50 51 52 |
# File 'lib/weixin_pam/public_account_reply.rb', line 47 def initialize(public_account, , keyword) @weixin_public_account = public_account @weixin_user_account = public_account.user_accounts.find_or_create_by!(uid: .FromUserName) @weixin_message = @keyword = keyword end |
Instance Attribute Details
#keyword ⇒ Object (readonly)
Returns the value of attribute keyword.
43 44 45 |
# File 'lib/weixin_pam/public_account_reply.rb', line 43 def keyword @keyword end |
#weixin_message ⇒ Object (readonly)
Returns the value of attribute weixin_message.
43 44 45 |
# File 'lib/weixin_pam/public_account_reply.rb', line 43 def @weixin_message end |
#weixin_public_account ⇒ Object (readonly)
Returns the value of attribute weixin_public_account.
43 44 45 |
# File 'lib/weixin_pam/public_account_reply.rb', line 43 def weixin_public_account @weixin_public_account end |
#weixin_user_account ⇒ Object (readonly)
Returns the value of attribute weixin_user_account.
43 44 45 |
# File 'lib/weixin_pam/public_account_reply.rb', line 43 def weixin_user_account @weixin_user_account end |
Instance Method Details
#handle_click_event ⇒ Object
点击菜单拉取消息时的事件推送
159 160 161 162 163 164 165 166 |
# File 'lib/weixin_pam/public_account_reply.rb', line 159 def handle_click_event key_event = find_key_event(@keyword) if key_event key_event.execute(self) else (("你点击了: #{@keyword}")) end end |
#handle_location_event ⇒ Object
上报地理位置事件
151 152 153 154 155 156 |
# File 'lib/weixin_pam/public_account_reply.rb', line 151 def handle_location_event # 上报地理位置事件 @lat = @weixin_message.Latitude @lgt = @weixin_message.Longitude @precision = @weixin_message.Precision (("Your Location: #{@lat}, #{@lgt}, #{@precision}")) end |
#handle_masssendjobfinish_event ⇒ Object
<xml> <ToUserName><![CDATA]></ToUserName> <FromUserName><![CDATA]></FromUserName> <CreateTime>1394524295</CreateTime> <MsgType><![CDATA]></MsgType> <Event><![CDATA]></Event> <MsgID>1988</MsgID> <Status><![CDATA]></Status> <TotalCount>100</TotalCount> <FilterCount>80</FilterCount> <SentCount>75</SentCount> <ErrorCount>5</ErrorCount> </xml>
208 209 210 211 |
# File 'lib/weixin_pam/public_account_reply.rb', line 208 def handle_masssendjobfinish_event Rails.logger.info("回调事件处理") NO_CONTENT end |
#handle_pic_photo_or_album_event ⇒ Object
弹出拍照或者相册发图的事件推送
180 181 182 |
# File 'lib/weixin_pam/public_account_reply.rb', line 180 def handle_pic_photo_or_album_event NO_CONTENT end |
#handle_pic_sysphoto_event ⇒ Object
弹出系统拍照发图
175 176 177 |
# File 'lib/weixin_pam/public_account_reply.rb', line 175 def handle_pic_sysphoto_event NO_CONTENT end |
#handle_scan_event ⇒ Object
扫描带参数二维码事件: 2. 用户已关注时的事件推送
147 148 149 |
# File 'lib/weixin_pam/public_account_reply.rb', line 147 def handle_scan_event (("扫描带参数二维码事件: 2. 用户已关注时的事件推送, keyword: #{@keyword}")) end |
#handle_scancode_push_event ⇒ Object
扫码事件
185 186 187 |
# File 'lib/weixin_pam/public_account_reply.rb', line 185 def handle_scancode_push_event NO_CONTENT end |
#handle_subscribe_event ⇒ Object
关注公众账号
132 133 134 135 136 137 138 |
# File 'lib/weixin_pam/public_account_reply.rb', line 132 def handle_subscribe_event if @keyword.present? # 扫描带参数二维码事件: 1. 用户未关注时,进行关注后的事件推送 return (("扫描带参数二维码事件: 1. 用户未关注时,进行关注后的事件推送, keyword: #{@keyword}")) end (("关注公众账号")) end |
#handle_templatesendjobfinish_event ⇒ Object
213 214 215 216 |
# File 'lib/weixin_pam/public_account_reply.rb', line 213 def handle_templatesendjobfinish_event Rails.logger.info("回调模板任务") NO_CONTENT end |
#handle_unsubscribe_event ⇒ Object
取消关注
141 142 143 144 |
# File 'lib/weixin_pam/public_account_reply.rb', line 141 def handle_unsubscribe_event Rails.logger.info("取消关注") NO_CONTENT end |
#handle_view_event ⇒ Object
点击菜单跳转链接时的事件推送
169 170 171 172 |
# File 'lib/weixin_pam/public_account_reply.rb', line 169 def handle_view_event Rails.logger.info("你点击了: #{@keyword}") NO_CONTENT end |
#reply ⇒ Object
54 55 56 |
# File 'lib/weixin_pam/public_account_reply.rb', line 54 def reply send("response_#{@weixin_message.MsgType}_message") end |
#reply_with_dev_message(msg) ⇒ Object
218 219 220 |
# File 'lib/weixin_pam/public_account_reply.rb', line 218 def (msg) Rails.env.development? ? msg : NO_CONTENT end |
#response_event_message ⇒ Object
120 121 122 123 124 125 126 127 128 129 |
# File 'lib/weixin_pam/public_account_reply.rb', line 120 def event_type = @weixin_message.Event case event_type.downcase when 'unsubscribe' @weixin_public_account.user_accounts.where(uid: @weixin_message.FromUserName).limit(1).update_all(subscribed: false) when 'subscribe' @weixin_public_account.user_accounts.where(uid: @weixin_message.FromUserName).limit(1).update_all(subscribed: true) end send("handle_#{event_type.downcase}_event") end |
#response_image_message ⇒ Object
<PicUrl><![CDATA[this is a url]]></PicUrl> <MediaId><![CDATA]></MediaId>
76 77 78 79 80 |
# File 'lib/weixin_pam/public_account_reply.rb', line 76 def @media_id = @weixin_message.MediaId # 可以调用多媒体文件下载接口拉取数据。 @pic_url = @weixin_message.PicUrl # 也可以直接通过此链接下载图片, 建议使用carrierwave. (generate_image(@media_id)) end |
#response_link_message ⇒ Object
<Title><![CDATA]></Title> <Description><![CDATA]></Description> <Url><![CDATA]></Url>
85 86 87 88 89 90 |
# File 'lib/weixin_pam/public_account_reply.rb', line 85 def @title = @weixin_message.Title @desc = @weixin_message.Description @url = @weixin_message.Url (("回复链接信息")) end |
#response_location_message ⇒ Object
<Location_X>23.134521</Location_X> <Location_Y>113.358803</Location_Y> <Scale>20</Scale> <Label><![CDATA]></Label>
66 67 68 69 70 71 72 |
# File 'lib/weixin_pam/public_account_reply.rb', line 66 def @lx = @weixin_message.Location_X @ly = @weixin_message.Location_Y @scale = @weixin_message.Scale @label = @weixin_message.Label (("Your Location: #{@lx}, #{@ly}, #{@scale}, #{@label}")) end |
#response_shortvideo_message ⇒ Object
<MediaId><![CDATA]></MediaId> <ThumbMediaId><![CDATA]></ThumbMediaId>
113 114 115 116 117 118 |
# File 'lib/weixin_pam/public_account_reply.rb', line 113 def @media_id = @weixin_message.MediaId # 可以调用多媒体文件下载接口拉取数据。 # 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。 @thumb_media_id = @weixin_message.ThumbMediaId (("回复短视频信息")) end |
#response_text_message ⇒ Object
58 59 60 |
# File 'lib/weixin_pam/public_account_reply.rb', line 58 def (("Your Message: #{@keyword}")) end |
#response_video_message ⇒ Object
<MediaId><![CDATA]></MediaId> <ThumbMediaId><![CDATA]></ThumbMediaId>
104 105 106 107 108 109 |
# File 'lib/weixin_pam/public_account_reply.rb', line 104 def @media_id = @weixin_message.MediaId # 可以调用多媒体文件下载接口拉取数据。 # 视频消息缩略图的媒体id,可以调用多媒体文件下载接口拉取数据。 @thumb_media_id = @weixin_message.ThumbMediaId (("回复视频信息")) end |
#response_voice_message ⇒ Object
<MediaId><![CDATA]></MediaId> <Format><![CDATA]></Format>
94 95 96 97 98 99 100 |
# File 'lib/weixin_pam/public_account_reply.rb', line 94 def @media_id = @weixin_message.MediaId # 可以调用多媒体文件下载接口拉取数据。 @format = @weixin_message.Format # 如果开启了语音翻译功能,@keyword则为翻译的结果 # reply_text_message("回复语音信息: #{@keyword}") (generate_voice(@media_id)) end |