From ed2acd46a86e64f4466fa9af408ac10f570d0391 Mon Sep 17 00:00:00 2001 From: duLingLing Date: Tue, 22 Oct 2019 11:29:21 +0800 Subject: [PATCH] =?UTF-8?q?Add:=E6=89=8B=E6=9C=BA=E3=80=81=E5=BE=AE?= =?UTF-8?q?=E4=BF=A1=E7=99=BB=E5=BD=95?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../appclient/beans/MobileLoginInfo.java | 34 +++++++ .../appclient/core/RetailAppService.java | 2 + .../core/impls/RetailAppServiceImp.java | 29 ++++++ .../appclient/web/RetailAppController.java | 14 +++ .../web/RetailValidationController.java | 97 ++++++++++++++++++- .../core/SimpleClientApplyService.java | 6 ++ .../impls/SimpleClientApplyServiceImpl.java | 50 ++++++++++ .../signin/core/SignInStatusManager.java | 17 ++++ .../core/impls/SignInStatusManagerImpl.java | 63 +++++++++--- .../wechatclients/MerchantAppWechatImpl.java | 28 ++++++ 10 files changed, 320 insertions(+), 20 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/appclient/beans/MobileLoginInfo.java create mode 100644 src/main/java/au/com/royalpay/payment/manage/support/wechatclients/MerchantAppWechatImpl.java diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/beans/MobileLoginInfo.java b/src/main/java/au/com/royalpay/payment/manage/appclient/beans/MobileLoginInfo.java new file mode 100644 index 000000000..db009ec6c --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/beans/MobileLoginInfo.java @@ -0,0 +1,34 @@ +package au.com.royalpay.payment.manage.appclient.beans; + +import au.com.royalpay.payment.manage.signin.beans.LoginInfo; + +import javax.validation.constraints.NotEmpty; + +/** + * @Author DuLingLing + * @create 2019/10/18 0018 18:14 + */ +public class MobileLoginInfo { + + public String getVerifyCode() { + return verifyCode; + } + + public void setVerifyCode(String verifyCode) { + this.verifyCode = verifyCode; + } + + @NotEmpty(message = "error.payment.valid.param_missing") + private String verifyCode; + private String devId; + + + public LoginInfo toLoginInfo(String username){ + LoginInfo info = new LoginInfo(); + info.setLoginId(username); +// info.setPassword(password); + info.setVerifyCode(verifyCode); + return info; + } + +} 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..9fd4b43e3 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 @@ -225,4 +225,6 @@ public interface RetailAppService { JSONObject getCustomerInfo(JSONObject device); boolean isSubPartner(JSONObject device, String clientMoniker); + + void unbindAccountPhone(JSONObject device, JSONObject params); } 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..f4eac5749 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 @@ -207,6 +207,7 @@ public class RetailAppServiceImp implements RetailAppService { private SmsSender smsSender; private final String BIND_ACCOUNT_EMAIL_PREFIX = "BIND_ACCOUNT_EMAIL"; private final String BIND_ACCOUNT_PHONE_PREFIX = "BIND_ACCOUNT_PHONE"; + private final String UNBIND_ACCOUNT_PHONE_PREFIX = "UHBIND_ACCOUNT_PHONE"; private final int BIND_PHONE_TEMPLID = 126978; private Map senderMap = new HashMap<>(); @@ -2156,6 +2157,24 @@ public class RetailAppServiceImp implements RetailAppService { deleteAccountPhoneKey(device.getString("account_id")); } + @Override + public void unbindAccountPhone(JSONObject device, JSONObject phone) { + String codeKeyValueRedis = stringRedisTemplate.boundValueOps(getUnbindAccountPhoneKey(device.getString("account_id"))).get(); + if (codeKeyValueRedis == null) { + throw new BadRequestException("Captcha has expired"); + } + String captcha = codeKeyValueRedis.split("&")[0]; + if (!StringUtils.equals(captcha, phone.getString("captcha"))) { + throw new BadRequestException("Verification code is wrong"); + } + JSONObject account = new JSONObject(); + account.put("account_id", device.getString("account_id")); + account.put("contact_phone", ""); + account.put("nation_code", ""); + clientAccountMapper.update(account); + deleteUnbindAccountPhoneKey(device.getString("account_id")); + } + @Override public void verifyRefundPassword(JSONObject device, JSONObject json) { String clientType = device.getString("client_type"); @@ -2462,6 +2481,8 @@ public class RetailAppServiceImp implements RetailAppService { return (listSubClients.contains(client.getString("client_id")) && deviceClient.getBooleanValue("sub_manage")); } + + private void exportCBBankAggregateFile(JSONObject client, HttpServletResponse httpResponse) { httpResponse.setContentType("application/pdf"); httpResponse.setHeader("content-disposition", "attachment;filename=" + client.getString("client_moniker") + "_AGREEMENT_" + new Date() + ".pdf"); @@ -2514,6 +2535,14 @@ public class RetailAppServiceImp implements RetailAppService { return BIND_ACCOUNT_PHONE_PREFIX + codeKey; } + private String getUnbindAccountPhoneKey(String codeKey) { + return UNBIND_ACCOUNT_PHONE_PREFIX + codeKey; + } + + private void deleteUnbindAccountPhoneKey(String codeKey) { + stringRedisTemplate.delete(getUnbindAccountPhoneKey(codeKey)); + } + private JSONObject getBankAccountByClientId(int client_id) { List list = clientBankAccountMapper.clientBankAccounts(client_id); return list.isEmpty() ? new JSONObject() : list.get(0); 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..164a2910e 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 @@ -738,6 +738,20 @@ public class RetailAppController { retailAppService.updateAccountPhone(device, params); } + /** + * 解绑关联手机 + * + * @param device + * @param params 验证码 + * @throws Exception + */ + @PutMapping("/account/phone/unbind") + public void unbindAccountPhone(@ModelAttribute(RETAIL_DEVICE) JSONObject device, @RequestBody JSONObject params) throws Exception { + retailAppService.unbindAccountPhone(device, params); + } + + + /** * 验证退款密码 */ 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..0df2be435 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 @@ -2,10 +2,15 @@ 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.RetailAppService; +import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService; +import au.com.royalpay.payment.manage.merchants.core.ClientManager; +import au.com.royalpay.payment.manage.signin.beans.LoginInfo; import au.com.royalpay.payment.manage.signin.core.SignInStatusManager; -import au.com.royalpay.payment.tools.CommonConsts; +import au.com.royalpay.payment.manage.signin.events.ClientLoginEvent; import au.com.royalpay.payment.tools.device.DeviceSupport; import au.com.royalpay.payment.tools.device.ManageDeviceSupport; +import au.com.royalpay.payment.tools.env.PlatformEnvironment; +import au.com.royalpay.payment.tools.env.RequestEnvironment; 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,12 +22,17 @@ import org.apache.commons.codec.binary.Base64; import org.apache.commons.lang3.RandomStringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.context.ApplicationEvent; +import org.springframework.context.ApplicationEventPublisher; +import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.*; import javax.annotation.Resource; import javax.imageio.ImageIO; +import javax.servlet.http.HttpServletRequest; import javax.validation.Valid; +import javax.validation.constraints.NotEmpty; import java.awt.image.BufferedImage; import java.io.ByteArrayOutputStream; import java.io.IOException; @@ -32,8 +42,8 @@ import java.io.IOException; */ @RestController @RequestMapping("/api/v1.0/retail_valid") -public class RetailValidationController { - Logger logger = LoggerFactory.getLogger(getClass()); +public class RetailValidationController implements ApplicationEventPublisherAware { + Logger logger = LoggerFactory.getLogger(getClass()); @Resource private Producer captchaProducer; @Resource @@ -44,6 +54,16 @@ public class RetailValidationController { private ManageDeviceSupport manageDeviceSupport; @Resource private RetailAppService retailAppService; + @Resource + private ClientManager clientManager; + @Resource + private SimpleClientApplyService simpleClientApplyService; + private ApplicationEventPublisher publisher; + + @Override + public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) { + this.publisher = applicationEventPublisher; + } @PostMapping("/devices/{devType}/register") public JSONObject register(@RequestBody String registeration, @PathVariable String devType) { @@ -149,6 +169,75 @@ public class RetailValidationController { @GetMapping("/ads/{article_id}") public JSONObject getAdDetail(@PathVariable String article_id) { - return retailAppService.getAdDetail( article_id); + return retailAppService.getAdDetail(article_id); } + + + /** + * 登录发送手机验证码 + * + * @param phoneNumber + * @param nationCode + * @param request + * @return + */ + @PostMapping("/send/{phoneNumber}/verify_code") + @ResponseBody + public String sendLoginMobileVerifyCode(@PathVariable("phoneNumber") @NotEmpty(message = "phone number can't be null") String phoneNumber, + @RequestParam("nationCode") @NotEmpty(message = "nation code can't be null") String nationCode, + HttpServletRequest request) { + return simpleClientApplyService.getAndSendLoginSmsCode(phoneNumber, nationCode, request); + } + + /** + * 登录校验手机验证 + * + * @param phoneNumber + * @param nationCode + * @param params + */ + @PostMapping("/login/verify/{phoneNumber}/verify_code") + public JSONObject verifyLoginMobileCode(@PathVariable("phoneNumber") @NotEmpty(message = "phone number can't be null") String phoneNumber, + @RequestParam("nationCode") @NotEmpty(message = "nation code can't be null") String nationCode, + @RequestBody JSONObject params) { + if (params.getString("codeKey").isEmpty() && params.getString("codeKey") == null) { + throw new BadRequestException("verify code can't be null"); + } + simpleClientApplyService.verifyLoginSMSCode(params.getString("codeKey"), phoneNumber); + nationCode = "+"+nationCode; + JSONObject result = new JSONObject(); + String signKey = signInStatusManager.getClientInfoByPhoneStatusKey(phoneNumber, nationCode); + JSONObject client = signInStatusManager.getCurrentClient(signKey); + client = JSON.parseObject(client.toJSONString()); + if (params.getString("devId") != null) { + deviceSupport.validDeviceWithClient(client, params.getString("devId")); + } + if(client!=null){ + result =client; + client.put("sign_key", signKey); + 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); + } + + return result; + } + + /** + * 商戶端App微信授权登录 + * @param data + * @return + */ + @PostMapping("/client_app_wechat_signin") + public JSONObject clientAppWechatSignIn(@RequestBody JSONObject data) { + 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; + } + + } diff --git a/src/main/java/au/com/royalpay/payment/manage/application/core/SimpleClientApplyService.java b/src/main/java/au/com/royalpay/payment/manage/application/core/SimpleClientApplyService.java index 2e7c43c13..0bcb9a8c3 100644 --- a/src/main/java/au/com/royalpay/payment/manage/application/core/SimpleClientApplyService.java +++ b/src/main/java/au/com/royalpay/payment/manage/application/core/SimpleClientApplyService.java @@ -35,4 +35,10 @@ public interface SimpleClientApplyService { void subscribeNewsletter(String mail, String lang); + //region 手机登录验证 + String getAndSendLoginSmsCode(String phoneNumber, String nationCode, HttpServletRequest request); + + void verifyLoginSMSCode(String codeKey, String phoneNumber); + //endregion + } diff --git a/src/main/java/au/com/royalpay/payment/manage/application/core/impls/SimpleClientApplyServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/application/core/impls/SimpleClientApplyServiceImpl.java index 402837155..c51af4172 100644 --- a/src/main/java/au/com/royalpay/payment/manage/application/core/impls/SimpleClientApplyServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/application/core/impls/SimpleClientApplyServiceImpl.java @@ -104,6 +104,8 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService { private final String REGISTER_CLIENT_PREFIX = "REGISTER_CLIENT"; private final String REGISTER_CLIENT_PROCESS_PREFIX = "REGISTER_CLIENT_PROCESS"; private final String VERIFY_MAIL_PREFIX = "VERIFY_MAIL"; + private final String LOGIN_CLIENT_PREFIX = "LGOIN_CLIENT"; + private final String LOGIN_CLIENT_PROCESS_PREFIX = "LOGIN_CLIENT_PROCESS"; private final List tags = new ArrayList<>(); @PostConstruct @@ -533,7 +535,55 @@ public class SimpleClientApplyServiceImpl implements SimpleClientApplyService { return REGISTER_CLIENT_PROCESS_PREFIX + codeKey; } + + //region 手机登录 + @Override + public String getAndSendLoginSmsCode(String phoneNumber, String nationCode, HttpServletRequest request) { + String reidsCheckCodeKey = getLoginClientRedisKey(phoneNumber); + String value = stringRedisTemplate.boundValueOps(reidsCheckCodeKey).get(); + if (StringUtils.isNotEmpty(value)) { + throw new BadRequestException("SMS has been sent,Please check your messages or try again in 3 minutes."); + } + ArrayList param = new ArrayList<>(); + String registerClientCode = RandomStringUtils.random(6, false, true); + param.add("RoyalPay"); + param.add(registerClientCode); + String expireMin = "3"; + param.add(expireMin); + try { + /* if(request.getLocales().nextElement().equals(Locale.CHINESE)|| request.getLocales().nextElement().equals(Locale.SIMPLIFIED_CHINESE)){ + smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID, param, "RoyalPay", "", ""); + }else{ + smsSender.getSender().sendWithParam(nationCode.trim(), phoneNumber, REGISTER_CLIENT_TEMPLID_ENGLISH, param, "RoyalPay", "", ""); + }*/ + } catch (Exception e) { + e.printStackTrace(); + throw new ServerErrorException("Phone number is wrong Please try again"); + } + stringRedisTemplate.boundValueOps(getLoginClientRedisKey(phoneNumber)).set(registerClientCode, Long.parseLong(expireMin), TimeUnit.MINUTES); + return registerClientCode; + } + + @Override + public void verifyLoginSMSCode(String codeKey, String phoneNumber) { + String rediskey = getLoginClientRedisKey(phoneNumber); + String codeValue = stringRedisTemplate.boundValueOps(rediskey).get(); + if (codeValue == null || !codeValue.equals(codeKey)) { + throw new BadRequestException("Verification code has expired or is not correct"); + } + stringRedisTemplate.delete(rediskey); + } + private String getVerifyMailRedisKey(String codekey) { return VERIFY_MAIL_PREFIX + codekey; } + + private String getLoginClientRedisKey(String phoneNumber){ + return LOGIN_CLIENT_PREFIX + phoneNumber; + } + + private String getLoginClientProcessRedisKey(String codeKey) { + return LOGIN_CLIENT_PROCESS_PREFIX + codeKey; + } + //endregion } 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..f68dbc572 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,21 @@ public interface SignInStatusManager { void scanCustomerQrcode(String codeId, String openid); String getWechatCustomerId(String codeId); + + /** + * 商户端App微信授权 + * @param code + * @return + */ + JSONObject clientAppWechatSignIn(String code); + + /** + * 手机号登录 + * @param phone + * @param nationCode + * @return + */ + String getClientInfoByPhoneStatusKey(String phone,String nationCode); + + } 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..8dfb2f1f7 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 @@ -1,16 +1,15 @@ 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.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.connections.mpsupport.MpClientAppWechatApiProvider; import au.com.royalpay.payment.tools.env.PlatformEnvironment; 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; - import com.alibaba.fastjson.JSONObject; - import org.apache.commons.lang3.RandomStringUtils; import org.apache.commons.lang3.StringUtils; 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.web.servlet.ModelAndView; -import java.util.concurrent.TimeUnit; -import java.util.logging.Logger; - import javax.annotation.Resource; +import java.util.concurrent.TimeUnit; /** * Created by yixian on 2016-06-29. @@ -36,7 +33,9 @@ public class SignInStatusManagerImpl implements SignInStatusManager { @Resource private SignInAccountService signInAccountService; @Resource - private WechatAppApi wechatAppApi; + private MpClientAppWechatApiProvider mpClientAppWechatApiProvider; + @Resource + private ClientAccountMapper clientAccountMapper; @Override public JSONObject getCurrentManager(String statusKey) { @@ -76,6 +75,14 @@ public class SignInStatusManagerImpl implements SignInStatusManager { 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() { 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(); JSONObject res = new JSONObject(); 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; } @@ -231,13 +238,13 @@ public class SignInStatusManagerImpl implements SignInStatusManager { @Override public JSONObject partnerWechatAppSignIn(String code) { - JSONObject user = wechatAppApi.appLoginUser(code); + JSONObject user = mpClientAppWechatApiProvider.getApi("clientapp").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){ + account = signInAccountService.clientWechatAppSignInByUnionId(unionId); + if (account == null) { JSONObject res = new JSONObject(); res.put("not_exists", true); res.put("app_openid", openId); @@ -265,7 +272,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager { String codeId = "client_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis(); JSONObject res = new JSONObject(); 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); return res; } @@ -275,13 +282,13 @@ public class SignInStatusManagerImpl implements SignInStatusManager { String codeId = "app_" + RandomStringUtils.random(20, true, true) + "_" + System.currentTimeMillis(); JSONObject res = new JSONObject(); 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); return res; } @Override - public void clientQRCodeAppSignIn(JSONObject device,String codeId) { + public void clientQRCodeAppSignIn(JSONObject device, String codeId) { getlockRandomCodeId(codeId); String statusKey = newStatusKey(); JSONObject account = new JSONObject(); @@ -296,7 +303,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager { } @Override - public void clientQRCodeWechatSignIn(JSONObject wxUser,String codeId) { + public void clientQRCodeWechatSignIn(JSONObject wxUser, String codeId) { getlockRandomCodeId(codeId); String statusKey = newStatusKey(); JSONObject account = new JSONObject(); @@ -325,7 +332,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager { String codeId = "customer_" + RandomStringUtils.random(15, true, true) + "_" + System.currentTimeMillis(); JSONObject res = new JSONObject(); 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; } @@ -344,6 +351,30 @@ public class SignInStatusManagerImpl implements SignInStatusManager { 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) { stringRedisTemplate.boundValueOps(redisPrefix + "partner_signin" + codeId).set(codeId, 30, TimeUnit.SECONDS); diff --git a/src/main/java/au/com/royalpay/payment/manage/support/wechatclients/MerchantAppWechatImpl.java b/src/main/java/au/com/royalpay/payment/manage/support/wechatclients/MerchantAppWechatImpl.java new file mode 100644 index 000000000..a0cbead02 --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/support/wechatclients/MerchantAppWechatImpl.java @@ -0,0 +1,28 @@ +package au.com.royalpay.payment.manage.support.wechatclients; + +import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi; +import au.com.royalpay.payment.tools.connections.mpsupport.WechatAppApi; +import au.com.royalpay.payment.tools.connections.mpsupport.impls.AbstractClientWechatAppImpl; +import org.springframework.stereotype.Service; + +/** + * @Author DuLingLing + * @create 2019/10/21 0021 17:57 + */ +@Service +public class MerchantAppWechatImpl extends AbstractClientWechatAppImpl implements WechatAppApi { + @Override + public String targetMpAccount() { + return "merchant-app"; + } + + @Override + public String getOpenIdKey() { + return ""; + } + + @Override + public boolean matchOpenId(String openId) { + return false; + } +}