|
|
@ -1,16 +1,15 @@
|
|
|
|
package au.com.royalpay.payment.manage.signin.core.impls;
|
|
|
|
package au.com.royalpay.payment.manage.signin.core.impls;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper;
|
|
|
|
import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
|
|
|
|
import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
|
|
|
|
import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
|
|
|
|
import au.com.royalpay.payment.manage.signin.core.SignInAccountService;
|
|
|
|
import au.com.royalpay.payment.manage.signin.core.SignInStatusManager;
|
|
|
|
import au.com.royalpay.payment.manage.signin.core.SignInStatusManager;
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.WechatAppApi;
|
|
|
|
import au.com.royalpay.payment.tools.connections.mpsupport.MpClientAppWechatApiProvider;
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
import au.com.royalpay.payment.tools.env.PlatformEnvironment;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
|
|
|
|
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
|
|
|
|
import au.com.royalpay.payment.tools.utils.QRCodeUtils;
|
|
|
|
import au.com.royalpay.payment.tools.utils.QRCodeUtils;
|
|
|
|
|
|
|
|
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
import com.alibaba.fastjson.JSONObject;
|
|
|
|
|
|
|
|
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
import org.apache.commons.lang3.RandomStringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
@ -19,10 +18,8 @@ import org.springframework.data.redis.core.StringRedisTemplate;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
import org.springframework.web.servlet.ModelAndView;
|
|
|
|
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
import java.util.logging.Logger;
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
import javax.annotation.Resource;
|
|
|
|
|
|
|
|
import java.util.concurrent.TimeUnit;
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
/**
|
|
|
|
* Created by yixian on 2016-06-29.
|
|
|
|
* Created by yixian on 2016-06-29.
|
|
|
@ -36,7 +33,9 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private SignInAccountService signInAccountService;
|
|
|
|
private SignInAccountService signInAccountService;
|
|
|
|
@Resource
|
|
|
|
@Resource
|
|
|
|
private WechatAppApi wechatAppApi;
|
|
|
|
private MpClientAppWechatApiProvider mpClientAppWechatApiProvider;
|
|
|
|
|
|
|
|
@Resource
|
|
|
|
|
|
|
|
private ClientAccountMapper clientAccountMapper;
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject getCurrentManager(String statusKey) {
|
|
|
|
public JSONObject getCurrentManager(String statusKey) {
|
|
|
@ -76,6 +75,14 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
|
|
|
|
return statusKey;
|
|
|
|
return statusKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public String getClientInfoByPhoneStatusKey(String phone,String nationCode) {
|
|
|
|
|
|
|
|
JSONObject account = clientAccountMapper.findByPhone(phone, nationCode);
|
|
|
|
|
|
|
|
String statusKey = newStatusKey();
|
|
|
|
|
|
|
|
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
return statusKey;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
private String newStatusKey() {
|
|
|
|
private String newStatusKey() {
|
|
|
|
return Long.toHexString(System.currentTimeMillis()) + "_" + RandomStringUtils.random(20, true, true);
|
|
|
|
return Long.toHexString(System.currentTimeMillis()) + "_" + RandomStringUtils.random(20, true, true);
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -177,7 +184,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
|
|
|
|
String codeId = "manager_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis();
|
|
|
|
String codeId = "manager_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis();
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
res.put("code_id", codeId);
|
|
|
|
res.put("code_id", codeId);
|
|
|
|
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat_qrcode/" + codeId), 300,false));
|
|
|
|
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/manager_signin_wechat_qrcode/" + codeId), 300, false));
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -231,13 +238,13 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public JSONObject partnerWechatAppSignIn(String code) {
|
|
|
|
public JSONObject partnerWechatAppSignIn(String code) {
|
|
|
|
JSONObject user = wechatAppApi.appLoginUser(code);
|
|
|
|
JSONObject user = mpClientAppWechatApiProvider.getApi("clientapp").appLoginUser(code);
|
|
|
|
String openId = user.getString("openid");
|
|
|
|
String openId = user.getString("openid");
|
|
|
|
String unionId = user.getString("unionid");
|
|
|
|
String unionId = user.getString("unionid");
|
|
|
|
JSONObject account = signInAccountService.clientWechatAppSignIn(openId);
|
|
|
|
JSONObject account = signInAccountService.clientWechatAppSignIn(openId);
|
|
|
|
if (account == null) {
|
|
|
|
if (account == null) {
|
|
|
|
account = signInAccountService.clientWechatAppSignInByUnionId(unionId);
|
|
|
|
account = signInAccountService.clientWechatAppSignInByUnionId(unionId);
|
|
|
|
if (account==null){
|
|
|
|
if (account == null) {
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
res.put("not_exists", true);
|
|
|
|
res.put("not_exists", true);
|
|
|
|
res.put("app_openid", openId);
|
|
|
|
res.put("app_openid", openId);
|
|
|
@ -265,7 +272,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
|
|
|
|
String codeId = "client_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis();
|
|
|
|
String codeId = "client_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis();
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
res.put("code_id", codeId);
|
|
|
|
res.put("code_id", codeId);
|
|
|
|
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/partner_signin_wechat_qrcode/" + codeId), 300,false));
|
|
|
|
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/partner_signin_wechat_qrcode/" + codeId), 300, false));
|
|
|
|
lockRandomCodeId(codeId);
|
|
|
|
lockRandomCodeId(codeId);
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
@ -275,13 +282,13 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
|
|
|
|
String codeId = "app_" + RandomStringUtils.random(20, true, true) + "_" + System.currentTimeMillis();
|
|
|
|
String codeId = "app_" + RandomStringUtils.random(20, true, true) + "_" + System.currentTimeMillis();
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
res.put("code_id", codeId);
|
|
|
|
res.put("code_id", codeId);
|
|
|
|
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/partner_signin_qrcode/verify/" + codeId), 300,false));
|
|
|
|
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/partner_signin_qrcode/verify/" + codeId), 300, false));
|
|
|
|
lockRandomCodeId(codeId);
|
|
|
|
lockRandomCodeId(codeId);
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void clientQRCodeAppSignIn(JSONObject device,String codeId) {
|
|
|
|
public void clientQRCodeAppSignIn(JSONObject device, String codeId) {
|
|
|
|
getlockRandomCodeId(codeId);
|
|
|
|
getlockRandomCodeId(codeId);
|
|
|
|
String statusKey = newStatusKey();
|
|
|
|
String statusKey = newStatusKey();
|
|
|
|
JSONObject account = new JSONObject();
|
|
|
|
JSONObject account = new JSONObject();
|
|
|
@ -296,7 +303,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
@Override
|
|
|
|
public void clientQRCodeWechatSignIn(JSONObject wxUser,String codeId) {
|
|
|
|
public void clientQRCodeWechatSignIn(JSONObject wxUser, String codeId) {
|
|
|
|
getlockRandomCodeId(codeId);
|
|
|
|
getlockRandomCodeId(codeId);
|
|
|
|
String statusKey = newStatusKey();
|
|
|
|
String statusKey = newStatusKey();
|
|
|
|
JSONObject account = new JSONObject();
|
|
|
|
JSONObject account = new JSONObject();
|
|
|
@ -325,7 +332,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
|
|
|
|
String codeId = "customer_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis();
|
|
|
|
String codeId = "customer_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis();
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
res.put("code_id", codeId);
|
|
|
|
res.put("code_id", codeId);
|
|
|
|
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/customer_qrcode_scan/" + codeId), 300,false));
|
|
|
|
res.put("code_img", QRCodeUtils.qrcodeImageCode(PlatformEnvironment.getEnv().concatUrl("/global/userstatus/customer_qrcode_scan/" + codeId), 300, false));
|
|
|
|
return res;
|
|
|
|
return res;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
@ -344,6 +351,30 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
|
|
|
|
return statusKey;
|
|
|
|
return statusKey;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override
|
|
|
|
|
|
|
|
public JSONObject clientAppWechatSignIn(String code) {
|
|
|
|
|
|
|
|
JSONObject user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(code);
|
|
|
|
|
|
|
|
String openId = user.getString("openid");
|
|
|
|
|
|
|
|
String unionId = user.getString("unionid");
|
|
|
|
|
|
|
|
JSONObject account = signInAccountService.clientWechatAppSignIn(openId);
|
|
|
|
|
|
|
|
if (account == null) {
|
|
|
|
|
|
|
|
account = signInAccountService.clientWechatAppSignInByUnionId(unionId);
|
|
|
|
|
|
|
|
if (account == null) {
|
|
|
|
|
|
|
|
JSONObject res = new JSONObject();
|
|
|
|
|
|
|
|
res.put("bind_status", false);
|
|
|
|
|
|
|
|
res.put("app_openid", openId);
|
|
|
|
|
|
|
|
return res;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
String statusKey = newStatusKey();
|
|
|
|
|
|
|
|
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
|
|
|
|
|
|
|
|
account = getCurrentClient(statusKey);
|
|
|
|
|
|
|
|
account.put("sign_key", statusKey);
|
|
|
|
|
|
|
|
account.put("app_openid", openId);
|
|
|
|
|
|
|
|
account.put("bind_status",true);
|
|
|
|
|
|
|
|
return account;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
private void lockRandomCodeId(String codeId) {
|
|
|
|
private void lockRandomCodeId(String codeId) {
|
|
|
|
stringRedisTemplate.boundValueOps(redisPrefix + "partner_signin" + codeId).set(codeId, 30, TimeUnit.SECONDS);
|
|
|
|
stringRedisTemplate.boundValueOps(redisPrefix + "partner_signin" + codeId).set(codeId, 30, TimeUnit.SECONDS);
|
|
|
|