|
|
|
@ -11,15 +11,15 @@ class Oauth::CreateOrFindWechatAccountService < ApplicationService
|
|
|
|
|
def call
|
|
|
|
|
code = params['code'].to_s.strip
|
|
|
|
|
raise Error, 'Code不能为空' if code.blank?
|
|
|
|
|
new_user = false
|
|
|
|
|
|
|
|
|
|
result = WechatOauth::Service.access_token(code)
|
|
|
|
|
result = WechatOauth::Service.user_info(result['access_token'], result['openid'])
|
|
|
|
|
|
|
|
|
|
# 存在该用户
|
|
|
|
|
open_user = OpenUsers::Wechat.find_by(uid: result['unionid'])
|
|
|
|
|
return open_user.user if open_user.present?
|
|
|
|
|
return [open_user.user, new_user] if open_user.present?
|
|
|
|
|
|
|
|
|
|
new_user = false
|
|
|
|
|
if user.blank? || !user.logged?
|
|
|
|
|
new_user = true
|
|
|
|
|
# 新用户
|
|
|
|
|