lib/blsm-mp-wx.rb in blsm-mp-wx-0.2.3 vs lib/blsm-mp-wx.rb in blsm-mp-wx-0.2.4

- old
+ new

@@ -13,14 +13,17 @@ module BlsmMpWx ERROR_CODES = { 404 => {code: 404, msg: '未知的公众号,如有疑问,请联系xi.liu@abcomb.com'} } + class << self attr_accessor :APP_ID attr_accessor :APP_ID_2 + MP_MSG_TYPES = %w(new_order balance score_change distribute custom split_order order todo) #微信公众号消息类型 + #根据app_id获取access_token #系统会根据当前的access_token即过期时间,自动更新并返回 #开发者无需关心这里的access_token怎么更新 #===Parameters # * +app_id+ -公众号的appid @@ -217,18 +220,31 @@ # score_change => content: {touser:'',change:5,total:25,content:'邀请他人。。。。'} def create_msg(app_id=nil, openid, content, msg_name) app_id ||= self.APP_ID return nil unless openid return nil unless content[:touser]==openid - return nil unless %w(new_order balance score_change distribute custom split_order order todo).include?(msg_name) + return nil unless MP_MSG_TYPES.include?(msg_name) VdMpMsg.create({ app_id: app_id, openid: openid, content: content.to_json, msg_name: msg_name, - template_msg: %w(new_order balance score_change distribute split_order order todo).include?(msg_name), + template_msg: MP_MSG_TYPES.include?(msg_name), status: 'none' }) + end + + + def create_msg!(app_id=nil, openid, content, msg_name) + app_id ||= self.APP_ID + VdMpMsg.create!({ + app_id: app_id, + openid: openid, + content: content.to_json, + msg_name: msg_name, + template_msg: MP_MSG_TYPES.include?(msg_name), + status: 'none' + }) end #批量获取公众号的素材列表 #=====Parameters # * +app_id+