add PINE商户重置密码后账户信息放置mongo

master
luoyang 6 years ago
parent 17c4207956
commit 03353f0f3e

@ -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);
}
}

@ -1,5 +1,6 @@
package au.com.royalpay.payment.manage.dev.web; 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.manage.mappers.system.ManagerMapper;
import au.com.royalpay.payment.tools.CommonConsts; import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException; 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.apache.commons.lang3.StringUtils;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; 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.stereotype.Controller;
import org.springframework.ui.Model; import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*; import org.springframework.web.bind.annotation.*;
@ -37,14 +40,12 @@ public class TestMerchantPassword {
@Resource @Resource
private ManagerMapper managerMapper; private ManagerMapper managerMapper;
@Resource
private MongoTemplate mongoTemplate;
@WechatMapping(value = "/testMerchantPassword",method = RequestMethod.GET) @WechatMapping(value = "/testMerchantPassword",method = RequestMethod.GET)
public String testMerchantPassword(@RequestParam String sign, public String testMerchantPassword(@RequestParam(defaultValue = "") String sign,
@ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser, @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser, Model modelMap) throws Exception{
Model modelMap) throws Exception{
if (StringUtils.isBlank(sign)) {
return null;
}
String openid = wxUser.getString("openid"); String openid = wxUser.getString("openid");
List<JSONObject> royalPayUsers = managerMapper.listRoyalPayUsers(); List<JSONObject> royalPayUsers = managerMapper.listRoyalPayUsers();
List<String> needNotifyUsers = royalPayUsers.stream().filter(user -> StringUtils.isNotEmpty(user.getString("wx_openid"))) List<String> 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)) { if (!ArrayUtils.contains(needNotifyUsers.toArray(new String[needNotifyUsers.size()]), openid)) {
throw new ForbiddenException("无权限查看此页面"); throw new ForbiddenException("无权限查看此页面");
} }
String accounts = new String(AESdecrypt(Base64.decodeBase64(sign.replace("%2B", "+")), openid), "utf-8"); if (StringUtils.isNotBlank(sign)) {
JSONArray array = JSONArray.parseArray(accounts); String accounts = new String(AESdecrypt(Base64.decodeBase64(sign.replace("%2B", "+")), openid), "utf-8");
modelMap.addAttribute("accounts", array); JSONArray array = JSONArray.parseArray(accounts);
modelMap.addAttribute("accounts", array);
}else {
Query query = new Query();
List<TestMerchantAccountInfo> accountInfos = mongoTemplate.find(query,TestMerchantAccountInfo.class);
List<JSONObject> accounts = new ArrayList<>();
for (TestMerchantAccountInfo accountInfo : accountInfos) {
accounts.add(accountInfo.toJSON());
}
modelMap.addAttribute("accounts", accounts);
}
return "testMerchantPassword"; return "testMerchantPassword";
} }
@ -86,5 +97,4 @@ public class TestMerchantPassword {
return null; return null;
} }
} }

@ -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.AppClientBean;
import au.com.royalpay.payment.manage.appclient.beans.AppMerchantBean; import au.com.royalpay.payment.manage.appclient.beans.AppMerchantBean;
import au.com.royalpay.payment.manage.application.core.SimpleClientApplyService; 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.device.core.DeviceManager;
import au.com.royalpay.payment.manage.management.sysconfig.core.impls.PermissionPartnerManagerImpl; import au.com.royalpay.payment.manage.management.sysconfig.core.impls.PermissionPartnerManagerImpl;
import au.com.royalpay.payment.manage.mappers.financial.FinancialBDConfigMapper; 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.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware; import org.springframework.context.ApplicationEventPublisherAware;
import org.springframework.context.MessageSource; import org.springframework.context.MessageSource;
import org.springframework.data.mongodb.core.MongoTemplate;
import org.springframework.data.redis.core.StringRedisTemplate; import org.springframework.data.redis.core.StringRedisTemplate;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional; import org.springframework.transaction.annotation.Transactional;
@ -280,6 +282,8 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
private CommonSubMerchantIdMapper commonSubMerchantIdMapper; private CommonSubMerchantIdMapper commonSubMerchantIdMapper;
@Resource @Resource
private Locker locker; private Locker locker;
@Resource
private MongoTemplate mongoTemplate;
@Resource @Resource
@ -5093,30 +5097,28 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
private void sendTestMerchantPassword(List<JSONObject> accounts) { private void sendTestMerchantPassword(List<JSONObject> accounts) {
List<JSONObject> royalPayUsers = managerMapper.listRoyalPayUsers(); List<JSONObject> royalPayUsers = managerMapper.listRoyalPayUsers();
royalPayUsers = royalPayUsers.stream().filter(rpUser -> StringUtils.isNotEmpty(rpUser.getString("email"))).collect(Collectors.toList());
List<String> needNotifyUsers = royalPayUsers.stream().filter(user -> StringUtils.isNotEmpty(user.getString("wx_openid"))).map(user -> user.getString("wx_openid")).collect(Collectors.toList()); List<String> needNotifyUsers = royalPayUsers.stream().filter(user -> StringUtils.isNotEmpty(user.getString("wx_openid"))).map(user -> user.getString("wx_openid")).collect(Collectors.toList());
List<JSONObject> 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 -> { needNotifyUsers.forEach(userOpenId -> {
try { 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(); 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); paymentApi.sendTemplateMessage(msg);
} catch (Exception e) { } catch (Exception e) {
logger.error("给{}发送微信消息失败,原因:{}", userOpenId, e); logger.error("给{}发送微信消息失败,原因:{}", userOpenId, e);
} }
}); });
} }
private TemplateMessage initSendTestPasswordTemplate(String wxopenid, String templateId, String url) { private TemplateMessage initSendTestPasswordTemplate(String wxopenid, String templateId) {
TemplateMessage msg = new TemplateMessage(wxopenid, templateId, PlatformEnvironment.getEnv().concatUrl("testMerchantPassword" + url)); TemplateMessage msg = new TemplateMessage(wxopenid, templateId, PlatformEnvironment.getEnv().concatUrl("testMerchantPassword"));
msg.put("first", "系统测试商户账户已重置", "#000000"); msg.put("first", "系统测试商户账户已重置", "#000000");
msg.put("keyword1", "PINE", "#0000ff"); msg.put("keyword1", "PINE", "#0000ff");
msg.put("keyword2", "账号密码重置", "#000000"); msg.put("keyword2", "账号密码重置", "#000000");
@ -5130,27 +5132,6 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
return api.registerShortUrl(longUrl); 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() { private JSONObject getRsaKey() {
JSONObject key = new JSONObject(); JSONObject key = new JSONObject();
KeyPair keyPairGen = RSACrypt.generateKeyPairs(); KeyPair keyPairGen = RSACrypt.generateKeyPairs();

@ -38,7 +38,7 @@
</thead> </thead>
<tbody> <tbody>
<tr th:each="account : ${accounts}"> <tr th:each="account : ${accounts}">
<td th:text="${account.client_moniker}"></td> <td th:text="${account.clientMoniker}"></td>
<td th:if="${account.role} == 1">admin</td> <td th:if="${account.role} == 1">admin</td>
<td th:if="${account.role} == 2">Manager</td> <td th:if="${account.role} == 2">Manager</td>
<td th:if="${account.role} == 3">Cashier</td> <td th:if="${account.role} == 3">Cashier</td>

Loading…
Cancel
Save