diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java index 36bb7164d..6efc931a2 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailAppService.java @@ -188,10 +188,13 @@ public interface RetailAppService { void updateAccountEmail(JSONObject device,JSONObject codekey); - void bindAccountPhone(JSONObject device,JSONObject phone); + JSONObject bindAccountPhone(JSONObject device,JSONObject phone); - void updateAccountPhone(JSONObject device,JSONObject codekey); + JSONObject updateAccountPhone(JSONObject device,JSONObject codekey); + void updateLoginClientAccountPhone(JSONObject account,String contactPhone, String nationCode); + + void updateLoginClientAccountOpenId(JSONObject client,JSONObject params); /** * 退款密码 */ @@ -225,4 +228,13 @@ public interface RetailAppService { JSONObject getCustomerInfo(JSONObject device); boolean isSubPartner(JSONObject device, String clientMoniker); +<<<<<<< Updated upstream +======= + + JSONObject unbindAccountPhone(JSONObject device, JSONObject params); + + void unbindAccountWechat(JSONObject device); + + JSONObject bindAccountWechat(JSONObject device, JSONObject params); +>>>>>>> Stashed changes } diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java index 0c32d1df7..00d6ce5c9 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailAppServiceImp.java @@ -44,6 +44,7 @@ import au.com.royalpay.payment.manage.tradelog.core.TradeLogService; import au.com.royalpay.payment.manage.tradelog.refund.RefundService; import au.com.royalpay.payment.tools.cms.RoyalPayCMSSupport; import au.com.royalpay.payment.tools.connections.attachment.core.AttachmentClient; +import au.com.royalpay.payment.tools.connections.mpsupport.MpClientAppWechatApiProvider; import au.com.royalpay.payment.tools.device.DeviceSupport; import au.com.royalpay.payment.tools.device.message.AppMessage; import au.com.royalpay.payment.tools.device.message.AppMsgSender; @@ -200,6 +201,8 @@ public class RetailAppServiceImp implements RetailAppService { private SysClientLegalPersonMapper sysClientLegalPersonMapper; @Resource private StringRedisTemplate stringRedisTemplate; + @Resource + private MpClientAppWechatApiProvider mpClientAppWechatApiProvider; private final String CBBANK_AGGREGATE_FILE = "https://file.royalpay.com.au/open/2019/08/05/1564972204689_uwZvpTBjtLUMcN8c540xcZvux1Rd3O.pdf"; private final String IMG_AGGREGATE_FILE = "https://file.royalpay.com.au/open/2019/09/06/1567741055646_qeWC7kwqEwsJjRHisJSyAjqnB9nnnh.pdf"; @@ -2113,11 +2116,14 @@ public class RetailAppServiceImp implements RetailAppService { } @Override - public void bindAccountPhone(JSONObject device, JSONObject phone) { + public JSONObject bindAccountPhone(JSONObject device, JSONObject phone) { String codeKey = device.getString("account_id"); String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).get(); + JSONObject result = new JSONObject(); if (StringUtils.isNotEmpty(codeKeyValueRedis)) { - throw new BadRequestException("Captcha has been sent.Please check your phone or try again in 5 minutes."); + result.put("status","error"); + result.put("message","Captcha has been sent.Please check your phone or try again in 5 minutes."); + return result; } String codeKeyValue = RandomStringUtils.random(6, false, true); String nationCode = phone.getString("nation_code"); @@ -2128,35 +2134,133 @@ public class RetailAppServiceImp implements RetailAppService { String expireMin = "5"; param.add(expireMin); try { - smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, BIND_PHONE_TEMPLID, param, "RoyalPay", "", ""); +// smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, BIND_PHONE_TEMPLID, param, "RoyalPay", "", ""); + stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES); + result.put("status","success"); + result.put("code_Key_Value",codeKeyValue); } catch (Exception e) { e.printStackTrace(); - throw new ServerErrorException("Phone number is wrong.Please try again."); + result.put("status","error"); + result.put("message","Phone number is wrong.Please try again."); } - stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(codeKey)).set(codeKeyValue + "&" + nationCode + "&" + phoneNumber, Long.parseLong(expireMin), TimeUnit.MINUTES); + return result; } @Override - public void updateAccountPhone(JSONObject device, JSONObject params) { + public JSONObject updateAccountPhone(JSONObject device, JSONObject params) { String key = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get(); + JSONObject result = new JSONObject(); if (key == null) { - throw new BadRequestException("Captcha has expired"); + result.put("status","error"); + result.put("message","Captcha has expired"); + return result; } String captcha = key.split("&")[0]; String nation_code = key.split("&")[1]; String contact_phone = key.split("&")[2]; + if (!StringUtils.equals(captcha, params.getString("captcha"))) { - throw new BadRequestException("Verification code is wrong"); + result.put("status","error"); + result.put("message","Verification code is wrong"); + return result; + } + JSONObject account = clientAccountMapper.findByPhone(contact_phone, "+"+nation_code); + if(account!=null){ + result.put("status","error"); + result.put("message","Mobile phone number has been bound to other users, please unbind it before binding"); + return result; + } + + JSONObject updateAccount = new JSONObject(); + updateAccount.put("account_id", device.getString("account_id")); + updateAccount.put("contact_phone", contact_phone); + updateAccount.put("nation_code", "+" + nation_code); + clientAccountMapper.update(updateAccount); + deleteAccountPhoneKey(device.getString("account_id")); + result.put("status","success"); + return result; + } + + @Override + public void updateLoginClientAccountPhone(JSONObject account, String contactPhone, String nationCode){ + JSONObject updateAccount = new JSONObject(); + updateAccount.put("account_id",account.getString("account_id")); + updateAccount.put("contact_phone",contactPhone); + updateAccount.put("nation_code","+" + nationCode); + clientAccountMapper.update(updateAccount); + } + + @Override + public void updateLoginClientAccountOpenId(JSONObject account,JSONObject params){ + JSONObject updateAccount = new JSONObject(); + JSONObject queryAccount = account.getJSONObject("account"); + updateAccount.put("account_id",queryAccount.getString("account_id")); + updateAccount.put("wechat_openid",params.getString("wechat_openid")); + clientAccountMapper.update(updateAccount); + } + + @Override +<<<<<<< Updated upstream +======= + public JSONObject unbindAccountPhone(JSONObject device, JSONObject phone) { + + String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUpdateAccountPhoneKey(device.getString("account_id"))).get(); + JSONObject result = new JSONObject(); + if (codeKeyValueRedis == null) { + result.put("status","error"); + result.put("message","Captcha has expired"); + return result; + } + String captcha = codeKeyValueRedis.split("&")[0]; + if (!StringUtils.equals(captcha, phone.getString("captcha"))) { + result.put("status","error"); + result.put("message","Verification code is wrong"); + return result; } JSONObject account = new JSONObject(); account.put("account_id", device.getString("account_id")); - account.put("contact_phone", contact_phone); - account.put("nation_code", "+" + nation_code); + account.put("contact_phone", null); + account.put("nation_code", null); clientAccountMapper.update(account); deleteAccountPhoneKey(device.getString("account_id")); + result.put("status","success"); + return result; + } + + @Override + public void unbindAccountWechat(JSONObject device) { + JSONObject account = new JSONObject(); + account.put("account_id", device.getString("account_id")); + account.put("wechat_openid", null); + clientAccountMapper.update(account); + } + + @Override + public JSONObject bindAccountWechat(JSONObject device, JSONObject params){ + JSONObject user = mpClientAppWechatApiProvider.getApi("merchant-app").appLoginUser(params.getString("code")); + JSONObject result = new JSONObject(); + if(user==null){ + result.put("status","error"); + result.put("message","WeChat users do not exist"); + return result; + } + String openId = user.getString("openid"); + JSONObject account = clientAccountMapper.findByOpenId(openId); + if(account!=null){ + result.put("status","error"); + result.put("message","WeChat ID has been bound to other accounts, please unbind it before binding"); + return result; + } + JSONObject updateAccount = new JSONObject(); + updateAccount.put("account_id", device.getString("account_id")); + updateAccount.put("wechat_openid", openId); + clientAccountMapper.update(updateAccount); + result.put("status","success"); + return result; } @Override +>>>>>>> Stashed changes public void verifyRefundPassword(JSONObject device, JSONObject json) { String clientType = device.getString("client_type"); deviceSupport.findRegister(clientType); diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java index 56b24df82..523d44b47 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailAppController.java @@ -57,7 +57,7 @@ import static au.com.royalpay.payment.tools.CommonConsts.RETAIL_DEVICE; /** * Created by yishuqian on 28/03/2017. */ -@AppClientController +@RestController @RequestMapping("/api/v1.0/retail/app") public class RetailAppController { Logger logger = LoggerFactory.getLogger(getClass()); @@ -722,8 +722,9 @@ public class RetailAppController { * @throws Exception */ @PutMapping("/account/phone") - public void bindAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject phone) throws Exception { - retailAppService.bindAccountPhone(device, phone); + public JSONObject bindAccountPhone(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject phone) throws Exception { + JSONObject deviceInfo = JSONObject.parseObject(device); + return retailAppService.bindAccountPhone(deviceInfo, phone); } /** @@ -734,11 +735,57 @@ public class RetailAppController { * @throws Exception */ @PutMapping("/account/phone/bind") - public void updateAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) throws Exception { - retailAppService.updateAccountPhone(device, params); +// @ModelAttribute(RETAIL_DEVICE) JSONObject device, + public JSONObject updateAccountPhone(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject params) throws Exception { + JSONObject deviceInfo = JSONObject.parseObject(device); + return retailAppService.updateAccountPhone(deviceInfo, params); } /** +<<<<<<< Updated upstream +======= + * 解绑关联手机 + * + * @param device + * @param params 验证码 + * @throws Exception + */ + @PutMapping("/account/phone/unbind") +// @ModelAttribute(RETAIL_DEVICE) JSONObject device, + public JSONObject unbindAccountPhone(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject params) throws Exception { + JSONObject deviceInfo = JSONObject.parseObject(device); + return retailAppService.unbindAccountPhone(deviceInfo, params); + } + + /** + * 微信绑定 + * @param device + * @param params + */ + @PutMapping("/account/wechat/bind") +// @ModelAttribute(RETAIL_DEVICE) JSONObject device, + public JSONObject bindAccountWechat(@RequestHeader("X-Device-Info") String device, @RequestBody JSONObject params){ + JSONObject deviceInfo = JSONObject.parseObject(device); + return retailAppService.bindAccountWechat(deviceInfo,params); + } + + + /** + * 微信解绑 + * @param device + */ + @PutMapping("/account/wechat/unbind") +// @ModelAttribute(RETAIL_DEVICE) JSONObject device, + public void unbindAccountWechat(@RequestHeader("X-Device-Info") String device){ + JSONObject deviceInfo = JSONObject.parseObject(device); + retailAppService.unbindAccountWechat(deviceInfo); + } + + + + + /** +>>>>>>> Stashed changes * 验证退款密码 */ @PutMapping("/refund/passwd/verify") diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailValidationController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailValidationController.java index 7f544e030..e662cf8cb 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailValidationController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RetailValidationController.java @@ -1,11 +1,20 @@ package au.com.royalpay.payment.manage.appclient.web; 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.RetailAppService; import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; +<<<<<<< Updated upstream import au.com.royalpay.payment.tools.CommonConsts; import au.com.royalpay.payment.tools.device.DeviceSupport; import au.com.royalpay.payment.tools.device.ManageDeviceSupport; +======= +import au.com.royalpay.payment.manage.signin.events.ClientLoginEvent; +import au.com.royalpay.payment.tools.CommonConsts; +import au.com.royalpay.payment.tools.device.DeviceSupport; +import au.com.royalpay.payment.tools.device.ManageDeviceSupport; +import au.com.royalpay.payment.tools.env.RequestEnvironment; +>>>>>>> Stashed changes import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.http.HttpUtils; import au.com.royalpay.payment.tools.locale.LocaleSupport; @@ -17,6 +26,11 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.RandomStringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +<<<<<<< Updated upstream +======= +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.ApplicationEventPublisherAware; +>>>>>>> Stashed changes import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.*; @@ -44,6 +58,21 @@ public class RetailValidationController { private ManageDeviceSupport manageDeviceSupport; @Resource private RetailAppService retailAppService; +<<<<<<< Updated upstream +======= + @Resource + private ClientManager clientManager; + @Resource + private SimpleClientApplyService simpleClientApplyService; + private ApplicationEventPublisher publisher; + @Resource + private ManageAppService manageAppService; + + @Override + public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { + this.publisher = applicationEventPublisher; + } +>>>>>>> Stashed changes @PostMapping("/devices/{devType}/register") public JSONObject register(@RequestBody String registeration, @PathVariable String devType) { @@ -151,4 +180,139 @@ public class RetailValidationController { public JSONObject getAdDetail(@PathVariable String article_id) { return retailAppService.getAdDetail( article_id); } +<<<<<<< Updated upstream +======= + + + /** + * 登录发送手机验证码 + * + * @param phoneNumber + * @param nationCode + * @param request + * @return + */ + @PostMapping("/send/{phone_number}/verify_code") + @ResponseBody + public String sendLoginMobileVerifyCode(@PathVariable("phone_number") String phoneNumber, + @RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode, + HttpServletRequest request) { + return simpleClientApplyService.getAndSendLoginSmsCode(phoneNumber, nationCode, request); + } + + /** + * 登录校验手机验证 + * + * @param contactPhone + * @param nationCode + * @param params + */ + @PostMapping("/login/verify/{contact_phone}/verify_code") + public JSONObject verifyLoginMobileCode(@PathVariable("contact_phone") String contactPhone, + @RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode, + @RequestBody JSONObject params, + @ModelAttribute(CommonConsts.MANAGER_DEVICE) JSONObject device, + Errors errors) { + HttpUtils.handleValidErrors(errors); + if (params.getString("verify_code").isEmpty() && params.getString("verify_code") == null) { + throw new BadRequestException("verify code can't be null"); + } + simpleClientApplyService.verifyLoginSMSCode(params.getString("verify_code"), contactPhone); + nationCode = nationCode; + JSONObject result = new JSONObject(); + JSONObject signKeyResult = signInStatusManager.getClientInfoByPhoneStatusKey(contactPhone, nationCode); + if(signKeyResult.getBoolean("account_exist")){ + JSONObject client = signInStatusManager.getCurrentClient(signKeyResult.getString("status_key")); + client = JSON.parseObject(client.toJSONString()); + if (params.getString("devId") != null) { + deviceSupport.validDeviceWithClient(client, params.getString("devId")); + } + result=client; + result.put("sign_key", signKeyResult.getString("status_key")); + result.put("bind_status", true); + this.publisher.publishEvent(new ClientLoginEvent(this, client.getIntValue("client_id"), client.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE")); + }else{ + result.put("bind_status", false); + result.put("contact_phone",contactPhone); + result.put("nation_code",nationCode); + } + return result; + } + + /** + * 手机登录-绑定账号 + * @param contactPhone + * @param nationCode + * @param params + */ + @PostMapping("/login/mobile/{contact_phone}/bind") + public JSONObject mobileLoginBind(@PathVariable("contact_phone")String contactPhone, + @RequestParam("nation_code") @NotEmpty(message = "nation code can't be null") String nationCode, + @RequestBody JSONObject params, + Errors errors){ + HttpUtils.handleValidErrors(errors); + LoginInfo loginInfo = new LoginInfo(); + loginInfo.setLoginId(params.getString("loginId")); + loginInfo.setPassword(params.getString("password")); + JSONObject signKey = signInStatusManager.verifyClientAccountLogin(loginInfo,"phone"); + JSONObject client = signInStatusManager.getCurrentClient(signKey); + retailAppService.updateLoginClientAccountPhone(client, contactPhone,nationCode); + client = JSON.parseObject(client.toJSONString()); + if (params.getString("devId") != null) { + deviceSupport.validDeviceWithClient(client, params.getString("devId")); + } + client.put("sign_key", signKey); + client.put("bind_status", true); + this.publisher.publishEvent(new ClientLoginEvent(this, client.getIntValue("client_id"), client.getString("account_id"), RequestEnvironment.getClientIp(), "MOBILE")); + return client; + } + + /** + * 商戶端App微信授权登录 + * @param data + * @return + */ + @PostMapping("/client_app_wechat_signin") + public JSONObject clientAppWechatSignIn(@RequestBody JSONObject data, + Errors errors) { + HttpUtils.handleValidErrors(errors); + JSONObject res = signInStatusManager.clientAppWechatSignIn(data.getString("code")); + if (!res.getBooleanValue("not_exists")) { + deviceSupport.validDeviceWithClient(res, res.getString("app_openid")); + this.publisher.publishEvent(new ClientLoginEvent(this, res.getIntValue("client_id"), res.getString("account_id"), RequestEnvironment.getClientIp(), "wechat")); + } + return res; + } + + /** + * 微信绑定登录账号 + * @param params + * @return + */ + @PostMapping("/login/wechat_bind") + public JSONObject wechatLoginBind(@RequestBody JSONObject params){ + LoginInfo loginInfo = new LoginInfo(); + loginInfo.setLoginId(params.getString("loginId")); + loginInfo.setPassword(params.getString("password")); + JSONObject signKeyResult = signInStatusManager.verifyClientAccountLogin(loginInfo,"wechat"); + if("error".equals(signKeyResult.getString("status"))){ + return signKeyResult; + } + JSONObject client = signInStatusManager.getCurrentClient(signKeyResult.getString("status_key")); + if("error".equals(client.getString("status"))){ + return client; + } + retailAppService.updateLoginClientAccountOpenId(client,params); + client = JSON.parseObject(client.toJSONString()); + if (params.getString("devId") != null) { + deviceSupport.validDeviceWithClient(client, params.getString("devId")); + } + client.put("sign_key", signKeyResult.getString("status_key")); + client.put("bind_status", true); + client.put("status","success"); + this.publisher.publishEvent(new ClientLoginEvent(this, client.getIntValue("client_id"), client.getString("account_id"), RequestEnvironment.getClientIp(), "wechat")); + return client; + } + +>>>>>>> Stashed changes } diff --git a/src/main/java/au/com/royalpay/payment/manage/signin/core/SignInAccountService.java b/src/main/java/au/com/royalpay/payment/manage/signin/core/SignInAccountService.java index 8d18e669e..eca9d972b 100644 --- a/src/main/java/au/com/royalpay/payment/manage/signin/core/SignInAccountService.java +++ b/src/main/java/au/com/royalpay/payment/manage/signin/core/SignInAccountService.java @@ -28,6 +28,8 @@ public interface SignInAccountService { JSONObject clientLoginCheck(LoginInfo loginInfo); + JSONObject clientAccountCheck(LoginInfo loginInfo); + void changeManagerPassword(JSONObject manager, ChangePwdBean change); void changeAccountPassword(JSONObject partnerStatus, ChangePwdBean change); @@ -59,4 +61,5 @@ public interface SignInAccountService { void deleteManagerCodeKey(String codekey); JSONObject checkAuthFileStatus(JSONObject client); + } diff --git a/src/main/java/au/com/royalpay/payment/manage/signin/core/SignInStatusManager.java b/src/main/java/au/com/royalpay/payment/manage/signin/core/SignInStatusManager.java index df81168df..3b8e2e797 100644 --- a/src/main/java/au/com/royalpay/payment/manage/signin/core/SignInStatusManager.java +++ b/src/main/java/au/com/royalpay/payment/manage/signin/core/SignInStatusManager.java @@ -67,4 +67,29 @@ public interface SignInStatusManager { void scanCustomerQrcode(String codeId, String openid); String getWechatCustomerId(String codeId); +<<<<<<< Updated upstream +======= + + /** + * 商户端App微信授权 + * @param code + * @return + */ + JSONObject clientAppWechatSignIn(String code); + + /** + * 手机号登录 + * @param phone + * @param nationCode + * @return + */ + JSONObject getClientInfoByPhoneStatusKey(String phone,String nationCode); + + /** + * 登录绑定校验用户名密码 + * @param loginInfo + * @return + */ + JSONObject verifyClientAccountLogin(LoginInfo loginInfo,String verfiyType); +>>>>>>> Stashed changes } diff --git a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java index bf53b4cb7..c3e4f554f 100644 --- a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInAccountServiceImpl.java @@ -267,6 +267,13 @@ public class SignInAccountServiceImpl implements SignInAccountService, Applicati return account; } + @Override + public JSONObject clientAccountCheck(LoginInfo loginInfo) { + JSONObject account = clientAccountMapper.findByUsername(loginInfo.getLoginId()); + validLoginInfo(loginInfo, account); + return account; + } + @Override public void changeManagerPassword(JSONObject manager, ChangePwdBean change) { manager = managerMapper.findDetail(manager.getString("manager_id")); diff --git a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInStatusManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInStatusManagerImpl.java index 5ed1d62a3..a15e6c1b2 100644 --- a/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInStatusManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/signin/core/impls/SignInStatusManagerImpl.java @@ -5,6 +5,7 @@ import au.com.royalpay.payment.manage.signin.core.SignInAccountService; import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; import au.com.royalpay.payment.tools.connections.mpsupport.WechatAppApi; import au.com.royalpay.payment.tools.env.PlatformEnvironment; +import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.ForbiddenException; import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.utils.QRCodeUtils; @@ -61,7 +62,22 @@ public class SignInStatusManagerImpl implements SignInStatusManager { return null; } op.expire(30, TimeUnit.MINUTES); - return signInAccountService.getClient(accountId); + JSONObject result = new JSONObject(); + + try{ + JSONObject account = signInAccountService.getClient(accountId); + if(account.containsKey("wechat_openid")){ + result.put("status","error"); + result.put("account","The account has been bound to WeChat, please unbind it before binding"); + }else{ + result.put("status","success"); + result.put("account",account); + } + }catch (ForbiddenException e){ + result.put("status","error"); + result.put("message",e.getMessage()); + } + return result; } private String partnerLoginRedisKey(String statusKey) { @@ -76,10 +92,52 @@ public class SignInStatusManagerImpl implements SignInStatusManager { return statusKey; } +<<<<<<< Updated upstream +======= + @Override + public JSONObject getClientInfoByPhoneStatusKey(String phone,String nationCode) { + JSONObject result = new JSONObject(); + String statusKey = newStatusKey(); + JSONObject account = clientAccountMapper.findByPhone(phone, "+"+nationCode); + if(account==null){ + result.put("account_exist",false); + return result; + } + result.put("account_exist",true); + result.put("status_key",statusKey); + stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set(account.getString("account_id") + "", 30, TimeUnit.MINUTES); + return result; + } + +>>>>>>> Stashed changes private String newStatusKey() { return Long.toHexString(System.currentTimeMillis()) + "_" + RandomStringUtils.random(20, true, true); } + @Override + public JSONObject verifyClientAccountLogin(LoginInfo loginInfo,String verfiyType){ + JSONObject account = signInAccountService.clientAccountCheck(loginInfo); + JSONObject result = new JSONObject(); + if("phone".equals(verfiyType)){ + if(account.containsKey("contact_phone")){ + result.put("status","error"); + result.put("message","The account has been linked to the phone number!"); + return result; + } + }else{ + if(account.containsKey("wechat_openid")){ + result.put("status","error"); + result.put("message","The account has been linked to the wechat!"); + return result; + } + } + String statusKey = newStatusKey(); + stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set("" + account.getString("account_id"), 30, TimeUnit.MINUTES); + result.put("status","success"); + result.put("status_key",statusKey); + return result; + } + @Override public String managerSignIn(LoginInfo loginInfo) { JSONObject manager = signInAccountService.managerLoginCheck(loginInfo); @@ -344,6 +402,36 @@ public class SignInStatusManagerImpl implements SignInStatusManager { return statusKey; } +<<<<<<< Updated upstream +======= + @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); + String statusKey = newStatusKey(); + if (account == null) { + account = signInAccountService.clientWechatAppSignInByUnionId(unionId); + if (account == null) { + JSONObject res = new JSONObject(); + res.put("bind_status", false); + res.put("app_openid", openId); + res.put("status","success"); + return res; + } + } + + 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); + account.put("status","success"); + return account; + } + +>>>>>>> Stashed changes private void lockRandomCodeId(String codeId) { stringRedisTemplate.boundValueOps(redisPrefix + "partner_signin" + codeId).set(codeId, 30, TimeUnit.SECONDS);