Class: WeixinPam::PublicAccount
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- WeixinPam::PublicAccount
- Includes:
- WeixinRailsMiddleware::AutoGenerateWeixinTokenSecretKey
- Defined in:
- app/models/weixin_pam/public_account.rb
Instance Method Summary collapse
- #build_menu ⇒ Object
- #client ⇒ Object
- #download_menu! ⇒ Object
- #reply_weixin(message, keyword) ⇒ Object
- #temp_qrcode(sence_id = 1) ⇒ Object
- #upload_menu ⇒ Object
Instance Method Details
#build_menu ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 |
# File 'app/models/weixin_pam/public_account.rb', line 21 def Jbuilder.encode do |json| json.() do || json.name .name if . json.(.) do || json.type . json.name .name .(json) end else json.type . .(json) end end end end |
#client ⇒ Object
12 13 14 |
# File 'app/models/weixin_pam/public_account.rb', line 12 def client @client ||= WeixinAuthorize::Client.new(app_id, app_secret) end |
#download_menu! ⇒ Object
43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
# File 'app/models/weixin_pam/public_account.rb', line 43 def ret = client. fail ApiError::FailedResult.new(ret, '下载公众号菜单失败') unless ret.ok? # Reset menu .where(parent: nil).update_all(is_show: false) data = ret.result return unless data.key?('menu') && data['menu'].key?('button') i = 0 data['menu']['button'].each do || i += 1 = .delete('sub_button') ['button_type'] = ::[.delete('type')] = .find_or_initialize_by() .parent = nil .is_show = true .sort = i .save! if .changed? ..update_all(parent_id: nil, is_show: false) j = 0 .each do || j += 1 .delete('sub_button') ['button_type'] = ::[.delete('type')] = .find_or_initialize_by() .parent = .is_show = true .sort = j .save! if .changed? end end end |
#reply_weixin(message, keyword) ⇒ Object
16 17 18 19 |
# File 'app/models/weixin_pam/public_account.rb', line 16 def reply_weixin(, keyword) klass = reply_class.present? ? reply_class.constantize : PublicAccountReply klass.new(self, , keyword).reply end |
#temp_qrcode(sence_id = 1) ⇒ Object
77 78 79 |
# File 'app/models/weixin_pam/public_account.rb', line 77 def temp_qrcode(sence_id = 1) client.qr_code_url(client.create_qr_scene(sence_id).result['ticket']) end |
#upload_menu ⇒ Object
39 40 41 |
# File 'app/models/weixin_pam/public_account.rb', line 39 def client.() end |