Module: Model::Notice::PublicNotice

Included in:
Wechat::PublicNotice
Defined in:
app/models/wechat/model/notice/public_notice.rb

Constant Summary collapse

BASE =
'https://api.weixin.qq.com/cgi-bin/'

Instance Method Summary collapse

Instance Method Details

#do_sendObject



5
6
7
8
9
10
11
12
13
# File 'app/models/wechat/model/notice/public_notice.rb', line 5

def do_send
  r = app.api.post 'message/template/send', **message_hash, base: BASE
  if r['errcode'] == 0
    self.update msg_id: r['msgid']
    subscribe.update sending_at: Time.now if subscribe
  else
    r
  end
end

#message_hashObject



15
16
17
18
19
20
21
22
# File 'app/models/wechat/model/notice/public_notice.rb', line 15

def message_hash
  {
    touser: wechat_user.uid,
    template_id: template.template_id,
    url: link,
    data: data
  }
end