From 963dbc704080089b295ecdc183288b7657f6f636 Mon Sep 17 00:00:00 2001 From: luoyang Date: Fri, 21 Feb 2020 10:17:14 +0800 Subject: [PATCH] =?UTF-8?q?add=20=E5=BC=80=E5=BA=97=E7=8A=B6=E6=80=81?= =?UTF-8?q?=E9=80=9A=E7=9F=A5=E3=80=81app=E6=89=AB=E7=A0=81=E6=8E=A5?= =?UTF-8?q?=E5=8F=A3=E5=A2=9E=E5=8A=A0source=E5=8F=82=E6=95=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- pom.xml | 2 +- .../appclient/core/RetailRSvcService.java | 2 + .../core/impls/RetailRSvcServiceImpl.java | 38 +++++++++++++++++++ .../appclient/web/RetailAppController.java | 5 ++- .../appclient/web/RsvcServiceController.java | 5 +++ .../signin/core/SignInStatusManager.java | 4 +- .../core/impls/SignInStatusManagerImpl.java | 17 +++++++-- .../manage/signin/web/SignInController.java | 18 ++++++--- src/main/ui/login.html | 8 +++- src/main/ui/login_v1.html | 8 +++- 10 files changed, 89 insertions(+), 18 deletions(-) diff --git a/pom.xml b/pom.xml index 390b095a9..92ba279d1 100644 --- a/pom.xml +++ b/pom.xml @@ -9,7 +9,7 @@ 4.0.0 manage - 1.3.51 + 1.3.52 UTF-8 1.8.0 diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailRSvcService.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailRSvcService.java index 61426d124..62935b725 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailRSvcService.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/RetailRSvcService.java @@ -14,5 +14,7 @@ public interface RetailRSvcService { JSONObject enterIntoServiceBySourceCode(String sourceCode, JSONObject params); + JSONObject setUpShopBySourceCode(String sourceCode, JSONObject params); + JSONObject getGeekSsoTokenInfo(String sourceCode, String clientMoniker); } diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java index 2722522d1..14bea82e8 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/core/impls/RetailRSvcServiceImpl.java @@ -4,6 +4,7 @@ import au.com.royalpay.payment.core.exceptions.InvalidShortIdException; import au.com.royalpay.payment.manage.appclient.beans.RSvcMchBean; import au.com.royalpay.payment.manage.appclient.core.RetailRSvcService; import au.com.royalpay.payment.manage.appclient.extend.JWTUtil; +import au.com.royalpay.payment.manage.mappers.system.ClientConfigMapper; import au.com.royalpay.payment.manage.mappers.system.ClientServicesApplyMapper; import au.com.royalpay.payment.manage.merchants.core.ClientManager; import au.com.royalpay.payment.tools.codec.AESCrypt; @@ -38,6 +39,8 @@ public class RetailRSvcServiceImpl implements RetailRSvcService { private CommonIncrementalChannelMapper commonIncrementalChannelMapper; @Resource private ClientServicesApplyMapper clientServicesApplyMapper; + @Resource + private ClientConfigMapper clientConfigMapper; @Override public JSONObject findMchInfoBySourceCode(JSONObject device, String sourceCode) { @@ -128,6 +131,41 @@ public class RetailRSvcServiceImpl implements RetailRSvcService { return result; } + @Override + public JSONObject setUpShopBySourceCode(String sourceCode, JSONObject params) { + JSONObject result = new JSONObject(); + JSONObject svcInfo = commonIncrementalChannelMapper.findIncreamentalChannelBySourceCode(sourceCode); + try { + if (svcInfo == null || StringUtils.isEmpty(svcInfo.getString("channel_pub_key")) + || StringUtils.isEmpty(svcInfo.getString("platform_pub_key")) || StringUtils.isEmpty("platform_pri_key")) { + throw new BadRequestException("this channel config is wrong"); + } + Key key = AESCrypt.fromKeyString(Base64.decodeBase64(params.getString("nonce_str"))); + String signa = params.getString("sign"); + params.remove("sign"); + params = JSONObject.parseObject(JSON.toJSONString(params), Feature.OrderedField); + boolean checkSign = SignUtils.validSign(params.toJSONString(), signa, svcInfo.getString("channel_pub_key")); + if (!checkSign) { + throw new BadRequestException("sign is wrong"); + } + String clientMoniker = decData(params.getString("partnerCode"), key, svcInfo.getString("platform_pri_key")); + logger.debug("{} new shop set up :{}", clientMoniker,params.toJSONString()); + JSONObject client = clientManager.getClientInfoByMoniker(clientMoniker); + if (client == null) { + throw new InvalidShortIdException(); + } + JSONObject clientConfig = clientConfigMapper.find(client.getIntValue("client_id")); + clientConfig.put("geek_shop_status", 1); + clientConfigMapper.update(clientConfig); + result.put("result_status", "SUCCESS"); + } catch (Exception e) { + logger.error("set up geek shop fail:{} - {}",sourceCode,e.getMessage()); + result.put("result_status", "SYSTEMERROR"); + result.put("result_msg", e.getMessage()); + } + return result; + } + @Override public JSONObject getGeekSsoTokenInfo(String sourceCode, String clientMoniker) { JSONObject svcInfo = commonIncrementalChannelMapper.findIncreamentalChannelBySourceCode(sourceCode); 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 545fbd33b..0919e7b5a 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 @@ -422,8 +422,9 @@ public class RetailAppController { } @GetMapping("/partner_signin_app_qrcode/{codeId}") - public void partnerAppSigninViaQRCode(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, @PathVariable String codeId) { - signInStatusManager.clientQRCodeAppSignIn(device, codeId); + public void partnerAppSigninViaQRCode(@ModelAttribute(CommonConsts.RETAIL_DEVICE) JSONObject device, @PathVariable String codeId, + @RequestParam(required = false) String source) { + signInStatusManager.clientQRCodeAppSignIn(device, codeId, source); } /* 优惠券Begin */ diff --git a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RsvcServiceController.java b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RsvcServiceController.java index 8608a502a..73d28f932 100644 --- a/src/main/java/au/com/royalpay/payment/manage/appclient/web/RsvcServiceController.java +++ b/src/main/java/au/com/royalpay/payment/manage/appclient/web/RsvcServiceController.java @@ -17,4 +17,9 @@ public class RsvcServiceController { public JSONObject enterIntoServiceBySourceCode(@PathVariable String source_code, @RequestBody JSONObject params) { return retailRSvcService.enterIntoServiceBySourceCode(source_code, params); } + + @PostMapping(value = "/{source_code}/setUpShop") + public JSONObject setUpShopBySourceCode(@PathVariable String source_code, @RequestBody JSONObject params) { + return retailRSvcService.setUpShopBySourceCode(source_code, params); + } } 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 2dc07fbd0..94ada22e5 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 @@ -56,11 +56,11 @@ public interface SignInStatusManager { JSONObject newClientAppSignInQRCode(); - void clientQRCodeAppSignIn(JSONObject device, String codeId); + void clientQRCodeAppSignIn(JSONObject device, String codeId, String source); void clientQRCodeWechatSignIn(JSONObject wxUser, String codeId); - String appQRCodeSignInStatus(String codeId); + JSONObject appQRCodeSignInStatus(String codeId); JSONObject customerQRCode(); 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 736d9023c..38e553741 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 @@ -4,7 +4,6 @@ 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.MpClient; import au.com.royalpay.payment.tools.connections.mpsupport.MpClientAppWechatApiProvider; import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.exceptions.BadRequestException; @@ -316,7 +315,7 @@ public class SignInStatusManagerImpl implements SignInStatusManager { } @Override - public void clientQRCodeAppSignIn(JSONObject device, String codeId) { + public void clientQRCodeAppSignIn(JSONObject device, String codeId, String source) { getlockRandomCodeId(codeId); String statusKey = newStatusKey(); JSONObject account = new JSONObject(); @@ -328,6 +327,9 @@ public class SignInStatusManagerImpl implements SignInStatusManager { } stringRedisTemplate.boundValueOps(partnerLoginRedisKey(statusKey)).set("" + account.getString("account_id"), 30, TimeUnit.MINUTES); stringRedisTemplate.boundValueOps(redisPrefix + ":app_qrcode_signin:code:" + codeId).set(statusKey, 1, TimeUnit.MINUTES); + if (StringUtils.isNotBlank(source)) { + stringRedisTemplate.boundValueOps(redisPrefix + ":app_qrcode_signin_" + source + ":code:" + codeId).set(statusKey, 1, TimeUnit.MINUTES); + } } @Override @@ -346,13 +348,20 @@ public class SignInStatusManagerImpl implements SignInStatusManager { } @Override - public String appQRCodeSignInStatus(String codeId) { + public JSONObject appQRCodeSignInStatus(String codeId) { + JSONObject statusInfo = new JSONObject(); String statusKey = stringRedisTemplate.boundValueOps(redisPrefix + ":app_qrcode_signin:code:" + codeId).get(); if (statusKey == null) { throw new ForbiddenException("Not signed yet"); } stringRedisTemplate.delete(redisPrefix + ":app_qrcode_signin:code:" + codeId); - return statusKey; + String source = stringRedisTemplate.boundValueOps(redisPrefix + ":app_qrcode_signin_RYCBSM:code:" + codeId).get(); + if (source != null) { + statusInfo.put("redirect_geek", true); + stringRedisTemplate.delete(redisPrefix + ":app_qrcode_signin_RYCBSM:code:" + codeId); + } + statusInfo.put("status_key", statusKey); + return statusInfo; } @Override diff --git a/src/main/java/au/com/royalpay/payment/manage/signin/web/SignInController.java b/src/main/java/au/com/royalpay/payment/manage/signin/web/SignInController.java index 4be5f282c..732059794 100644 --- a/src/main/java/au/com/royalpay/payment/manage/signin/web/SignInController.java +++ b/src/main/java/au/com/royalpay/payment/manage/signin/web/SignInController.java @@ -20,6 +20,7 @@ import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.permission.wechat.WechatMapping; import com.alibaba.fastjson.JSONObject; import com.google.code.kaptcha.Producer; +import org.apache.commons.lang3.StringUtils; import org.springframework.ui.Model; import org.springframework.validation.Errors; import org.springframework.web.bind.annotation.*; @@ -315,9 +316,11 @@ public class SignInController { @GetMapping("/partner_signin_app_qrcode/{codeId}/check") - public void checkQRCodeAppLoginStatus(@PathVariable String codeId, HttpServletResponse response) { - String statusKey = signInStatusManager.appQRCodeSignInStatus(codeId); - HttpUtils.setCookie(response, CommonConsts.PARTNER_STATUS, statusKey); + public JSONObject checkQRCodeAppLoginStatus(@PathVariable String codeId, HttpServletResponse response) { + JSONObject statusInfo = signInStatusManager.appQRCodeSignInStatus(codeId); + HttpUtils.setCookie(response, CommonConsts.PARTNER_STATUS, statusInfo.getString("status_key")); + statusInfo.remove("status_key"); + return statusInfo; } @WechatMapping(value = "/partner_signin_qrcode/{codeId}", method = RequestMethod.GET) @@ -327,13 +330,18 @@ public class SignInController { } @GetMapping("/partner_signin_qrcode/verify/{codeId}") - public void verifyQRCode(@PathVariable String codeId, @RequestHeader("User-Agent") String ua, HttpServletResponse response) throws IOException { + public void verifyQRCode(@PathVariable String codeId, @RequestHeader("User-Agent") String ua, + HttpServletResponse response, @RequestParam(required = false) String source) throws IOException { if (ua.toLowerCase().contains("micromessenger")) { response.sendRedirect("/global/userstatus/partner_signin_qrcode/" + codeId); return; } if (ua.toLowerCase().contains("royalpayclient")) { - response.sendRedirect("/api/v1.0/retail/app/partner_signin_app_qrcode/" + codeId); + if (StringUtils.isNotBlank(source)) { + response.sendRedirect("/api/v1.0/retail/app/partner_signin_app_qrcode/" + codeId + "?source=" + source); + }else { + response.sendRedirect("/api/v1.0/retail/app/partner_signin_app_qrcode/" + codeId); + } return; } throw new ForbiddenException("error.not_support_browser"); diff --git a/src/main/ui/login.html b/src/main/ui/login.html index 432a0a419..d6fa1e212 100644 --- a/src/main/ui/login.html +++ b/src/main/ui/login.html @@ -338,8 +338,12 @@ $.ajax({ url: '/global/userstatus/partner_signin_app_qrcode/' + codeId + '/check', method: 'get', - success: function () { - getGeekSsoLoginUrl(); + success: function (res) { + if (res.redirect_geek) { + getGeekSsoLoginUrl(); + }else { + location.href = '/index.html'; + } }, error: function () { if ($('#qrdiv').is(":visible")) { diff --git a/src/main/ui/login_v1.html b/src/main/ui/login_v1.html index d878eca6d..5e665bf65 100644 --- a/src/main/ui/login_v1.html +++ b/src/main/ui/login_v1.html @@ -319,8 +319,12 @@ $.ajax({ url: '/global/userstatus/partner_signin_app_qrcode/' + codeId + '/check', method: 'get', - success: function () { - getGeekSsoLoginUrl(); + success: function (res) { + if (res.redirect_geek) { + getGeekSsoLoginUrl(); + }else { + location.href = '/index.html'; + } }, error: function () { if ($('#qrdiv').is(":visible")) {