blsm-mp-wx 0.3.4 → 0.3.5
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/blsm-mp-wx/version.rb +1 -1
- data/lib/blsm-mp-wx.rb +27 -0
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8dd83e50e4ad1c6578569af7ceff7fb6012224ec
|
4
|
+
data.tar.gz: 0bf1585f16b7e9c9067b18c71266f4c8d8b67b5d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: dd897f7ebd66a70863fc180c25cec67269b3477672c9ab65bce7766e6279f24865968a9832dfde79ed2232aa83603a97cd6039a747e2b356bb404fe1bd451f88
|
7
|
+
data.tar.gz: c3dfbfde05338e7c734e4f0bac1c2ff5e48e8bbf01d0d81da38244a4e8ed7b22d7b354db525b594e7167a4d3670e90525f76a0301285dc456a41ac56860562b1
|
data/Gemfile.lock
CHANGED
data/lib/blsm-mp-wx/version.rb
CHANGED
data/lib/blsm-mp-wx.rb
CHANGED
@@ -405,6 +405,33 @@ module BlsmMpWx
|
|
405
405
|
end
|
406
406
|
end
|
407
407
|
|
408
|
+
#sns登录(公众号)获取用户信息
|
409
|
+
def sns_mp_login_userinfo(app_id, code)
|
410
|
+
conn = Faraday.new(:url => 'https://api.weixin.qq.com')
|
411
|
+
response = conn.get do |req|
|
412
|
+
req.url '/sns/oauth2/access_token'
|
413
|
+
req.params[:appid] = app_id
|
414
|
+
req.params[:secret] = VdMpWx.where(app_id: app_id).take.app_secret
|
415
|
+
req.params[:code] = code
|
416
|
+
req.params[:grant_type] = 'authorization_code'
|
417
|
+
end
|
418
|
+
response_body = response.body
|
419
|
+
res = parse_json(response_body)
|
420
|
+
return res unless res['nickname']
|
421
|
+
|
422
|
+
VdWxUser.find_or_create_by({app_id: app_id, openid: res['openid']}) do |u|
|
423
|
+
u.update_attributes({nickname: res['nickname'],
|
424
|
+
sex: res['sex'],
|
425
|
+
unionid: res['unionid'],
|
426
|
+
language: res['language'],
|
427
|
+
city: res['city'],
|
428
|
+
province: res['province'],
|
429
|
+
country: res['country'],
|
430
|
+
headimgurl: res['headimgurl'],
|
431
|
+
})
|
432
|
+
end
|
433
|
+
end
|
434
|
+
|
408
435
|
private
|
409
436
|
#解析json类型的数据,并将最后的数据转为hash或array
|
410
437
|
# +json_data_str+ 要转换的json数据
|