blsm-mp-wx 0.1.1 → 0.1.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +8 -8
- data/Gemfile.lock +1 -1
- data/bin/console +1 -1
- data/blsm-mp-wx.gemspec +1 -1
- data/lib/blsm-mp-wx/model/active_record.rb +10 -0
- data/lib/{blsm_mp_wx → blsm-mp-wx}/version.rb +1 -1
- data/lib/{blsm_mp_wx.rb → blsm-mp-wx.rb} +41 -13
- metadata +5 -6
- data/lib/blsm_mp_wx/db_config.rb +0 -4
- data/lib/blsm_mp_wx/model/active_record.rb +0 -10
- /data/lib/{blsm_mp_wx → blsm-mp-wx}/model/vd_mp_wx.rb +0 -0
checksums.yaml
CHANGED
@@ -1,15 +1,15 @@
|
|
1
1
|
---
|
2
2
|
!binary "U0hBMQ==":
|
3
3
|
metadata.gz: !binary |-
|
4
|
-
|
4
|
+
YmRjNmMzOTQxNzc3NzczY2ZjZWQ1MmY2MDc0ODVhMWRiNjU5Y2Q2NQ==
|
5
5
|
data.tar.gz: !binary |-
|
6
|
-
|
6
|
+
YzM0MmRlNTcyZTYzNzI5NGNkYmU5YzNiZmIyNzU2NjE2YTBlYWNiMQ==
|
7
7
|
SHA512:
|
8
8
|
metadata.gz: !binary |-
|
9
|
-
|
10
|
-
|
11
|
-
|
9
|
+
M2ZmMzE3MTM2Nzc2MzBjNmFlZjk1MzdlNjQ2NjhiNjRjZWE1MjI5MzEwMjA1
|
10
|
+
OTAyODBlMGZjZmM5MzljMzYzNDI3MGE5YjY5NjUwYWE3ZWU3M2I0NWY1Y2Zj
|
11
|
+
MmU4MWJiY2ViMWE4NGNhYzY1MmY5OTQ2YzIzYjUwMTBlNTIwODg=
|
12
12
|
data.tar.gz: !binary |-
|
13
|
-
|
14
|
-
|
15
|
-
|
13
|
+
N2FlZmQxNDlkYjA2OWJmZmY0M2NkYWY2MjRmYTY3OWNjNDg3M2M1MThiZWE3
|
14
|
+
ZmY3Mzg0M2I0ODUwNDY0NjQ5ZWI1ZjhiOWIwN2Y0MmMzYjk4NzVjNzE0M2Q0
|
15
|
+
ZTYyNDFiMjgxOGIzY2VkYjE4ZTQ5NTRjOGI5ZmNkNWM2MjdjZGI=
|
data/Gemfile.lock
CHANGED
data/bin/console
CHANGED
data/blsm-mp-wx.gemspec
CHANGED
@@ -0,0 +1,10 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
module BlsmMpWx
|
3
|
+
|
4
|
+
class BaseRecord < ActiveRecord::Base
|
5
|
+
self.configurations = YAML::load(ERB.new(File.open(Rails.root ? File.join(Rails.root, "config", "database.yml") : './config/database.yml').inject('') { |text, line| text+line }).result)
|
6
|
+
establish_connection Rails::env.to_s.to_sym
|
7
|
+
self.table_name='vd_mp_wxes'
|
8
|
+
end
|
9
|
+
|
10
|
+
end
|
@@ -4,10 +4,9 @@ require 'rails'
|
|
4
4
|
require 'active_model'
|
5
5
|
require 'active_record'
|
6
6
|
require 'active_support'
|
7
|
-
require '
|
8
|
-
require '
|
9
|
-
require '
|
10
|
-
require 'blsm_mp_wx/model/vd_mp_wx'
|
7
|
+
require 'blsm-mp-wx/version'
|
8
|
+
require 'blsm-mp-wx/model/active_record'
|
9
|
+
require 'blsm-mp-wx/model/vd_mp_wx'
|
11
10
|
require 'json'
|
12
11
|
require 'faraday'
|
13
12
|
|
@@ -16,15 +15,16 @@ module BlsmMpWx
|
|
16
15
|
404 => {code: 404, msg: '未知的公众号,如有疑问,请联系xi.liu@abcomb.com'}
|
17
16
|
}
|
18
17
|
class << self
|
19
|
-
attr_accessor :
|
20
|
-
attr_accessor :
|
18
|
+
attr_accessor :APP_ID
|
19
|
+
attr_accessor :APP_ID_2
|
21
20
|
|
22
21
|
#根据app_id获取access_token
|
23
22
|
#系统会根据当前的access_token即过期时间,自动更新并返回
|
24
23
|
#开发者无需关心这里的access_token怎么更新
|
25
24
|
#===Parameters
|
26
25
|
# * +app_id+ -公众号的appid
|
27
|
-
def access_token(app_id)
|
26
|
+
def access_token(app_id=nil)
|
27
|
+
app_id ||= self.APP_ID
|
28
28
|
app = VdMpWx.where(app_id: app_id).first
|
29
29
|
return nil unless app
|
30
30
|
return app.access_token unless app.access_token_expired? #没有过期,直接返回
|
@@ -47,8 +47,8 @@ module BlsmMpWx
|
|
47
47
|
end
|
48
48
|
|
49
49
|
#获取jsapi全局唯一票据
|
50
|
-
def js_api_ticket(app_id)
|
51
|
-
|
50
|
+
def js_api_ticket(app_id=nil)
|
51
|
+
app_id ||= self.APP_ID
|
52
52
|
access_token = access_token(app_id)
|
53
53
|
app = VdMpWx.where(app_id: app_id).first
|
54
54
|
|
@@ -104,7 +104,8 @@ module BlsmMpWx
|
|
104
104
|
# ]
|
105
105
|
# }
|
106
106
|
# }
|
107
|
-
def send_msg(app_id, openid, msg)
|
107
|
+
def send_msg(app_id=nil, openid, msg)
|
108
|
+
app_id ||= self.APP_ID
|
108
109
|
access_token = access_token(app_id)
|
109
110
|
return nil unless access_token
|
110
111
|
return nil unless openid
|
@@ -124,7 +125,8 @@ module BlsmMpWx
|
|
124
125
|
end
|
125
126
|
|
126
127
|
#JSAPI签名package
|
127
|
-
def js_api_sign_package(app_id, url)
|
128
|
+
def js_api_sign_package(app_id=nil, url)
|
129
|
+
app_id ||= self.APP_ID
|
128
130
|
ticket = js_api_ticket(app_id)
|
129
131
|
timestamp = Time.new.to_i
|
130
132
|
nonce_str = Digest::MD5.hexdigest(Time.new.to_i.to_s + Random.rand(99999).to_s)
|
@@ -142,7 +144,8 @@ module BlsmMpWx
|
|
142
144
|
|
143
145
|
|
144
146
|
#获取用户的基本信息(包括UnionID机制)
|
145
|
-
def gen_wx_user_info(app_id, openid)
|
147
|
+
def gen_wx_user_info(app_id=nil, openid)
|
148
|
+
app_id ||= self.APP_ID
|
146
149
|
access_token = access_token(app_id)
|
147
150
|
return nil unless access_token
|
148
151
|
|
@@ -161,7 +164,8 @@ module BlsmMpWx
|
|
161
164
|
end
|
162
165
|
|
163
166
|
#生成永久二维码ticket
|
164
|
-
def gen_forever_qr_ticket(app_id, scene_id)
|
167
|
+
def gen_forever_qr_ticket(app_id=nil, scene_id)
|
168
|
+
app_id ||= self.APP_ID
|
165
169
|
access_token = access_token(app_id)
|
166
170
|
return nil unless access_token
|
167
171
|
|
@@ -178,6 +182,30 @@ module BlsmMpWx
|
|
178
182
|
json_obj['ticket']
|
179
183
|
end
|
180
184
|
|
185
|
+
#长链接转短连接
|
186
|
+
def gen_short_url(app_id=nil, long_url)
|
187
|
+
app_id ||= self.APP_ID
|
188
|
+
access_token = access_token(app_id)
|
189
|
+
return nil unless access_token
|
190
|
+
|
191
|
+
response = Faraday.new(:url => 'https://api.weixin.qq.com').post do |req|
|
192
|
+
req.url '/cgi-bin/shorturl'
|
193
|
+
req.headers['Content-Type'] = 'application/json'
|
194
|
+
data = {
|
195
|
+
action: 'long2short',
|
196
|
+
long_url: long_url
|
197
|
+
}
|
198
|
+
req.params[:long_url] = long_url
|
199
|
+
req.params[:access_token] = access_token
|
200
|
+
req.body = data.to_json
|
201
|
+
end
|
202
|
+
|
203
|
+
json_obj = parse_json(response.body)
|
204
|
+
return nil unless json_obj
|
205
|
+
return nil unless json_obj.has_key?('short_url')
|
206
|
+
json_obj['short_url']
|
207
|
+
end
|
208
|
+
|
181
209
|
private
|
182
210
|
#解析json类型的数据,并将最后的数据转为hash或array
|
183
211
|
# +json_data_str+ 要转换的json数据
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: blsm-mp-wx
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.
|
4
|
+
version: 0.1.5
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- saxer
|
@@ -153,11 +153,10 @@ files:
|
|
153
153
|
- bin/setup
|
154
154
|
- blsm-mp-wx-0.1.0.gem
|
155
155
|
- blsm-mp-wx.gemspec
|
156
|
-
- lib/
|
157
|
-
- lib/
|
158
|
-
- lib/
|
159
|
-
- lib/
|
160
|
-
- lib/blsm_mp_wx/version.rb
|
156
|
+
- lib/blsm-mp-wx.rb
|
157
|
+
- lib/blsm-mp-wx/model/active_record.rb
|
158
|
+
- lib/blsm-mp-wx/model/vd_mp_wx.rb
|
159
|
+
- lib/blsm-mp-wx/version.rb
|
161
160
|
homepage: https://bitbucket.org/liuxi/blsm-mp-wx/
|
162
161
|
licenses:
|
163
162
|
- MIT
|
data/lib/blsm_mp_wx/db_config.rb
DELETED
File without changes
|