lib/blsm-mp-wx.rb in blsm-mp-wx-0.3.5 vs lib/blsm-mp-wx.rb in blsm-mp-wx-0.3.6
- old
+ new
@@ -350,12 +350,12 @@
end
returned_openids
end
#sns登录获取用户信息
- def sns_login_userinfo(code)
- app_id = 'wx143306afc47c63a6'
+ def sns_login_userinfo(code,app_id=nil)
+ app_id = app_id || 'wx143306afc47c63a6'
app = VdMpWx.where(app_id: app_id).first
conn = Faraday.new(:url => 'https://api.weixin.qq.com')
response = conn.post do |req|
req.url '/sns/oauth2/access_token'
@@ -387,36 +387,9 @@
response_body = response.body.force_encoding('UTF-8')
else
response_body = response.body
end
- res = parse_json(response_body)
- return res unless res['nickname']
-
- VdWxUser.find_or_create_by({app_id: app_id, openid: res['openid']}) do |u|
- u.update_attributes({nickname: res['nickname'],
- sex: res['sex'],
- unionid: res['unionid'],
- language: res['language'],
- city: res['city'],
- province: res['province'],
- country: res['country'],
- headimgurl: res['headimgurl'],
- })
- end
- end
-
- #sns登录(公众号)获取用户信息
- def sns_mp_login_userinfo(app_id, code)
- conn = Faraday.new(:url => 'https://api.weixin.qq.com')
- response = conn.get do |req|
- req.url '/sns/oauth2/access_token'
- req.params[:appid] = app_id
- req.params[:secret] = VdMpWx.where(app_id: app_id).take.app_secret
- req.params[:code] = code
- req.params[:grant_type] = 'authorization_code'
- end
- response_body = response.body
res = parse_json(response_body)
return res unless res['nickname']
VdWxUser.find_or_create_by({app_id: app_id, openid: res['openid']}) do |u|
u.update_attributes({nickname: res['nickname'],