From 03353f0f3e381b8e3c4a6b11831e7d85f8787224 Mon Sep 17 00:00:00 2001 From: luoyang Date: Tue, 16 Jul 2019 16:14:43 +0800 Subject: [PATCH] =?UTF-8?q?add=20PINE=E5=95=86=E6=88=B7=E9=87=8D=E7=BD=AE?= =?UTF-8?q?=E5=AF=86=E7=A0=81=E5=90=8E=E8=B4=A6=E6=88=B7=E4=BF=A1=E6=81=AF?= =?UTF-8?q?=E6=94=BE=E7=BD=AEmongo?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../dev/bean/TestMerchantAccountInfo.java | 56 +++++++++++++++++++ .../manage/dev/web/TestMerchantPassword.java | 30 ++++++---- .../core/impls/ClientManagerImpl.java | 51 ++++++----------- .../templates/testMerchantPassword.html | 2 +- 4 files changed, 93 insertions(+), 46 deletions(-) create mode 100644 src/main/java/au/com/royalpay/payment/manage/dev/bean/TestMerchantAccountInfo.java diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/bean/TestMerchantAccountInfo.java b/src/main/java/au/com/royalpay/payment/manage/dev/bean/TestMerchantAccountInfo.java new file mode 100644 index 000000000..69214a65a --- /dev/null +++ b/src/main/java/au/com/royalpay/payment/manage/dev/bean/TestMerchantAccountInfo.java @@ -0,0 +1,56 @@ +package au.com.royalpay.payment.manage.dev.bean; + +import com.alibaba.fastjson.JSONObject; + +public class TestMerchantAccountInfo { + + private String id; + private String clientMoniker; + private int role; + private String username; + private String password; + + public void setClientMoniker(String clientMoniker) { + this.clientMoniker = clientMoniker; + } + + public void setRole(int role) { + this.role = role; + } + + public void setUsername(String username) { + this.username = username; + } + + public void setPassword(String password) { + this.password = password; + } + + public String getClientMoniker() { + return clientMoniker; + } + + public int getRole() { + return role; + } + + public String getUsername() { + return username; + } + + public String getPassword() { + return password; + } + + public String getId() { + return id; + } + + public void setId(String id) { + this.id = id; + } + + public JSONObject toJSON() { + return (JSONObject) JSONObject.toJSON(this); + } +} diff --git a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestMerchantPassword.java b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestMerchantPassword.java index bcb5677ce..9759a7154 100644 --- a/src/main/java/au/com/royalpay/payment/manage/dev/web/TestMerchantPassword.java +++ b/src/main/java/au/com/royalpay/payment/manage/dev/web/TestMerchantPassword.java @@ -1,5 +1,6 @@ package au.com.royalpay.payment.manage.dev.web; +import au.com.royalpay.payment.manage.dev.bean.TestMerchantAccountInfo; import au.com.royalpay.payment.manage.mappers.system.ManagerMapper; import au.com.royalpay.payment.tools.CommonConsts; import au.com.royalpay.payment.tools.exceptions.ForbiddenException; @@ -11,6 +12,8 @@ import org.apache.commons.lang3.ArrayUtils; import org.apache.commons.lang3.StringUtils; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.data.mongodb.core.MongoTemplate; +import org.springframework.data.mongodb.core.query.Query; import org.springframework.stereotype.Controller; import org.springframework.ui.Model; import org.springframework.web.bind.annotation.*; @@ -37,14 +40,12 @@ public class TestMerchantPassword { @Resource private ManagerMapper managerMapper; + @Resource + private MongoTemplate mongoTemplate; @WechatMapping(value = "/testMerchantPassword",method = RequestMethod.GET) - public String testMerchantPassword(@RequestParam String sign, - @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser, - Model modelMap) throws Exception{ - if (StringUtils.isBlank(sign)) { - return null; - } + public String testMerchantPassword(@RequestParam(defaultValue = "") String sign, + @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser, Model modelMap) throws Exception{ String openid = wxUser.getString("openid"); List royalPayUsers = managerMapper.listRoyalPayUsers(); List needNotifyUsers = royalPayUsers.stream().filter(user -> StringUtils.isNotEmpty(user.getString("wx_openid"))) @@ -52,9 +53,19 @@ public class TestMerchantPassword { if (!ArrayUtils.contains(needNotifyUsers.toArray(new String[needNotifyUsers.size()]), openid)) { throw new ForbiddenException("无权限查看此页面"); } - String accounts = new String(AESdecrypt(Base64.decodeBase64(sign.replace("%2B", "+")), openid), "utf-8"); - JSONArray array = JSONArray.parseArray(accounts); - modelMap.addAttribute("accounts", array); + if (StringUtils.isNotBlank(sign)) { + String accounts = new String(AESdecrypt(Base64.decodeBase64(sign.replace("%2B", "+")), openid), "utf-8"); + JSONArray array = JSONArray.parseArray(accounts); + modelMap.addAttribute("accounts", array); + }else { + Query query = new Query(); + List accountInfos = mongoTemplate.find(query,TestMerchantAccountInfo.class); + List accounts = new ArrayList<>(); + for (TestMerchantAccountInfo accountInfo : accountInfos) { + accounts.add(accountInfo.toJSON()); + } + modelMap.addAttribute("accounts", accounts); + } return "testMerchantPassword"; } @@ -86,5 +97,4 @@ public class TestMerchantPassword { return null; } - } diff --git a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java index 50beb1e9b..fea78aecf 100644 --- a/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java +++ b/src/main/java/au/com/royalpay/payment/manage/merchants/core/impls/ClientManagerImpl.java @@ -22,6 +22,7 @@ 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.AppMerchantBean; import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService; +import au.com.royalpay.payment.manage.dev.bean.TestMerchantAccountInfo; import au.com.royalpay.payment.manage.device.core.DeviceManager; import au.com.royalpay.payment.manage.management.sysconfig.core.impls.PermissionPartnerManagerImpl; import au.com.royalpay.payment.manage.mappers.financial.FinancialBDConfigMapper; @@ -94,6 +95,7 @@ import org.springframework.cache.annotation.Cacheable; import org.springframework.context.ApplicationEventPublisher; import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.MessageSource; +import org.springframework.data.mongodb.core.MongoTemplate; import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.stereotype.Service; import org.springframework.transaction.annotation.Transactional; @@ -280,6 +282,8 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid private CommonSubMerchantIdMapper commonSubMerchantIdMapper; @Resource private Locker locker; + @Resource + private MongoTemplate mongoTemplate; @Resource @@ -5093,30 +5097,28 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid private void sendTestMerchantPassword(List accounts) { List royalPayUsers = managerMapper.listRoyalPayUsers(); - royalPayUsers = royalPayUsers.stream().filter(rpUser -> StringUtils.isNotEmpty(rpUser.getString("email"))).collect(Collectors.toList()); List needNotifyUsers = royalPayUsers.stream().filter(user -> StringUtils.isNotEmpty(user.getString("wx_openid"))).map(user -> user.getString("wx_openid")).collect(Collectors.toList()); - List sendAccounts = new ArrayList<>(); + accounts.forEach(account -> { + TestMerchantAccountInfo accountInfo = new TestMerchantAccountInfo(); + accountInfo.setId(account.getString("username")); + accountInfo.setClientMoniker(account.getString("client_moniker")); + accountInfo.setRole(account.getIntValue("role")); + accountInfo.setUsername(account.getString("username")); + accountInfo.setPassword(account.getString("password")); + mongoTemplate.save(accountInfo); + }); needNotifyUsers.forEach(userOpenId -> { try { - accounts.forEach(account -> { - JSONObject params = new JSONObject(); - params.put("client_moniker", account.getString("client_moniker")); - params.put("role", account.getIntValue("role")); - params.put("username", account.getString("username")); - params.put("password", account.getString("password")); - sendAccounts.add(params); - }); - String signStr = "?sign=" + AESencrypt(sendAccounts.toString(), userOpenId); MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi(); - TemplateMessage msg = initSendTestPasswordTemplate(userOpenId, paymentApi.getTemplateId("test-merchant-password"), signStr.replace("+", "%2B")); + TemplateMessage msg = initSendTestPasswordTemplate(userOpenId, paymentApi.getTemplateId("test-merchant-password")); paymentApi.sendTemplateMessage(msg); } catch (Exception e) { logger.error("给{}发送微信消息失败,原因:{}", userOpenId, e); } }); } - private TemplateMessage initSendTestPasswordTemplate(String wxopenid, String templateId, String url) { - TemplateMessage msg = new TemplateMessage(wxopenid, templateId, PlatformEnvironment.getEnv().concatUrl("testMerchantPassword" + url)); + private TemplateMessage initSendTestPasswordTemplate(String wxopenid, String templateId) { + TemplateMessage msg = new TemplateMessage(wxopenid, templateId, PlatformEnvironment.getEnv().concatUrl("testMerchantPassword")); msg.put("first", "系统测试商户账户已重置", "#000000"); msg.put("keyword1", "PINE", "#0000ff"); msg.put("keyword2", "账号密码重置", "#000000"); @@ -5130,27 +5132,6 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid return api.registerShortUrl(longUrl); } - - public static String AESencrypt(String content, String password) { - try { - KeyGenerator kgen = KeyGenerator.getInstance("AES"); - SecureRandom random = SecureRandom.getInstance("SHA1PRNG"); - random.setSeed(password.getBytes()); - kgen.init(128, random); - SecretKey secretKey = kgen.generateKey(); - byte[] enCodeFormat = secretKey.getEncoded(); - SecretKeySpec key = new SecretKeySpec(enCodeFormat, "AES"); - Cipher cipher = Cipher.getInstance("AES"); - byte[] byteContent = content.getBytes(StandardCharsets.UTF_8); - cipher.init(Cipher.ENCRYPT_MODE, key); - byte[] result = cipher.doFinal(byteContent); - return Base64.encodeBase64String(result); - } catch (NoSuchPaddingException | NoSuchAlgorithmException | InvalidKeyException | IllegalBlockSizeException | BadPaddingException e) { - e.printStackTrace(); - } - return null; - } - private JSONObject getRsaKey() { JSONObject key = new JSONObject(); KeyPair keyPairGen = RSACrypt.generateKeyPairs(); diff --git a/src/main/resources/templates/testMerchantPassword.html b/src/main/resources/templates/testMerchantPassword.html index 2e6f35bf6..9ff89608d 100644 --- a/src/main/resources/templates/testMerchantPassword.html +++ b/src/main/resources/templates/testMerchantPassword.html @@ -38,7 +38,7 @@ - + admin Manager Cashier