eric_weixin 0.0.7 → 0.0.8

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -13,9 +13,6 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
13
13
  options = get_arguments_options options, [:weixin_public_account_id, :key_word, :reply_message, :key_word_type, :order, :reply_type], is_valid: true
14
14
  ::EricWeixin::ReplyMessageRule.transaction do
15
15
  reply_message_rule = ::EricWeixin::ReplyMessageRule.new options
16
- public_account = ::EricWeixin::PublicAccount.find(options[:weixin_public_account_id])
17
- reply_message_rule.weixin_app_id = public_account.weixin_app_id
18
- reply_message_rule.weixin_secret_key = public_account.weixin_secret_key
19
16
  reply_message_rule.save!
20
17
  reply_message_rule
21
18
  end
@@ -26,34 +23,31 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
26
23
  EricWeixin::ReplyMessageRule.transaction do
27
24
  rule = EricWeixin::ReplyMessageRule.find(rule_id)
28
25
  rule.update_attributes(options)
29
- public_account = ::EricWeixin::PublicAccount.find(options[:weixin_public_account_id])
30
- rule.weixin_app_id = public_account.weixin_app_id
31
- rule.weixin_secret_key = public_account.weixin_secret_key
32
26
  rule.save!
33
27
  rule
34
28
  end
35
29
  end
36
30
 
37
- def process_rule(receive_message, secret_key)
31
+ def process_rule(receive_message, public_account)
38
32
  business_type = "#{receive_message[:MsgType]}~#{receive_message[:Event]}"
39
-
40
- pa = EricWeixin::PublicAccount.find_by_weixin_number receive_message[:ToUserName]
33
+ pa = ::EricWeixin::PublicAccount.find_by_weixin_number receive_message[:ToUserName]
41
34
  log = ::EricWeixin::MessageLog.create_public_account_receive_message_log openid: receive_message[:FromUserName],
42
- app_id: pa.weixin_app_id,
43
- message_type: receive_message[:MsgType],
44
- message_id: receive_message[:MsgId],
45
- data: receive_message.to_json,
46
- process_status: 0, #在这里假设都处理完毕,由业务引起的更新请在工程的Process中进行修改。
47
- event_name: receive_message[:Event],
48
- create_time: receive_message[:CreateTime]
35
+ weixin_public_account_id: pa.id,
36
+ message_type: receive_message[:MsgType],
37
+ message_id: receive_message[:MsgId],
38
+ data: receive_message.to_json,
39
+ process_status: 0, #在这里假设都处理完毕,由业务引起的更新请在工程的Process中进行修改。
40
+ event_name: receive_message[:Event],
41
+ event_key: receive_message[:EventKey], #事件值
42
+ create_time: receive_message[:CreateTime]
49
43
 
50
44
  reply_message = case business_type
51
45
  #订阅
52
46
  when /event~subscribe/
53
47
  result = ::Weixin::Process.subscribe receive_message
54
48
  if result == true
55
- ::EricWeixin::WeixinUser.create_weixin_user secret_key, receive_message[:FromUserName]
56
- match_key_words 'subscribe', secret_key, receive_message
49
+ ::EricWeixin::WeixinUser.create_weixin_user public_account.id, receive_message[:FromUserName],receive_message[:EventKey]
50
+ match_key_words 'subscribe', public_account.id, receive_message
57
51
  else
58
52
  result
59
53
  end
@@ -62,8 +56,8 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
62
56
  when /event~unsubscribe/
63
57
  result = ::Weixin::Process.unsubscribe receive_message
64
58
  if result == true
65
- ::EricWeixin::WeixinUser.create_weixin_user secret_key, receive_message[:FromUserName]
66
- match_key_words 'unsubscribe', secret_key, receive_message
59
+ ::EricWeixin::WeixinUser.create_weixin_user public_account.id, receive_message[:FromUserName]
60
+ ''
67
61
  else
68
62
  result
69
63
  end
@@ -72,7 +66,16 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
72
66
  when /event~CLICK/
73
67
  result = ::Weixin::Process.click_event receive_message[:EventKey], receive_message
74
68
  if result == true
75
- match_key_words receive_message[:EventKey], secret_key, receive_message
69
+ match_key_words receive_message[:EventKey], public_account.id, receive_message
70
+ else
71
+ result
72
+ end
73
+
74
+ #点击消息
75
+ when /event~SCAN/
76
+ result = ::Weixin::Process.scan_event receive_message[:EventKey], receive_message
77
+ if result == true
78
+ match_key_words "scan_#{receive_message[:EventKey]}", public_account.id, receive_message, false
76
79
  else
77
80
  result
78
81
  end
@@ -86,7 +89,16 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
86
89
  result
87
90
  end
88
91
 
89
- #用户上报地理位置
92
+ #用户自动上报地理位置信息
93
+ when /event~LOCATION/
94
+ result = ::Weixin::Process.auto_location_event receive_message
95
+ if result == true
96
+ ''
97
+ else
98
+ result
99
+ end
100
+
101
+ #用户共享地理位置信息
90
102
  when /location/
91
103
  result = ::Weixin::Process.location_event receive_message
92
104
  if result == true
@@ -105,7 +117,7 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
105
117
  when /text~/
106
118
  result = ::Weixin::Process.text_event receive_message[:Content], receive_message
107
119
  if result == true
108
- match_key_words receive_message[:Content], secret_key, receive_message
120
+ match_key_words receive_message[:Content], public_account.id, receive_message
109
121
  else
110
122
  result
111
123
  end
@@ -114,24 +126,32 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
114
126
  else
115
127
  result = ::Weixin::Process.another_event receive_message
116
128
  if result == true
117
- match_key_words 'unknow~words', secret_key, receive_message
129
+ match_key_words 'unknow~words', public_account.id, receive_message
118
130
  else
119
131
  result
120
132
  end
121
133
  end
122
134
  "message_to_wechat:".to_logger
123
135
  reply_message.to_logger
124
- log.passive_reply_message = reply_message.to_s
125
- log.save!
136
+ unless receive_message.to_s.blank?
137
+ log.passive_reply_message = reply_message.to_s
138
+ log.save!
139
+ end
140
+
126
141
  reply_message
127
142
  end
128
143
 
129
- def match_key_words wx_key_word, secret_key, receive_message
144
+ def match_key_words wx_key_word, public_account_id, receive_message,need_to_mult_service=true
130
145
  matched_rule = EricWeixin::ReplyMessageRule.order(order: :desc).
131
- where(:key_word => wx_key_word, :weixin_secret_key => secret_key).first
146
+ where(:key_word => wx_key_word, :weixin_public_account_id => public_account_id, :key_word_type=>(receive_message[:MsgType]||"keyword")).first
132
147
  if matched_rule.nil?
133
- return EricWeixin::ReplyMessage::transfer_mult_customer_service ToUserName: receive_message[:FromUserName],
134
- FromUserName: receive_message[:ToUserName]
148
+ if need_to_mult_service
149
+ return EricWeixin::ReplyMessage::transfer_mult_customer_service ToUserName: receive_message[:FromUserName],
150
+ FromUserName: receive_message[:ToUserName]
151
+ else
152
+ return '' #当匹配不上,也不需要去多客服的时候,就直接返回。
153
+ end
154
+
135
155
  end
136
156
  reply_msg = case matched_rule.reply_type
137
157
  when "text"
@@ -144,7 +164,7 @@ class EricWeixin::ReplyMessageRule < ActiveRecord::Base
144
164
  FromUserName: receive_message[:ToUserName],
145
165
  news: weixin_news.weixin_articles
146
166
  when "wx_function"
147
- Weixin::WeixinAutoReplyFunctions.send(matched_rule.reply_message, {:key_word => wx_key_word, :receive_message => receive_message})
167
+ ::Weixin::WeixinAutoReplyFunctions.send(matched_rule.reply_message, ({:key_word => wx_key_word, :receive_message => receive_message}))
148
168
  end
149
169
  reply_msg
150
170
  end
@@ -13,6 +13,7 @@ class EricWeixin::TemplateMessageLog < ActiveRecord::Base
13
13
  # template_id: "WdYZPTwhAMc59aKGs5SUCxRw9xqOM-eOkvGJlZpQahk",
14
14
  # topcolor: '#00FF00',
15
15
  # url: 'www.baidu.com',
16
+ # public_account_id: 1,
16
17
  # data: {
17
18
  # first: {value: 'xx'},
18
19
  # keyword1: {value: '王小明'},
@@ -21,8 +22,8 @@ class EricWeixin::TemplateMessageLog < ActiveRecord::Base
21
22
  # keyword4: {value: '小明同学今天上课表现很别棒,很认真。手工都自己做的,依恋家长比较严重。'},
22
23
  # keyword5: {value: '总体来讲还很不错,心理上缺乏安全感,需要家长多陪同。'},
23
24
  # remark: {value: ''}
24
- # },
25
- # app_id: "wx4564afc37fac0ebf"
25
+ # }
26
+
26
27
  def send_template_message options
27
28
  BusinessException.raise '没有接收对象' if options[:openid].blank?
28
29
  BusinessException.raise '模板未指定' if options[:template_id].blank?
@@ -35,9 +36,16 @@ class EricWeixin::TemplateMessageLog < ActiveRecord::Base
35
36
  :topcolor => options[:topcolor],
36
37
  :data => options[:data]
37
38
  }.to_json
38
- token = EricWeixin::AccessToken.get_valid_access_token(:weixin_secret_key => EricWeixin::PublicAccount.get_secret(options[:app_id]))
39
+
40
+ #todo 在日志表中补充模板信息
41
+
42
+ public_account = ::EricWeixin::PublicAccount.find_by_id options[:public_account_id]
43
+ token = EricWeixin::AccessToken.get_valid_access_token_by_app_id app_id: public_account.weixin_app_id
44
+
45
+
39
46
  response = RestClient.post "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=#{token}", message_json
40
47
  response = JSON.parse response.body
48
+ pp response
41
49
  log = EricWeixin::TemplateMessageLog.new openid: options[:openid],
42
50
  url: options[:url],
43
51
  template_id: options[:template_id],
@@ -45,7 +53,7 @@ class EricWeixin::TemplateMessageLog < ActiveRecord::Base
45
53
  data: options[:data].to_json,
46
54
  message_id: response["msgid"],
47
55
  error_code: response["errcode"],
48
- app_id: options[:app_id]
56
+ weixin_public_account_id: options[:public_account_id]
49
57
  log.save!
50
58
  end
51
59
 
@@ -0,0 +1,146 @@
1
+ class EricWeixin::TwoDimensionCode < ActiveRecord::Base
2
+ self.table_name = "weixin_two_dimension_codes"
3
+ validates_uniqueness_of :scene_str, :allow_blank => true, :message => "永久二维码健值重复", if: Proc.new { |code| code.action_name == 'QR_LIMIT_STR_SCENE' }
4
+ validates_presence_of :scene_str, message: '永久二维码健值不能为空。', if: Proc.new { |code| code.action_name == 'QR_LIMIT_STR_SCENE' }
5
+ validate :check_scene_str_length
6
+
7
+ def check_scene_str_length
8
+ return if self.scene_str.blank?
9
+ BusinessException.raise '永久性二维码场景值不能超过64位' if self.scene_str.length > 64
10
+ end
11
+
12
+ def encode_ticket
13
+ CGI::escape(self.ticket)
14
+ end
15
+
16
+ def image_url
17
+ "https://mp.weixin.qq.com/cgi-bin/showqrcode?ticket=#{self.encode_ticket}"
18
+ end
19
+
20
+ # 获取永久性二维码对象。
21
+ # 典型使用场景如下:
22
+ # 1.第一步调用此方法先创建/获取二维码对象。
23
+ # 2.使用二维码对象获取二维码下载、展示链接。 如:two_dimension_code.image_url
24
+ # 3.尽情享受带参数的永久二维码吧,很简单,有木有?
25
+ # ===参数描述:
26
+ # * app_id 微信app_id
27
+ # * scene_str 场景值,字符串长度不能超过64位,亦不能为空。
28
+ # * action_info 场景值描述(可选)
29
+ # 调用示例:
30
+ # EricWeixin::TwoDimensionCode.get_long_time_two_dimension_code app_id: 'wx51729870d9012531', scene_str: 'abc', action_info: 'hello'
31
+ # EricWeixin::TwoDimensionCode.get_long_time_two_dimension_code app_id: 'wx51729870d9012531', scene_str: 'bus'
32
+ def self.get_long_time_two_dimension_code options
33
+ BusinessException.raise '场景值不能为空' if options[:scene_str].blank?
34
+ BusinessException.raise '场景值不能超过64字符' if options[:scene_str].length > 63
35
+ EricWeixin::TwoDimensionCode.transaction do
36
+ public_account = EricWeixin::PublicAccount.find_by_weixin_app_id options[:app_id]
37
+ BusinessException.raise 'app_id不存在' if public_account.blank?
38
+ codes = public_account.two_dimension_codes.where scene_str: options[:scene_str],
39
+ action_name: "QR_LIMIT_STR_SCENE"
40
+ code = if codes.blank?
41
+ code = EricWeixin::TwoDimensionCode.new weixin_public_account_id: public_account.id,
42
+ action_name: "QR_LIMIT_STR_SCENE",
43
+ action_info: options[:action_info],
44
+ scene_str: options[:scene_str],
45
+ expire_at: Time.now.chinese_format +
46
+ code.save!
47
+ code
48
+ else
49
+ codes[0]
50
+ end
51
+ if not code.ticket.blank?
52
+ return code #永久性二维码,不需要再次进行更新。
53
+ end
54
+ token = ::EricWeixin::AccessToken.get_valid_access_token_by_app_id app_id: options[:app_id]
55
+ url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=#{token}"
56
+ json = {:action_name => 'QR_LIMIT_STR_SCENE',
57
+ :action_info => {
58
+ :scene => {
59
+ :scene_str => options[:scene_str]
60
+ }
61
+ }}.to_json
62
+ response = RestClient.post url, json
63
+ response = JSON.parse response.body
64
+ pp response
65
+ code.ticket = response["ticket"]
66
+ code.url = response["url"]
67
+ code.save!
68
+ code
69
+ end
70
+ end
71
+
72
+
73
+ # 获取临时二维码对象。
74
+ # 典型使用场景如下:
75
+ # 1.第一步调用此方法先创建/获取二维码对象。
76
+ # 2.使用二维码对象获取二维码下载、展示链接。 如:two_dimension_code.image_url
77
+ # 3.尽情享受带参数的永久二维码吧,很简单,有木有?
78
+ # ===参数描述:
79
+ # * app_id 微信app_id
80
+ # * scene_id 场景值,应该是一个数字
81
+ # * expire_seconds 过期时间,默认为604800秒,可选
82
+ # 调用示例:
83
+ # EricWeixin::TwoDimensionCode.get_short_time_two_dimension_code app_id: 'wx51729870d9012531', scene_id: 1, expire_seconds: 3600
84
+ # EricWeixin::TwoDimensionCode.get_short_time_two_dimension_code app_id: 'wx51729870d9012531', scene_id: 2300
85
+ def self.get_short_time_two_dimension_code options
86
+ BusinessException.raise '场景值不能为空' if options[:scene_id].blank?
87
+
88
+ EricWeixin::TwoDimensionCode.transaction do
89
+ public_account = EricWeixin::PublicAccount.find_by_weixin_app_id options[:app_id]
90
+ BusinessException.raise 'app_id不存在' if public_account.blank?
91
+ codes = public_account.two_dimension_codes.where ["scene_id = ? and action_name = ? and expire_at > ?",
92
+ options[:scene_id],
93
+ "QR_SCENE",
94
+ Time.now.chinese_format
95
+ ]
96
+
97
+ code = if codes.blank?
98
+ code = EricWeixin::TwoDimensionCode.new weixin_public_account_id: public_account.id,
99
+ action_name: "QR_SCENE",
100
+ scene_id: options[:scene_id],
101
+ expire_at: (Time.now + (options[:expire_seconds]||604800).to_i)
102
+ code.save!
103
+ code
104
+ else
105
+ codes[0]
106
+ end
107
+ if not code.ticket.blank?
108
+ return code #永久性二维码,不需要再次进行更新。
109
+ end
110
+ token = ::EricWeixin::AccessToken.get_valid_access_token_by_app_id app_id: options[:app_id]
111
+ url = "https://api.weixin.qq.com/cgi-bin/qrcode/create?access_token=#{token}"
112
+ json = {:action_name => 'QR_SCENE',
113
+ :expire_seconds => (options[:expire_seconds]||604800).to_i,
114
+ :action_info => {
115
+ :scene => {
116
+ :scene_id => options[:scene_id]
117
+ }
118
+ }}.to_json
119
+ response = RestClient.post url, json
120
+ response = JSON.parse response.body
121
+ pp response
122
+ code.ticket = response["ticket"]
123
+ code.url = response["url"]
124
+ code.expire_at = Time.now + (options[:expire_seconds]||604800).to_i
125
+ code.save!
126
+ code
127
+ end
128
+ end
129
+
130
+ # 长URL转短URL
131
+ # ===参数说明:
132
+ # * app_id 微信公众账号的app_id
133
+ # * url 需要转短url的链接
134
+ # ===调用示例:
135
+ # EricWeixin::TwoDimensionCode.short_url app_id: 'wx51729870d9012531', url: 'http://mp.weixin.qq.com/wiki/10/165c9b15eddcfbd8699ac12b0bd89ae6.html'
136
+ def self.short_url options
137
+ access_token = EricWeixin::AccessToken.get_valid_access_token_by_app_id app_id: options[:app_id]
138
+ url = "https://api.weixin.qq.com/cgi-bin/shorturl?access_token=#{access_token}"
139
+ response = RestClient.post url, {action: "long2short", long_url: options[:url]}.to_json
140
+ response = JSON.parse(response.body)
141
+ response["short_url"]
142
+ end
143
+
144
+ end
145
+
146
+ # EricWeixin::TwoDimensionCode.get_long_time_two_dimension_code app_id: 'wx51729870d9012531', scene_str: 'abc', action_info: 'hello'
@@ -2,8 +2,8 @@ class EricWeixin::WeixinUser < ActiveRecord::Base
2
2
  SEX = {1=>'男' , 2=>'女', 0=>'未知'}
3
3
  belongs_to :member_info
4
4
  belongs_to :weixin_public_account, :class_name => '::EricWeixin::PublicAccount', :foreign_key => 'weixin_public_account_id'
5
- validates_uniqueness_of :openid, scope: :weixin_secret_key
6
- validates_presence_of :openid, :weixin_secret_key, :weixin_public_account
5
+ validates_uniqueness_of :openid, scope: :weixin_public_account_id
6
+ validates_presence_of :openid, :weixin_public_account_id
7
7
 
8
8
 
9
9
  def nickname
@@ -18,39 +18,42 @@ class EricWeixin::WeixinUser < ActiveRecord::Base
18
18
 
19
19
  class << self
20
20
 
21
- ##
22
21
  # ===业务说明:创建、更新微信用户
23
22
  # * 微信用户在关注、取消关注时更新用户信息。
24
23
  # * 当用户关注微信时,创建用户。
25
24
  # * 当用户取消关注时,把用户标记为取消关注
26
25
  # ===参数说明
27
- # * secret_key::公众账号的secret_key,其值取决于公众账号的设置。
26
+ # * public_account_id::公众账号的数据库存储id
28
27
  # * openid::用户的openid,微信服务器传送过来。
29
28
  # ===调用方法
30
29
  # EricWeixin::WeixinUser.create_weixin_user 'adsfkj', 'sdfdf'
31
30
  # EricWeixin::WeixinUser.create_weixin_user 'adsfkj', 'sdfdf'
32
31
  # ====返回
33
32
  # 正常情况下返回当前微信用户 <tt>::EricWeixin::WeixinUser</tt>,抛出异常时错误查看异常信息。
34
- def create_weixin_user(secret_key, openid)
35
- public_account = ::EricWeixin::PublicAccount.find_by_weixin_secret_key(secret_key)
33
+ def create_weixin_user(public_account_id, openid, channel=nil)
34
+ public_account = ::EricWeixin::PublicAccount.find_by_id(public_account_id)
36
35
  ::EricWeixin::ReplyMessageRule.transaction do
37
- weixin_user = ::EricWeixin::WeixinUser.where(openid: openid, weixin_secret_key: secret_key).first
36
+ weixin_user = ::EricWeixin::WeixinUser.where(openid: openid, weixin_public_account_id: public_account.id).first
38
37
  if weixin_user.blank?
39
38
  weixin_user = ::EricWeixin::WeixinUser.new openid: openid,
40
- weixin_secret_key: secret_key,
41
39
  weixin_public_account_id: public_account.id
42
40
  weixin_user.save!
43
41
  end
44
42
  wx_user_data = public_account.get_user_data_from_weixin_api openid
45
43
  weixin_user.update_attributes(wx_user_data.select{|k,v| ["subscribe", "openid", "nickname", "sex", "language", "city", "province", "country", "headimgurl", "subscribe_time", "remark"].include? k })
44
+ if not channel.blank?
45
+ weixin_user.first_register_channel = channel if weixin_user.first_register_channel.blank?
46
+ weixin_user.last_register_channel = channel
47
+ weixin_user.save!
48
+ end
46
49
  weixin_user
47
50
  end
48
51
  end
49
52
 
50
53
 
51
- def export_users_to_csv(weixin_secret_key)
54
+ def export_users_to_csv(public_account_id)
52
55
  require 'csv'
53
- weixin_users = ::EricWeixin::WeixinUser.where(weixin_secret_key: weixin_secret_key)
56
+ weixin_users = ::EricWeixin::WeixinUser.where(weixin_public_account_id: public_account_id)
54
57
  CSV.generate do |csv|
55
58
  csv << ["订阅状态", "openid", "昵称", "性别", "语言", "城市", "省份", "国家", "订阅时间"]
56
59
  weixin_users.each do |weixin_user|
@@ -39,11 +39,11 @@ module EricWeixin::MultCustomer
39
39
  response = RestClient.post url, post_data.to_json
40
40
  response = JSON.parse response.body
41
41
  ::EricWeixin::MessageLog.transaction do
42
- message = ::EricWeixin::MessageLog.where(message_id: options[:message_id])
42
+ message = ::EricWeixin::MessageLog.where(message_id: options[:message_id]).first
43
43
  message_id = if message.blank? then
44
44
  nil
45
45
  else
46
- message.first.id
46
+ message.id
47
47
  end
48
48
  ::EricWeixin::MessageLog.create_public_account_send_message_log openid: options[:openid],
49
49
  app_id: options[:app_id],
@@ -10,13 +10,13 @@ module EricWeixin::Snsapi
10
10
  # * schema_host 当前项目的域名(包含http://):如http://www.baidu.com
11
11
  # * state 这个参数可以直接带到业务页面。
12
12
  # ===调用示例
13
- # EricWeixin::Snsapi.get_snsapi_uri url:'/weixin/service1/ddd?a=1', app_id: 'wx4564afc37fac0ebf', schema_host: "http://lxq.mdcc.com"
13
+ # EricWeixin::Snsapi.get_snsapi_base_url url:'/weixin/service1/ddd?a=1', app_id: 'wx51729870d9012531', schema_host: "http://lxq.mdcc.club"
14
14
  def self.get_snsapi_base_url options
15
15
  require 'base64'
16
16
  p_zhongzhuan = []
17
17
  p_zhongzhuan_host_path = "#{options[:schema_host]}/weixin/snsapi"
18
18
  p_zhongzhuan << ["weixin_app_id", options[:app_id]]
19
- p_zhongzhuan << ["url", Base64.encode64(options[:url])]
19
+ p_zhongzhuan << ["url", Base64.encode64(options[:url]).gsub(/\n/,'')]
20
20
  p_zhongzhuan = URI.encode_www_form p_zhongzhuan
21
21
  p_zhongzhuan = CGI::unescape p_zhongzhuan
22
22
  p_zhongzhuan_url = [p_zhongzhuan_host_path, p_zhongzhuan].join('?')
@@ -46,13 +46,13 @@ module EricWeixin::Snsapi
46
46
  # * schema_host 当前项目的域名(包含http://):如http://www.baidu.com
47
47
  # * state 这个参数可以直接带到业务页面。
48
48
  # ===调用示例
49
- # EricWeixin::Snsapi.get_snsapi_userinfo_url url:'/weixin/service1/ddd?a=1', app_id: 'wx4564afc37fac0ebf', schema_host: "http://lxq.mdcc.club"
49
+ # EricWeixin::Snsapi.get_snsapi_userinfo_url url:'/weixin/service1/ddd?a=1', app_id: 'wx51729870d9012531', schema_host: "http://lxq.mdcc.club"
50
50
  def self.get_snsapi_userinfo_url options
51
51
  require 'base64'
52
52
  p_zhongzhuan = []
53
53
  p_zhongzhuan_host_path = "#{options[:schema_host]}/weixin/snsuserinfo"
54
54
  p_zhongzhuan << ["weixin_app_id", options[:app_id]]
55
- p_zhongzhuan << ["url", Base64.encode64(options[:url])]
55
+ p_zhongzhuan << ["url", Base64.encode64(options[:url]).gsub(/\n/,'')]
56
56
  p_zhongzhuan = URI.encode_www_form p_zhongzhuan
57
57
  p_zhongzhuan = CGI::unescape p_zhongzhuan
58
58
  p_zhongzhuan_url = [p_zhongzhuan_host_path, p_zhongzhuan].join('?')