[Y] apple 登录

master
taylor.dang 5 years ago
parent 63631a6b46
commit 812b2474d6

@ -9,7 +9,7 @@
</parent> </parent>
<modelVersion>4.0.0</modelVersion> <modelVersion>4.0.0</modelVersion>
<artifactId>manage</artifactId> <artifactId>manage</artifactId>
<version>2.2.5</version> <version>2.2.6</version>
<properties> <properties>
<project.build.sourceEncoding>UTF-8</project.build.sourceEncoding> <project.build.sourceEncoding>UTF-8</project.build.sourceEncoding>
<jib-maven-plugin.version>1.8.0</jib-maven-plugin.version> <jib-maven-plugin.version>1.8.0</jib-maven-plugin.version>

@ -0,0 +1,28 @@
package au.com.royalpay.payment.manage.appclient.beans;
import com.alibaba.fastjson.annotation.JSONField;
import lombok.Getter;
import lombok.Setter;
import javax.validation.constraints.NotEmpty;
/**
* @author taylor.dang
* @date 2020-04-20 21:26
*/
@Getter
@Setter
public class AppleLoginBean {
@JSONField(name = "identityToken")
@NotEmpty
private String identityToken;
@JSONField(name = "user")
@NotEmpty
private String user;
@JSONField(name = "devId")
@NotEmpty
private String devId;
@JSONField(name = "authorizationCode")
@NotEmpty
private String authorizationCode;
}

@ -1,9 +1,6 @@
package au.com.royalpay.payment.manage.appclient.core; package au.com.royalpay.payment.manage.appclient.core;
import au.com.royalpay.payment.manage.appclient.beans.AppClientBean; import au.com.royalpay.payment.manage.appclient.beans.*;
import au.com.royalpay.payment.manage.appclient.beans.AppPaymentConfigBean;
import au.com.royalpay.payment.manage.appclient.beans.AppQueryBean;
import au.com.royalpay.payment.manage.appclient.beans.RetailAppMessage;
import au.com.royalpay.payment.manage.merchants.beans.ClientAuthFilesInfo; import au.com.royalpay.payment.manage.merchants.beans.ClientAuthFilesInfo;
import au.com.royalpay.payment.manage.merchants.beans.ClientKycFilesInfo; import au.com.royalpay.payment.manage.merchants.beans.ClientKycFilesInfo;
import au.com.royalpay.payment.manage.merchants.beans.ClientUpdateInfo; import au.com.royalpay.payment.manage.merchants.beans.ClientUpdateInfo;
@ -201,6 +198,8 @@ public interface RetailAppService {
void updateLoginClientAccountPhone(JSONObject account,String contactPhone, String nationCode); void updateLoginClientAccountPhone(JSONObject account,String contactPhone, String nationCode);
void updateLoginClientAccountOpenId(JSONObject client,JSONObject params); void updateLoginClientAccountOpenId(JSONObject client,JSONObject params);
void updateLoginClientAccountAppleId(JSONObject client,JSONObject params);
/** /**
* 退 * 退
*/ */
@ -251,6 +250,10 @@ public interface RetailAppService {
JSONObject bindAccountWechat(JSONObject device, JSONObject params); JSONObject bindAccountWechat(JSONObject device, JSONObject params);
JSONObject unbindAccountApple(JSONObject device);
JSONObject bindAccountApple(JSONObject device, AppleLoginBean appleLoginBean);
JSONObject getAccountBindInfos(JSONObject device); JSONObject getAccountBindInfos(JSONObject device);
JSONObject postAppMessage(JSONObject device, RetailAppMessage message); JSONObject postAppMessage(JSONObject device, RetailAppMessage message);

@ -6,10 +6,7 @@ import au.com.royalpay.payment.core.exceptions.InvalidShortIdException;
import au.com.royalpay.payment.manage.activities.app_index.core.AppActService; import au.com.royalpay.payment.manage.activities.app_index.core.AppActService;
import au.com.royalpay.payment.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper; import au.com.royalpay.payment.manage.analysis.mappers.CustomerAndOrdersStatisticsMapper;
import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper; import au.com.royalpay.payment.manage.analysis.mappers.TransactionAnalysisMapper;
import au.com.royalpay.payment.manage.appclient.beans.AppClientBean; import au.com.royalpay.payment.manage.appclient.beans.*;
import au.com.royalpay.payment.manage.appclient.beans.AppPaymentConfigBean;
import au.com.royalpay.payment.manage.appclient.beans.AppQueryBean;
import au.com.royalpay.payment.manage.appclient.beans.RetailAppMessage;
import au.com.royalpay.payment.manage.appclient.core.RetailAppService; import au.com.royalpay.payment.manage.appclient.core.RetailAppService;
import au.com.royalpay.payment.manage.appclient.extend.GatewayOAuthRegister; import au.com.royalpay.payment.manage.appclient.extend.GatewayOAuthRegister;
import au.com.royalpay.payment.manage.cashback.core.CashbackService; import au.com.royalpay.payment.manage.cashback.core.CashbackService;
@ -73,6 +70,8 @@ import au.com.royalpay.payment.tools.merchants.core.MerchantInfoProvider;
import au.com.royalpay.payment.tools.permission.enums.PartnerRole; import au.com.royalpay.payment.tools.permission.enums.PartnerRole;
import au.com.royalpay.payment.tools.threadpool.RoyalThreadPoolExecutor; import au.com.royalpay.payment.tools.threadpool.RoyalThreadPoolExecutor;
import au.com.royalpay.payment.tools.utils.*; import au.com.royalpay.payment.tools.utils.*;
import au.com.royalpay.payment.tools.utils.apple.AppleAuthUtils;
import au.com.royalpay.payment.tools.utils.apple.UserClaim;
import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray; import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
@ -1782,7 +1781,7 @@ public class RetailAppServiceImp implements RetailAppService {
if (geekShowActVersion(device.getString("version"))) { if (geekShowActVersion(device.getString("version"))) {
newActs.add(act); newActs.add(act);
} }
}else { } else {
newActs.add(act); newActs.add(act);
} }
} }
@ -2322,6 +2321,14 @@ public class RetailAppServiceImp implements RetailAppService {
clientAccountMapper.update(updateAccount); clientAccountMapper.update(updateAccount);
} }
@Override
public void updateLoginClientAccountAppleId(JSONObject account, JSONObject params) {
JSONObject updateAccount = new JSONObject();
updateAccount.put("account_id", account.getString("account_id"));
updateAccount.put("apple_userid", params.getString("apple_userid"));
clientAccountMapper.update(updateAccount);
}
@Override @Override
public JSONObject unbindAccountPhone(JSONObject device, JSONObject params) { public JSONObject unbindAccountPhone(JSONObject device, JSONObject params) {
String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get(); String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get();
@ -2379,6 +2386,36 @@ public class RetailAppServiceImp implements RetailAppService {
return result; return result;
} }
@Override
public JSONObject unbindAccountApple(JSONObject device) {
JSONObject account = new JSONObject();
account.put("account_id", device.getString("account_id"));
account.put("apple_userid", null);
clientAccountMapper.update(account);
JSONObject result = new JSONObject();
result.put("status", "success");
return result;
}
@Override
public JSONObject bindAccountApple(JSONObject device, AppleLoginBean appleLoginBean) {
UserClaim userClaim = AppleAuthUtils.verifyIdentifyToken(appleLoginBean.getIdentityToken());
if (!StringUtils.equalsIgnoreCase(userClaim.getSub(), appleLoginBean.getUser())) {
throw new ForbiddenException("apple userinfo is error");
}
JSONObject account = clientAccountMapper.findByAppleUserId(userClaim.getSub());
if (account != null) {
throw new BadRequestException("Apple UserID has been bound to other accounts, please unbind it before binding");
}
JSONObject updateAccount = new JSONObject();
updateAccount.put("account_id", device.getString("account_id"));
updateAccount.put("apple_userid", userClaim.getSub());
clientAccountMapper.update(updateAccount);
JSONObject result = new JSONObject();
result.put("status", "success");
return result;
}
@Override @Override
public JSONObject getAccountBindInfos(JSONObject device) { public JSONObject getAccountBindInfos(JSONObject device) {
JSONObject account = clientAccountMapper.findById(device.getString("account_id")); JSONObject account = clientAccountMapper.findById(device.getString("account_id"));
@ -2391,6 +2428,7 @@ public class RetailAppServiceImp implements RetailAppService {
result.put("nation_code", account.getString("nation_code")); result.put("nation_code", account.getString("nation_code"));
} }
result.put("wechat_bind_status", account.containsKey("wx_unionid")); result.put("wechat_bind_status", account.containsKey("wx_unionid"));
result.put("apple_bind_status", account.containsKey("apple_userid"));
if (account.containsKey("wx_unionid")) { if (account.containsKey("wx_unionid")) {
result.put("wechat_name", account.getString("wechat_name")); result.put("wechat_name", account.getString("wechat_name"));
} }
@ -2536,7 +2574,7 @@ public class RetailAppServiceImp implements RetailAppService {
} }
JSONObject compliance = clientComplianceCompanyMapper.findFileByClientId(account.getIntValue("client_id")); JSONObject compliance = clientComplianceCompanyMapper.findFileByClientId(account.getIntValue("client_id"));
if (compliance != null) { if (compliance != null) {
if (compliance.getIntValue("status")==0 || compliance.getIntValue("status")==1) { if (compliance.getIntValue("status") == 0 || compliance.getIntValue("status") == 1) {
authFileStatus.put("client_less_file", false); authFileStatus.put("client_less_file", false);
} }
} }
@ -2555,14 +2593,14 @@ public class RetailAppServiceImp implements RetailAppService {
authFileStatus.put("content", messageSource.getMessage("client.auth.file.title", null, RequestEnvironment.getLocale())); authFileStatus.put("content", messageSource.getMessage("client.auth.file.title", null, RequestEnvironment.getLocale()));
List<JSONObject> supplement_array = new ArrayList<>(); List<JSONObject> supplement_array = new ArrayList<>();
JSONObject complianceFilesNotice = complianceFilesNotice(client,account); JSONObject complianceFilesNotice = complianceFilesNotice(client, account);
JSONObject kycFilesNotice = kycFilesNotice(client,account); JSONObject kycFilesNotice = kycFilesNotice(client, account);
if(complianceFilesNotice != null && kycFilesNotice != null){ if (complianceFilesNotice != null && kycFilesNotice != null) {
if( !kycFilesNotice.getBoolean("client_less_file") && !complianceFilesNotice.getBoolean("client_less_file")){ if (!kycFilesNotice.getBoolean("client_less_file") && !complianceFilesNotice.getBoolean("client_less_file")) {
authFileStatus.put("isNeedShowKycAlert",false); authFileStatus.put("isNeedShowKycAlert", false);
}else{ } else {
authFileStatus.put("isNeedShowKycAlert",true); authFileStatus.put("isNeedShowKycAlert", true);
} }
} }
if (PartnerRole.getRole(account.getIntValue("role")) == PartnerRole.CASHIER) { if (PartnerRole.getRole(account.getIntValue("role")) == PartnerRole.CASHIER) {
@ -2652,20 +2690,20 @@ public class RetailAppServiceImp implements RetailAppService {
complianceFilesNotice.put("auth_type", FilesAuthTypeEnum.COMPLIANCE.getAuthType()); complianceFilesNotice.put("auth_type", FilesAuthTypeEnum.COMPLIANCE.getAuthType());
complianceFilesNotice.put("type", messageSource.getMessage("client.auth.file.compliance.type", null, RequestEnvironment.getLocale())); complianceFilesNotice.put("type", messageSource.getMessage("client.auth.file.compliance.type", null, RequestEnvironment.getLocale()));
complianceFilesNotice.put("client_less_file",complianceFileStatus.getBoolean("client_less_file")); complianceFilesNotice.put("client_less_file", complianceFileStatus.getBoolean("client_less_file"));
if(compliance != null){ if (compliance != null) {
if (compliance.getIntValue("status")==0 || compliance.getIntValue("status")==1) { if (compliance.getIntValue("status") == 0 || compliance.getIntValue("status") == 1) {
complianceFilesNotice.put("client_less_file", false); complianceFilesNotice.put("client_less_file", false);
} }
if(complianceFileStatus.getBoolean("client_less_file")){ if (complianceFileStatus.getBoolean("client_less_file")) {
complianceFilesNotice.put("client_refuse_reason",compliance.getString("description")); complianceFilesNotice.put("client_refuse_reason", compliance.getString("description"));
} }
complianceFilesNotice.put("status",compliance.getString("status")); complianceFilesNotice.put("status", compliance.getString("status"));
complianceFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(compliance.getIntValue("status")) ); complianceFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(compliance.getIntValue("status")));
}else if( !complianceFileStatus.getBoolean("client_less_file")){ } else if (!complianceFileStatus.getBoolean("client_less_file")) {
complianceFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(1) ); complianceFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(1));
}else{ } else {
complianceFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(-1) ); complianceFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(-1));
} }
complianceFilesNotice.put("status_type_description", messageSource.getMessage("client.auth.file.status." + complianceFilesNotice.getString("status_type").toLowerCase(), null, RequestEnvironment.getLocale())); complianceFilesNotice.put("status_type_description", messageSource.getMessage("client.auth.file.status." + complianceFilesNotice.getString("status_type").toLowerCase(), null, RequestEnvironment.getLocale()));
return complianceFilesNotice; return complianceFilesNotice;
@ -2683,15 +2721,15 @@ public class RetailAppServiceImp implements RetailAppService {
kycFilesNotice.put("auth_type", FilesAuthTypeEnum.KYC.getAuthType()); kycFilesNotice.put("auth_type", FilesAuthTypeEnum.KYC.getAuthType());
kycFilesNotice.put("type", messageSource.getMessage("client.auth.file.kyc.type", null, RequestEnvironment.getLocale())); kycFilesNotice.put("type", messageSource.getMessage("client.auth.file.kyc.type", null, RequestEnvironment.getLocale()));
kycFilesNotice.put("client_less_file",kycFileStatus.getBoolean("client_less_file")); kycFilesNotice.put("client_less_file", kycFileStatus.getBoolean("client_less_file"));
if(compliance != null){ if (compliance != null) {
if(kycFilesNotice.getBoolean("client_less_file")){ if (kycFilesNotice.getBoolean("client_less_file")) {
kycFilesNotice.put("client_refuse_reason",compliance.getString("description")); kycFilesNotice.put("client_refuse_reason", compliance.getString("description"));
} }
kycFilesNotice.put("status",compliance.getString("status")); kycFilesNotice.put("status", compliance.getString("status"));
kycFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(compliance.getIntValue("status")) ); kycFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(compliance.getIntValue("status")));
}else{ } else {
kycFilesNotice.put( "status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(-1) ); kycFilesNotice.put("status_type", FilesAuthStatusEnum.STATUS.getAuthStatus(-1));
} }
kycFilesNotice.put("status_type_description", messageSource.getMessage("client.auth.file.status." + kycFilesNotice.getString("status_type").toLowerCase(), null, RequestEnvironment.getLocale())); kycFilesNotice.put("status_type_description", messageSource.getMessage("client.auth.file.status." + kycFilesNotice.getString("status_type").toLowerCase(), null, RequestEnvironment.getLocale()));
return kycFilesNotice; return kycFilesNotice;
@ -3103,7 +3141,7 @@ public class RetailAppServiceImp implements RetailAppService {
int clientId = account.getIntValue("client_id"); int clientId = account.getIntValue("client_id");
JSONObject displayInfo = actPartnerReadMapper.displayInfo(actId, clientId, accountId); JSONObject displayInfo = actPartnerReadMapper.displayInfo(actId, clientId, accountId);
if (displayInfo == null) { if (displayInfo == null) {
displayInfo = new JSONObject(){{ displayInfo = new JSONObject() {{
put("display_client_id", UUID.randomUUID().toString()); put("display_client_id", UUID.randomUUID().toString());
put("act_id", actId); put("act_id", actId);
put("client_id", clientId); put("client_id", clientId);
@ -3117,7 +3155,7 @@ public class RetailAppServiceImp implements RetailAppService {
int accountDisplayCount = displayInfo.getIntValue("display_count"); int accountDisplayCount = displayInfo.getIntValue("display_count");
if (accountDisplayCount < displayCount) { if (accountDisplayCount < displayCount) {
displayInfo.put("last_read_time", new Date()); displayInfo.put("last_read_time", new Date());
displayInfo.put("display_count", (accountDisplayCount+1)); displayInfo.put("display_count", (accountDisplayCount + 1));
actPartnerReadMapper.update(displayInfo); actPartnerReadMapper.update(displayInfo);
return false; return false;
} }

@ -3,10 +3,7 @@ package au.com.royalpay.payment.manage.appclient.web;
import au.com.royalpay.payment.core.exceptions.ParamInvalidException; import au.com.royalpay.payment.core.exceptions.ParamInvalidException;
import au.com.royalpay.payment.manage.activities.app_index.core.AppActService; import au.com.royalpay.payment.manage.activities.app_index.core.AppActService;
import au.com.royalpay.payment.manage.activities.monsettledelay.core.ActMonDelaySettleService; import au.com.royalpay.payment.manage.activities.monsettledelay.core.ActMonDelaySettleService;
import au.com.royalpay.payment.manage.appclient.beans.AppClientBean; import au.com.royalpay.payment.manage.appclient.beans.*;
import au.com.royalpay.payment.manage.appclient.beans.AppPaymentConfigBean;
import au.com.royalpay.payment.manage.appclient.beans.AppQueryBean;
import au.com.royalpay.payment.manage.appclient.beans.RetailAppMessage;
import au.com.royalpay.payment.manage.appclient.core.RetailAppService; import au.com.royalpay.payment.manage.appclient.core.RetailAppService;
import au.com.royalpay.payment.manage.bill.bean.NewBillBean; import au.com.royalpay.payment.manage.bill.bean.NewBillBean;
import au.com.royalpay.payment.manage.bill.bean.QueryBillBean; import au.com.royalpay.payment.manage.bill.bean.QueryBillBean;
@ -206,7 +203,7 @@ public class RetailAppController {
@GetMapping("/notice/unread") @GetMapping("/notice/unread")
public List<JSONObject> latestNotice(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device) { public List<JSONObject> latestNotice(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device) {
return retailAppService.getLatestNotice(device,device.getIntValue("client_id")); return retailAppService.getLatestNotice(device, device.getIntValue("client_id"));
} }
/* 消息模块end */ /* 消息模块end */
@ -774,32 +771,53 @@ public class RetailAppController {
* @throws Exception * @throws Exception
*/ */
@PutMapping("/account/phone/unbind") @PutMapping("/account/phone/unbind")
public JSONObject unbindAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) throws Exception { public JSONObject unbindAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) throws Exception {
return retailAppService.unbindAccountPhone(device, params); return retailAppService.unbindAccountPhone(device, params);
} }
/** /**
* *
* @param device *
* @param device
* @param params * @param params
*/ */
@PutMapping("/account/wechat/bind") @PutMapping("/account/wechat/bind")
public JSONObject bindAccountWechat(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params){ public JSONObject bindAccountWechat(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) {
return retailAppService.bindAccountWechat(device,params); return retailAppService.bindAccountWechat(device, params);
} }
/** /**
* *
*
* @param device * @param device
*/ */
@PutMapping("/account/wechat/unbind") @PutMapping("/account/wechat/unbind")
public JSONObject unbindAccountWechat(@ModelAttribute(RETAIL_DEVICE) JSONObject device){ public JSONObject unbindAccountWechat(@ModelAttribute(RETAIL_DEVICE) JSONObject device) {
return retailAppService.unbindAccountWechat(device); return retailAppService.unbindAccountWechat(device);
} }
/**
* Apple
*
* @param device
*/
@PutMapping("/account/apple/bind")
public JSONObject bindAccountApple(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @Valid @RequestBody AppleLoginBean appleLoginBean) {
return retailAppService.bindAccountApple(device, appleLoginBean);
}
/**
* Apple
*
* @param device
*/
@PutMapping("/account/apple/unbind")
public JSONObject unbindAccountApple(@ModelAttribute(RETAIL_DEVICE) JSONObject device) {
return retailAppService.unbindAccountApple(device);
}
/** /**
* 退 * 退
@ -918,9 +936,9 @@ public class RetailAppController {
* @param device * @param device
*/ */
@PostMapping("/client/kyc_auth_file") @PostMapping("/client/kyc_auth_file")
public JSONObject uploadKycAuthFiles(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, @RequestParam MultipartFile file, @RequestParam("fileType") String fileType)throws Exception{ public JSONObject uploadKycAuthFiles(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, @RequestParam MultipartFile file, @RequestParam("fileType") String fileType) throws Exception {
JSONObject fileInfo = attachmentClient.uploadFile(file, false); JSONObject fileInfo = attachmentClient.uploadFile(file, false);
retailAppService.uploadKycAuthFilesForApp(device, fileInfo,fileType); retailAppService.uploadKycAuthFilesForApp(device, fileInfo, fileType);
return fileInfo; return fileInfo;
} }
@ -930,7 +948,7 @@ public class RetailAppController {
* @param device * @param device
*/ */
@PostMapping("/client/auth_file/commit_to_kyc") @PostMapping("/client/auth_file/commit_to_kyc")
public void commitToKycAuthFiles(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device,@RequestBody JSONObject params) { public void commitToKycAuthFiles(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) {
retailAppService.commitAuthFilesToKyc(device, params); retailAppService.commitAuthFilesToKyc(device, params);
} }
@ -960,12 +978,13 @@ public class RetailAppController {
/** /**
* () * ()
*
* @param device * @param device
* @return * @return
*/ */
@GetMapping("/client/account/bind/infos") @GetMapping("/client/account/bind/infos")
public JSONObject findClientAccountBindStatusInfos(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device){ public JSONObject findClientAccountBindStatusInfos(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device) {
return retailAppService.getAccountBindInfos(device); return retailAppService.getAccountBindInfos(device);
} }
} }

@ -1,5 +1,6 @@
package au.com.royalpay.payment.manage.appclient.web; package au.com.royalpay.payment.manage.appclient.web;
import au.com.royalpay.payment.manage.appclient.beans.AppleLoginBean;
import au.com.royalpay.payment.manage.appclient.beans.RetailLoginInfo; import au.com.royalpay.payment.manage.appclient.beans.RetailLoginInfo;
import au.com.royalpay.payment.manage.appclient.core.ManageAppService; import au.com.royalpay.payment.manage.appclient.core.ManageAppService;
import au.com.royalpay.payment.manage.appclient.core.RetailAppService; import au.com.royalpay.payment.manage.appclient.core.RetailAppService;
@ -138,6 +139,35 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
return res; return res;
} }
@PostMapping("/apple_signin")
public JSONObject mchAppleSignIn(@Valid @RequestBody AppleLoginBean appleLoginBean) {
return signInStatusManager.mchAppleSignIn(appleLoginBean);
}
/**
*
*
* @param params
* @return
*/
@PostMapping("/login/apple_bind")
public JSONObject appleLoginBind(@RequestBody JSONObject params) {
LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginId(params.getString("loginId"));
loginInfo.setPassword(params.getString("password"));
String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo, "apple");
JSONObject account = signInStatusManager.getCurrentClient(signKey);
retailAppService.updateLoginClientAccountAppleId(account, params);
account = JSON.parseObject(account.toJSONString());
JSONObject result = new JSONObject();
account.put("sign_key", signKey);
result.put("account", account);
result.put("bind_status", true);
result.put("status", "success");
this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "wechat"));
return result;
}
@GetMapping("/captcha") @GetMapping("/captcha")
public JSONObject getCaptchaForDevice(@RequestParam(defaultValue = "false") boolean imgurl) throws IOException { public JSONObject getCaptchaForDevice(@RequestParam(defaultValue = "false") boolean imgurl) throws IOException {
String capText = RandomStringUtils.random(4, false, true); String capText = RandomStringUtils.random(4, false, true);
@ -186,9 +216,9 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
@PostMapping("/send/{phone_number}/verify_code") @PostMapping("/send/{phone_number}/verify_code")
@ResponseBody @ResponseBody
public JSONObject sendLoginMobileVerifyCode(@PathVariable("phone_number") String phoneNumber, public JSONObject sendLoginMobileVerifyCode(@PathVariable("phone_number") String phoneNumber,
@RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode, @RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode,
HttpServletRequest request) { HttpServletRequest request) {
simpleClientApplyService.getAndSendLoginSmsCode(phoneNumber, nationCode, request); simpleClientApplyService.getAndSendLoginSmsCode(phoneNumber, nationCode, request);
return new JSONObject(); return new JSONObject();
} }
@ -201,58 +231,59 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
*/ */
@PostMapping("/login/verify/{contact_phone}/verify_code") @PostMapping("/login/verify/{contact_phone}/verify_code")
public JSONObject verifyLoginMobileCode(@PathVariable("contact_phone") String contactPhone, public JSONObject verifyLoginMobileCode(@PathVariable("contact_phone") String contactPhone,
@RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode, @RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode,
@RequestBody JSONObject params, @RequestBody JSONObject params,
@ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device, @ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device,
Errors errors) { Errors errors) {
HttpUtils.handleValidErrors(errors); HttpUtils.handleValidErrors(errors);
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
simpleClientApplyService.verifyLoginSMSCode(params.getString("verify_code"), contactPhone); simpleClientApplyService.verifyLoginSMSCode(params.getString("verify_code"), contactPhone);
String signKey = signInStatusManager.getClientInfoByPhoneStatusKey(contactPhone, nationCode); String signKey = signInStatusManager.getClientInfoByPhoneStatusKey(contactPhone, nationCode);
if(signKey!=null){ if (signKey != null) {
JSONObject account = signInStatusManager.getCurrentClient(signKey); JSONObject account = signInStatusManager.getCurrentClient(signKey);
account = JSON.parseObject(account.toJSONString()); account = JSON.parseObject(account.toJSONString());
if (params.getString("devId") != null) { if (params.getString("devId") != null) {
deviceSupport.validDeviceWithClient(account, params.getString("devId")); deviceSupport.validDeviceWithClient(account, params.getString("devId"));
} }
account.put("sign_key", signKey); account.put("sign_key", signKey);
result.put("account",account); result.put("account", account);
result.put("status","success"); result.put("status", "success");
result.put("bind_status", true); result.put("bind_status", true);
this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE")); this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE"));
}else{ } else {
result.put("status","success"); result.put("status", "success");
result.put("bind_status", false); result.put("bind_status", false);
result.put("contact_phone",contactPhone); result.put("contact_phone", contactPhone);
result.put("nation_code",nationCode); result.put("nation_code", nationCode);
} }
return result; return result;
} }
/** /**
* - * -
*
* @param contactPhone * @param contactPhone
* @param nationCode * @param nationCode
* @param params * @param params
*/ */
@PostMapping("/login/mobile/{contact_phone}/bind") @PostMapping("/login/mobile/{contact_phone}/bind")
public JSONObject mobileLoginBind(@PathVariable("contact_phone")String contactPhone, public JSONObject mobileLoginBind(@PathVariable("contact_phone") String contactPhone,
@RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode, @RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode,
@RequestBody JSONObject params, @RequestBody JSONObject params,
Errors errors){ Errors errors) {
HttpUtils.handleValidErrors(errors); HttpUtils.handleValidErrors(errors);
LoginInfo loginInfo = new LoginInfo(); LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginId(params.getString("loginId")); loginInfo.setLoginId(params.getString("loginId"));
loginInfo.setPassword(params.getString("password")); loginInfo.setPassword(params.getString("password"));
String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"phone"); String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo, "phone");
signInStatusManager.verifyClientLoginPhoneBindCode(contactPhone,nationCode); signInStatusManager.verifyClientLoginPhoneBindCode(contactPhone, nationCode);
JSONObject account = signInStatusManager.getCurrentClient(signKey); JSONObject account = signInStatusManager.getCurrentClient(signKey);
retailAppService.updateLoginClientAccountPhone(account, contactPhone,nationCode); retailAppService.updateLoginClientAccountPhone(account, contactPhone, nationCode);
account.put("sign_key", signKey); account.put("sign_key", signKey);
account = JSON.parseObject(account.toJSONString()); account = JSON.parseObject(account.toJSONString());
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
result.put("account",account); result.put("account", account);
result.put("bind_status", true); result.put("bind_status", true);
this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE")); this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE"));
return result; return result;
@ -260,6 +291,7 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
/** /**
* App * App
*
* @param params * @param params
* @return * @return
*/ */
@ -268,7 +300,7 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
Errors errors) { Errors errors) {
HttpUtils.handleValidErrors(errors); HttpUtils.handleValidErrors(errors);
JSONObject account = signInStatusManager.clientAppWechatSignIn(params.getString("code")); JSONObject account = signInStatusManager.clientAppWechatSignIn(params.getString("code"));
if(!account.getBoolean("bind_status")){ if (!account.getBoolean("bind_status")) {
deviceSupport.validDeviceWithClient(account, params.getString("app_openid")); deviceSupport.validDeviceWithClient(account, params.getString("app_openid"));
return account; return account;
} }
@ -278,26 +310,27 @@ public class RetailValidationController implements ApplicationEventPublisherAwar
/** /**
* *
*
* @param params * @param params
* @return * @return
*/ */
@PostMapping("/login/wechat_bind") @PostMapping("/login/wechat_bind")
public JSONObject wechatLoginBind(@RequestBody JSONObject params){ public JSONObject wechatLoginBind(@RequestBody JSONObject params) {
LoginInfo loginInfo = new LoginInfo(); LoginInfo loginInfo = new LoginInfo();
loginInfo.setLoginId(params.getString("loginId")); loginInfo.setLoginId(params.getString("loginId"));
loginInfo.setPassword(params.getString("password")); loginInfo.setPassword(params.getString("password"));
String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"wechat"); String signKey = signInStatusManager.verifyClientAccountLogin(loginInfo, "wechat");
JSONObject wechatInfo = signInStatusManager.verifyClientLoginWechatBindCode(params.getString("wechat_openid")); JSONObject wechatInfo = signInStatusManager.verifyClientLoginWechatBindCode(params.getString("wechat_openid"));
JSONObject account = signInStatusManager.getCurrentClient(signKey); JSONObject account = signInStatusManager.getCurrentClient(signKey);
params.put("nick_name",wechatInfo.getString("nick_name")); params.put("nick_name", wechatInfo.getString("nick_name"));
params.put("union_id",wechatInfo.getString("union_id")); params.put("union_id", wechatInfo.getString("union_id"));
retailAppService.updateLoginClientAccountOpenId(account,params); retailAppService.updateLoginClientAccountOpenId(account, params);
account = JSON.parseObject(account.toJSONString()); account = JSON.parseObject(account.toJSONString());
JSONObject result = new JSONObject(); JSONObject result = new JSONObject();
account.put("sign_key", signKey); account.put("sign_key", signKey);
result.put("account",account); result.put("account", account);
result.put("bind_status", true); result.put("bind_status", true);
result.put("status","success"); result.put("status", "success");
this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "wechat")); this.publisher.publishEvent(new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "wechat"));
return result; return result;
} }

@ -28,7 +28,7 @@ public interface ClientAccountMapper {
@AutoSql(SqlType.SELECT) @AutoSql(SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "is_valid=1") @AdvanceSelect(addonWhereClause = "is_valid=1")
List<JSONObject> findByPhone(@Param("contact_phone") String contact_phone,@Param("nation_code")String nation_code); List<JSONObject> findByPhone(@Param("contact_phone") String contact_phone, @Param("nation_code") String nation_code);
@AutoSql(SqlType.SELECT) @AutoSql(SqlType.SELECT)
JSONObject findDetail(@Param("account_id") String accountId); JSONObject findDetail(@Param("account_id") String accountId);
@ -51,6 +51,10 @@ public interface ClientAccountMapper {
@AdvanceSelect(addonWhereClause = "is_valid=1", excludeColumns = {"salt", "password_hash"}) @AdvanceSelect(addonWhereClause = "is_valid=1", excludeColumns = {"salt", "password_hash"})
JSONObject findByAppOpenId(@Param("wxapp_openid") String openId); JSONObject findByAppOpenId(@Param("wxapp_openid") String openId);
@AutoSql(SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "is_valid=1", excludeColumns = {"salt", "password_hash"})
JSONObject findByAppleUserId(@Param("apple_userid") String appleUserId);
@AutoSql(SqlType.SELECT) @AutoSql(SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "is_valid=1", excludeColumns = {"salt", "password_hash"}) @AdvanceSelect(addonWhereClause = "is_valid=1", excludeColumns = {"salt", "password_hash"})
JSONObject findByWxUnioinId(@Param("wx_unionid") String wx_unionid); JSONObject findByWxUnioinId(@Param("wx_unionid") String wx_unionid);
@ -85,22 +89,23 @@ public interface ClientAccountMapper {
/** /**
* *
*
* @param unionId * @param unionId
* @return * @return
*/ */
JSONObject findOneByUnionIdAndCreateTimeDesc(@Param("wx_unionid")String unionId); JSONObject findOneByUnionIdAndCreateTimeDesc(@Param("wx_unionid") String unionId);
JSONObject findOneByPhoneAndCreateTimeDesc(@Param("contact_phone")String contactPhone,@Param("nation_code")String nationCode); JSONObject findOneByPhoneAndCreateTimeDesc(@Param("contact_phone") String contactPhone, @Param("nation_code") String nationCode);
@AutoSql(SqlType.SELECT) @AutoSql(SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "is_valid=1", excludeColumns = {"salt", "password_hash"}) @AdvanceSelect(addonWhereClause = "is_valid=1", excludeColumns = {"salt", "password_hash"})
List<JSONObject> findByWechatOpenId(@Param("wechat_openid")String openid); List<JSONObject> findByWechatOpenId(@Param("wechat_openid") String openid);
@AutoSql(SqlType.SELECT) @AutoSql(SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "is_valid=1", excludeColumns = {"salt", "password_hash"}) @AdvanceSelect(addonWhereClause = "is_valid=1", excludeColumns = {"salt", "password_hash"})
List<JSONObject> findByWechatUnionId(@Param("wx_unionid")String unionId); List<JSONObject> findByWechatUnionId(@Param("wx_unionid") String unionId);
@AutoSql(SqlType.SELECT) @AutoSql(SqlType.SELECT)
JSONObject findRSvcClientInfo(@Param("account_id")String accountId); JSONObject findRSvcClientInfo(@Param("account_id") String accountId);
} }

@ -48,6 +48,8 @@ public interface SignInAccountService {
JSONObject clientWechatAppSignIn(String openId); JSONObject clientWechatAppSignIn(String openId);
JSONObject clientAppleSignIn(String appleUserId);
JSONObject clientWechatAppSignInByUnionId(String unionId); JSONObject clientWechatAppSignInByUnionId(String unionId);
String ForgetPassword(String partner_code) throws Exception; String ForgetPassword(String partner_code) throws Exception;

@ -1,5 +1,6 @@
package au.com.royalpay.payment.manage.signin.core; package au.com.royalpay.payment.manage.signin.core;
import au.com.royalpay.payment.manage.appclient.beans.AppleLoginBean;
import au.com.royalpay.payment.manage.signin.beans.LoginInfo; import au.com.royalpay.payment.manage.signin.beans.LoginInfo;
import com.alibaba.fastjson.JSONObject; import com.alibaba.fastjson.JSONObject;
import org.springframework.web.servlet.ModelAndView; import org.springframework.web.servlet.ModelAndView;
@ -50,6 +51,8 @@ public interface SignInStatusManager {
JSONObject partnerWechatAppSignIn(String code); JSONObject partnerWechatAppSignIn(String code);
JSONObject mchAppleSignIn(AppleLoginBean appleLoginBean);
String clientWechatSignIn(String openid); String clientWechatSignIn(String openid);
JSONObject newClientWechatSignInQRCode(); JSONObject newClientWechatSignInQRCode();

@ -394,6 +394,17 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
return account; return account;
} }
@Override
public JSONObject clientAppleSignIn(String appleUserId) {
JSONObject account = clientAccountMapper.findByAppleUserId(appleUserId);
if (account == null) {
return null;
}
publisher.publishEvent(
new ClientLoginEvent(this, account.getIntValue("client_id"), account.getString("account_id"), RequestEnvironment.getClientIp(), "wechat"));
return account;
}
@Override @Override
public JSONObject clientWechatAppSignInByUnionId(String unionId) { public JSONObject clientWechatAppSignInByUnionId(String unionId) {
if (StringUtils.isBlank(unionId) || unionId == "" || unionId == null) { if (StringUtils.isBlank(unionId) || unionId == "" || unionId == null) {
@ -498,7 +509,7 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati
"company_phone", "suburb", "postcode", "state", "contact_person", "contact_phone", "contact_email", "short_name", "logo_url", "enable_refund", "company_phone", "suburb", "postcode", "state", "contact_person", "contact_phone", "contact_email", "short_name", "logo_url", "enable_refund",
"enable_refund_auth", "retail_surcharge", "require_custinfo", "require_remark", "logo_thumbnail", "creator", "create_time", "approver", "enable_refund_auth", "retail_surcharge", "require_custinfo", "require_remark", "logo_thumbnail", "creator", "create_time", "approver",
"approve_result", "approve_time", "open_status", "timezone", "has_children", "source", "customer_surcharge_rate", "enable_alipay", "enable_wechat", "approve_result", "approve_time", "open_status", "timezone", "has_children", "source", "customer_surcharge_rate", "enable_alipay", "enable_wechat",
"enable_bestpay", "manual_settle", "skip_clearing", "mail_confirm", "surcharge_mode", "company_photo", "store_photo", "company_website", "contact_job", "sub_manage","enable_rpaypmt_card","enable_rpaypmt_dd"}; "enable_bestpay", "manual_settle", "skip_clearing", "mail_confirm", "surcharge_mode", "company_photo", "store_photo", "company_website", "contact_job", "sub_manage", "enable_rpaypmt_card", "enable_rpaypmt_dd"};
for (String col : columns) { for (String col : columns) {
simpleClient.put(col, client.get(col)); simpleClient.put(col, client.get(col));
} }

@ -1,5 +1,6 @@
package au.com.royalpay.payment.manage.signin.core.impls; package au.com.royalpay.payment.manage.signin.core.impls;
import au.com.royalpay.payment.manage.appclient.beans.AppleLoginBean;
import au.com.royalpay.payment.manage.mappers.system.ClientAccountMapper; 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;
@ -10,6 +11,8 @@ import au.com.royalpay.payment.tools.exceptions.BadRequestException;
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 au.com.royalpay.payment.tools.utils.apple.AppleAuthUtils;
import au.com.royalpay.payment.tools.utils.apple.UserClaim;
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;
@ -38,7 +41,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
@Resource @Resource
private ClientAccountMapper clientAccountMapper; private ClientAccountMapper clientAccountMapper;
private final String CLIENT_LOGIN_WECHAT_BIND_PREFIX = "CLIENT_LOGIN_WECHAT_BIND_PREFIX"; private final String CLIENT_LOGIN_WECHAT_BIND_PREFIX = "CLIENT_LOGIN_WECHAT_BIND_PREFIX";
private final String CLIENT_LOGIN_PHONE_BIND_PREFIX = "CLIENT_LOGIN_PHONE_BIND_PREFIX"; private final String CLIENT_LOGIN_PHONE_BIND_PREFIX = "CLIENT_LOGIN_PHONE_BIND_PREFIX";
@Override @Override
public JSONObject getCurrentManager(String statusKey) { public JSONObject getCurrentManager(String statusKey) {
@ -63,9 +66,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
return null; return null;
} }
op.expire(30, TimeUnit.MINUTES); op.expire(30, TimeUnit.MINUTES);
return signInAccountService.getClient(accountId);
JSONObject account = signInAccountService.getClient(accountId);
return account;
} }
private String partnerLoginRedisKey(String statusKey) { private String partnerLoginRedisKey(String statusKey) {
@ -86,7 +87,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
JSONObject account = clientAccountMapper.findOneByPhoneAndCreateTimeDesc(phone, "+" + nationCode); JSONObject account = clientAccountMapper.findOneByPhoneAndCreateTimeDesc(phone, "+" + nationCode);
if (account == null) { if (account == null) {
String expireMin = "5"; String expireMin = "5";
stringRedisTemplate.boundValueOps(getClientLoginPhoneBindRedisKey(phone,nationCode)).set(phone, Long.parseLong(expireMin), TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(getClientLoginPhoneBindRedisKey(phone, nationCode)).set(phone, Long.parseLong(expireMin), TimeUnit.MINUTES);
return null; return null;
} }
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
@ -99,11 +100,14 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
@Override @Override
public String verifyClientAccountLogin(LoginInfo loginInfo, String verfiyType) { public String verifyClientAccountLogin(LoginInfo loginInfo, String verfiyType) {
JSONObject account = signInAccountService.clientAccountCheck(loginInfo);; JSONObject account = signInAccountService.clientAccountCheck(loginInfo);
if ("phone".equals(verfiyType)) { if ("phone".equals(verfiyType)) {
if (account.containsKey("contact_phone")) { if (account.containsKey("contact_phone")) {
throw new BadRequestException("The account has been linked to the phone number!"); throw new BadRequestException("The account has been linked to the phone number!");
} }
} else if (StringUtils.equalsIgnoreCase("apple", verfiyType)
&& StringUtils.isNotEmpty(account.getString("apple_userid"))) {
throw new BadRequestException("The account has been binded and exist appleId!");
} else { } else {
if (account.containsKey("wechat_openid")) { if (account.containsKey("wechat_openid")) {
throw new BadRequestException("The account has been linked to the wechat!"); throw new BadRequestException("The account has been linked to the wechat!");
@ -286,6 +290,31 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
return account; return account;
} }
@Override
public JSONObject mchAppleSignIn(AppleLoginBean appleLoginBean) {
UserClaim userClaim = AppleAuthUtils.verifyIdentifyToken(appleLoginBean.getIdentityToken());
if (!StringUtils.equalsIgnoreCase(userClaim.getSub(), appleLoginBean.getUser())) {
throw new ForbiddenException("apple userinfo is error");
}
JSONObject account = signInAccountService.clientAppleSignIn(userClaim.getSub());
if (account == null || account.isEmpty()) {
return new JSONObject() {{
put("apple_userid", userClaim.getSub());
put("bind_status", false);
}};
}
String statusKey = newStatusKey();
JSONObject result = new JSONObject();
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
account = getCurrentClient(statusKey);
account.put("sign_key", statusKey);
result.put("account", account);
account.put("apple_userid", userClaim.getSub());
result.put("bind_status", true);
result.put("status", "success");
return result;
}
@Override @Override
public String clientWechatSignIn(String openid) { public String clientWechatSignIn(String openid) {
JSONObject account = signInAccountService.clientWechatSignIn(openid); JSONObject account = signInAccountService.clientWechatSignIn(openid);
@ -391,21 +420,21 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
@Override @Override
public JSONObject clientAppWechatSignIn(String code) { public JSONObject clientAppWechatSignIn(String code) {
JSONObject user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(code); JSONObject user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(code);
if(user==null){ if (user == null) {
throw new BadRequestException("WeChat users do not exist"); throw new BadRequestException("WeChat users do not exist");
} }
String unionId = user.getString("unionid"); String unionId = user.getString("unionid");
String openId = user.getString("openid"); String openId = user.getString("openid");
JSONObject account = signInAccountService.clientWechatOneSignIn(unionId); JSONObject account = signInAccountService.clientWechatOneSignIn(unionId);
if (account == null) { if (account == null) {
JSONObject wechatUserInfo = mpClientAppWechatApiProvider.getApi("merchant-app").appUserInfo(openId,user.getString("access_token")); JSONObject wechatUserInfo = mpClientAppWechatApiProvider.getApi("merchant-app").appUserInfo(openId, user.getString("access_token"));
JSONObject res = new JSONObject(); JSONObject res = new JSONObject();
String nickName = wechatUserInfo.getString("nickname"); String nickName = wechatUserInfo.getString("nickname");
res.put("bind_status", false); res.put("bind_status", false);
res.put("app_openid", openId); res.put("app_openid", openId);
res.put("status", "success"); res.put("status", "success");
String expireMin = "5"; String expireMin = "5";
stringRedisTemplate.boundValueOps(getClientLoginWechatBindRedisKey(openId)).set(openId+"&"+nickName+"&"+unionId, Long.parseLong(expireMin), TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(getClientLoginWechatBindRedisKey(openId)).set(openId + "&" + nickName + "&" + unionId, Long.parseLong(expireMin), TimeUnit.MINUTES);
return res; return res;
} }
String statusKey = newStatusKey(); String statusKey = newStatusKey();
@ -413,20 +442,20 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES);
account = getCurrentClient(statusKey); account = getCurrentClient(statusKey);
account.put("sign_key", statusKey); account.put("sign_key", statusKey);
result.put("account",account); result.put("account", account);
result.put("app_openid", unionId); result.put("app_openid", unionId);
result.put("bind_status", true); result.put("bind_status", true);
result.put("status", "success"); result.put("status", "success");
return result; return result;
} }
private String getClientLoginWechatBindRedisKey(String openId){ private String getClientLoginWechatBindRedisKey(String openId) {
return "login:"+":"+CLIENT_LOGIN_WECHAT_BIND_PREFIX + "&"+openId; return "login:" + ":" + CLIENT_LOGIN_WECHAT_BIND_PREFIX + "&" + openId;
} }
@Override @Override
public JSONObject verifyClientLoginWechatBindCode(String openId){ public JSONObject verifyClientLoginWechatBindCode(String openId) {
String rediskey = getClientLoginWechatBindRedisKey(openId); String rediskey = getClientLoginWechatBindRedisKey(openId);
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get(); String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
if (codeValue == null || !codeValue.split("&")[0].equals(openId)) { if (codeValue == null || !codeValue.split("&")[0].equals(openId)) {
@ -435,18 +464,18 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
String nickName = codeValue.split("&")[1]; String nickName = codeValue.split("&")[1];
String unionId = codeValue.split("&")[2]; String unionId = codeValue.split("&")[2];
stringRedisTemplate.delete(rediskey); stringRedisTemplate.delete(rediskey);
return new JSONObject(){{ return new JSONObject() {{
put("nick_name",nickName); put("nick_name", nickName);
put("union_id",unionId); put("union_id", unionId);
}}; }};
} }
private String getClientLoginPhoneBindRedisKey(String phone,String nationCode){ private String getClientLoginPhoneBindRedisKey(String phone, String nationCode) {
return "login:"+CLIENT_LOGIN_PHONE_BIND_PREFIX + "&"+nationCode+"&"+phone; return "login:" + CLIENT_LOGIN_PHONE_BIND_PREFIX + "&" + nationCode + "&" + phone;
} }
public void verifyClientLoginPhoneBindCode(String phone,String nationCode){ public void verifyClientLoginPhoneBindCode(String phone, String nationCode) {
String rediskey = getClientLoginPhoneBindRedisKey(phone,nationCode); String rediskey = getClientLoginPhoneBindRedisKey(phone, nationCode);
String codeValue = stringRedisTemplate.boundValueOps(rediskey).get(); String codeValue = stringRedisTemplate.boundValueOps(rediskey).get();
if (codeValue == null || !codeValue.equals(phone)) { if (codeValue == null || !codeValue.equals(phone)) {
throw new BadRequestException("The phone number is for application binding"); throw new BadRequestException("The phone number is for application binding");
@ -455,7 +484,6 @@ public class SignInStatusManagerImpl implements SignInStatusManager {
} }
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);
} }

Loading…
Cancel
Save