blsm-mp-wx 0.3.2 → 0.3.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 1f8627cdc21ebebaae6bd5ba1a751c7075da830c
4
- data.tar.gz: 3fd6d1978070acea8a13f3f9596ef1c41d2bff6f
3
+ metadata.gz: 1c73f477410ef96688ed160391f917d9b8d2c256
4
+ data.tar.gz: 003d583687cd0d1ea87cb3f8e22dfed170a41187
5
5
  SHA512:
6
- metadata.gz: 319af98b7850002080c95c0a8d7be39f3989d9d3bc74030c00cff82532ce6ba89338a01c7a9117195325a7a2891a0419dadc5444a933d4326b9f66159924eb20
7
- data.tar.gz: 187ca1692b3ef235337d6eae4a98e115d028483a38cd8a2224e72fe8f295f81b7731324d31b33bd01a69ff0c39f8d122d5ac1472d1d518ce0a8bace2f1ce1e27
6
+ metadata.gz: 8b7084c4133c7303944afa4972599f476ae2305d8dc8033b8b7c52ef4568cb0e8eb915a80795d0e11977832b4e5be433a1327d7731fbbc68ef87364d6eacd9fc
7
+ data.tar.gz: 44f3b74eabfa55cfb87f0084711fd4307e660430d0505cbd6c18b8cfa94f9b06233adb12d1766d5915181474d44f86f42cddea910f65b74f8819348f2b0c339d
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- blsm-mp-wx (0.3.2)
4
+ blsm-mp-wx (0.3.3)
5
5
 
6
6
  GEM
7
7
  remote: https://ruby.taobao.org/
@@ -119,4 +119,4 @@ DEPENDENCIES
119
119
  rspec (~> 3.2)
120
120
 
121
121
  BUNDLED WITH
122
- 1.12.5
122
+ 1.13.6
@@ -0,0 +1,7 @@
1
+ # coding: utf-8
2
+ module BlsmMpWx
3
+ class VdWxUser < BaseRecord
4
+ self.table_name='vd_wx_users'
5
+
6
+ end
7
+ end
@@ -1,3 +1,3 @@
1
1
  module BlsmMpWx
2
- VERSION = "0.3.2"
2
+ VERSION = "0.3.3"
3
3
  end
data/lib/blsm-mp-wx.rb CHANGED
@@ -11,6 +11,7 @@ require 'blsm-mp-wx/version'
11
11
  require 'blsm-mp-wx/model/active_record'
12
12
  require 'blsm-mp-wx/model/vd_mp_wx'
13
13
  require 'blsm-mp-wx/model/vd_mp_msg'
14
+ require 'blsm-mp-wx/model/vd_wx_user'
14
15
  require 'json'
15
16
  require 'faraday'
16
17
 
@@ -350,6 +351,57 @@ module BlsmMpWx
350
351
  returned_openids
351
352
  end
352
353
 
354
+ #sns登录获取用户信息
355
+ def sns_login_userinfo(code)
356
+ app_id = 'wx143306afc47c63a6'
357
+ app = VdMpWx.where(app_id: app_id).first
358
+
359
+ conn = Faraday.new(:url => 'https://api.weixin.qq.com')
360
+ response = conn.post do |req|
361
+ req.url '/sns/oauth2/access_token'
362
+ req.headers['Content-Type'] = 'application/xml'
363
+ req.params[:appid] = app_id
364
+ req.params[:secret] =app.app_secret
365
+ req.params[:code] = code
366
+ req.params[:grant_type] = 'authorization_code'
367
+ end
368
+
369
+ if response.body.encoding != 'UTF-8'
370
+ response_body = response.body.force_encoding('UTF-8')
371
+ else
372
+ response_body = response.body
373
+ end
374
+
375
+ res = parse_json(response_body)
376
+
377
+
378
+ conn = Faraday.new(:url => 'https://api.weixin.qq.com')
379
+ response = conn.post do |req|
380
+ req.url '/sns/userinfo'
381
+ req.headers['Content-Type'] = 'application/xml'
382
+ req.params[:access_token] = res['access_token']
383
+ req.params[:openid] = res['openid']
384
+ end
385
+ if response.body.encoding != 'UTF-8'
386
+ response_body = response.body.force_encoding('UTF-8')
387
+ else
388
+ response_body = response.body
389
+ end
390
+
391
+ res = parse_json(response_body)
392
+ VdWxUser.find_or_create_by({app_id: app_id, openid: res['openid']}) do |u|
393
+ u.update_attributes({nickname: res['nickname'],
394
+ sex: res['sex'],
395
+ unionid: res['unionid'],
396
+ language: res['language'],
397
+ city: res['city'],
398
+ province: res['province'],
399
+ country: res['country'],
400
+ headimgurl: res['headimgurl'],
401
+ })
402
+ end
403
+ end
404
+
353
405
  private
354
406
  #解析json类型的数据,并将最后的数据转为hash或array
355
407
  # +json_data_str+ 要转换的json数据
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: blsm-mp-wx
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.3.2
4
+ version: 0.3.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - saxer
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2016-08-25 00:00:00.000000000 Z
11
+ date: 2017-01-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: rspec
@@ -170,6 +170,7 @@ files:
170
170
  - lib/blsm-mp-wx/model/active_record.rb
171
171
  - lib/blsm-mp-wx/model/vd_mp_msg.rb
172
172
  - lib/blsm-mp-wx/model/vd_mp_wx.rb
173
+ - lib/blsm-mp-wx/model/vd_wx_user.rb
173
174
  - lib/blsm-mp-wx/version.rb
174
175
  homepage: https://bitbucket.org/Xiaopuzhu/blsm-mp-wx/
175
176
  licenses:
@@ -192,7 +193,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
192
193
  version: '0'
193
194
  requirements: []
194
195
  rubyforge_project:
195
- rubygems_version: 2.4.8
196
+ rubygems_version: 2.4.3
196
197
  signing_key:
197
198
  specification_version: 4
198
199
  summary: "首趣微店微信公众号基本模块"