修改重置密码逻辑

master
taylor.dang 6 years ago
parent 472f1d2743
commit a022541c99

@ -442,19 +442,7 @@ public class TestController implements ApplicationEventPublisherAware {
@ManagerMapping(value = "/partner/reset_password", method = RequestMethod.GET, role = ManagerRole.DEVELOPER)
public void resetPartnerPassword() {
//抄送人邮箱
JSONObject sysConfig = sysConfigManager.getSysConfig();
String ccMail = sysConfig.getString("reset_password.cc_list");
//账号白名单
String accountWhiteList = sysConfig.getString("reset_password.account_white_list");
if (StringUtils.isEmpty(ccMail)) {
throw new BadRequestException("抄送人不能为空");
}
if (accountWhiteList == null) {
accountWhiteList = "";
}
List<String> emailList = Arrays.asList(ccMail.split(","));
clientManager.updateAllPartnerPassword("PINE", emailList, accountWhiteList);
clientManager.updateAllPartnerPassword("PINE");
}
@ManagerMapping(value = "/secure/hanyin_reports/{date}", role = ManagerRole.DEVELOPER, method = RequestMethod.GET)

@ -1,13 +1,12 @@
package au.com.royalpay.payment.manage.dev.web;
import au.com.royalpay.payment.manage.mappers.system.ManagerMapper;
import au.com.royalpay.payment.manage.support.wechatclients.RedpackWechatApiImpl;
import au.com.royalpay.payment.tools.CommonConsts;
import au.com.royalpay.payment.tools.connections.mpsupport.beans.WxOauthType;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
import au.com.royalpay.payment.tools.permission.wechat.WechatMapping;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import org.apache.commons.lang3.ArrayUtils;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -19,28 +18,29 @@ import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;
import java.util.stream.Collectors;
@Controller
@WechatMapping(value = "/testMerchantPassword", addonMp = {RedpackWechatApiImpl.class}, oauthType = WxOauthType.USERINFO)
public class TestMerchantPassword {
private Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private ManagerMapper managerMapper;
@WechatMapping(method = RequestMethod.GET)
public String testMerchantPassword(@RequestParam String[] accounts, @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser, Model modelMap) {
@RequestMapping(value = "/testMerchantPassword",method = RequestMethod.GET)
public String testMerchantPassword(@RequestParam String[] accounts,
@ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser,
Model modelMap) {
if (accounts == null) {
return null;
}
List<String> openIds = managerMapper.listDevAndBdOpenId();
if (!openIds.contains(wxUser.getString("openid"))) {
List<JSONObject> royalPayUsers = managerMapper.listRoyalPayUsers();
List<String> needNotifyUsers = royalPayUsers.stream().filter(user -> StringUtils.isNotEmpty(user.getString("wx_openid")))
.map(user -> user.getString("wx_openid")).collect(Collectors.toList());
if (!ArrayUtils.contains(needNotifyUsers.toArray(new String[needNotifyUsers.size()]), wxUser.getString("openid"))) {
throw new ForbiddenException("无权限查看此页面");
}
JSONArray array = new JSONArray();
for (String account : accounts) {
try {
@ -51,16 +51,12 @@ public class TestMerchantPassword {
accountJson.put("password", temp[1]);
accountJson.put("role", temp[2]);
accountJson.put("client_moniker", temp[3]);
array.add(accountJson);
} catch (UnsupportedEncodingException e) {
logger.error("获取临时密码失败转换url错误 " + e);
}
}
modelMap.addAttribute("accounts", array);
return "testMerchantPassword";
}
}

@ -373,7 +373,7 @@ public interface ClientManager {
void reSubYeepayMerchantApplication(String clientMoniker,JSONObject merchantInfo, JSONObject manager);
void updateAllPartnerPassword(String clientMoniker, List<String> emails, String accountWhiteList);
void updateAllPartnerPassword(String clientMoniker);
void postponeClientRate(Date now, Date yearTomorrow, String expireDate, JSONObject client);

@ -4283,13 +4283,19 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
}
@Override
@Transactional
public void updateAllPartnerPassword(String clientMoniker, List<String> emails, String accountWhiteList) {
public void updateAllPartnerPassword(String clientMoniker) {
JSONObject client = getClientInfoByMoniker(clientMoniker);
if (client == null) {
throw new InvalidShortIdException();
}
JSONObject sysConfig = sysConfigManager.getSysConfig();
String accountWhiteList = sysConfig.getString("reset_password.account_white_list");
List<JSONObject> partners = clientAccountMapper.partnerAndSubPartnerAccounts(client.getIntValue("client_id"));
partners = partners.stream().filter(partner -> !Arrays.asList(accountWhiteList.split(",")).contains(partner.getString("username"))).collect(Collectors.toList());
if (!StringUtils.isEmpty(accountWhiteList)) {
partners = partners.stream().filter(partner ->
!Arrays.asList(accountWhiteList.split(",")).contains(partner.getString("username"))
).collect(Collectors.toList());
}
partners.forEach(
partner -> {
String pwd = RandomStringUtils.random(8, true, true);
@ -4298,13 +4304,13 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
partner.put("salt", salt);
partner.put("password_hash", pwdHash);
partner.put("password_aes", PasswordUtils.encryptAESPwd(pwd));
deviceManager.deviceOffline(partner.getString("account_id"));
clientAccountMapper.update(partner);
signInAccountService.clearAccountCache(partner.getString("account_id"));
// deviceManager.deviceOffline(partner.getString("account_id"));
// clientAccountMapper.update(partner);
// signInAccountService.clearAccountCache(partner.getString("account_id"));
partner.put("password", pwd);
}
);
sendTestMerchantPassword(partners, emails);
sendTestMerchantPassword(partners);
}
@Override
@ -4563,52 +4569,44 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
}
private void sendTestMerchantPassword(List<JSONObject> accounts, List<String> emails) {
List<String> devAndBdEmails = managerMapper.listDevAndBdManager();
for(int i=0;i<devAndBdEmails.size();i++){
if(StringUtils.isBlank(devAndBdEmails.get(i)))
devAndBdEmails.remove(i);
}
private void sendTestMerchantPassword(List<JSONObject> accounts) {
List<JSONObject> royalPayUsers = managerMapper.listRoyalPayUsers();
royalPayUsers = royalPayUsers.stream().filter(rpUser -> StringUtils.isNotEmpty(rpUser.getString("email"))).collect(Collectors.toList());
String needSendEmails = royalPayUsers.stream().filter(user -> StringUtils.isNotEmpty(user.getString("email"))).map(user ->
user.getString("email")
).collect(Collectors.joining(","));
Context ctx = new Context();
ctx.setVariable("accounts", accounts);
final String content = thymeleaf.process( "mail/test_merchant_password", ctx);
final String content = thymeleaf.process("mail/test_merchant_password", ctx);
new Thread(() -> {
try {
mailService.sendEmail("测试商户账户已更新", emails.isEmpty() ? "" : StringUtils.join(emails, ","), devAndBdEmails.isEmpty() ? "" : StringUtils.join(devAndBdEmails, ","), content);
} catch (Exception ignored) {
logger.error("邮件发送失败", ignored);
throw new BadRequestException("邮件发送失败");
mailService.sendEmailWhihBcc("测试商户账户已更新", "info@royalpay.com.au", needSendEmails, content);
} catch (Exception e) {
throw new BadRequestException("邮件发送失败", e);
}
}).start();
StringBuffer accountsStr = new StringBuffer("?");
accounts.forEach(e->{
accountsStr.append("accounts=" + e.getString("username") + ","
+ e.getString("password") + "," + e.getIntValue("role") + "," + e.getString("client_moniker") + "&");
accounts.forEach(account -> {
accountsStr.append("accounts=").append(account.getString("username")).append(",").append(account.getString("password")).append(",").append(account.getIntValue("role")).append(",").append(account.getString("client_moniker")).append("&");
});
String account = accountsStr.substring(0, accountsStr.length() - 1);
List<String> wx_openIds = managerMapper.listDevAndBdOpenId();
for (String wxopenid : wx_openIds) {
if (StringUtils.isNotBlank(wxopenid)) {
try {
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
TemplateMessage msg = initSendTestPasswordTemplate(wxopenid, paymentApi.getTemplateId("test-merchant-password"), account);
paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) {
logger.error("Wechat Message Error,密码修改完成" + e.getMessage());
publisher.publishEvent(new WechatExceptionEvent(this, e, "测试商户密码修改完成"));
}
List<String> needNotifyUsers = royalPayUsers.stream().filter(user -> StringUtils.isNotEmpty(user.getString("wx_openid"))).map(user -> user.getString("wx_openid")).collect(Collectors.toList());
needNotifyUsers.forEach(userOpenId -> {
try {
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
TemplateMessage msg = initSendTestPasswordTemplate(userOpenId, paymentApi.getTemplateId("test-merchant-password"), StringUtils.substring(accountsStr.toString(), 0, accountsStr.length() - 1));
paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) {
logger.error("给{}发送微信消息失败,原因:{}", userOpenId, e.getMessage());
publisher.publishEvent(new WechatExceptionEvent(this, e, "测试商户密码修改完成"));
} catch (Exception e) {
logger.error("给{}发送密码重置消息失败,原因: {}", userOpenId, e.getMessage());
}
}
});
}
private TemplateMessage initSendTestPasswordTemplate(String wxopenid, String templateId,String url) {
TemplateMessage msg = new TemplateMessage(wxopenid, templateId, "https://mpay.royalpay.com.au/testMerchantPassword" + url);
msg.put("first", "尊敬的用户,该商户下账号密码已重置。", "#000000");
private TemplateMessage initSendTestPasswordTemplate(String wxopenid, String templateId, String url) {
TemplateMessage msg = new TemplateMessage(wxopenid, templateId, PlatformEnvironment.getEnv().concatUrl("testMerchantPassword" + url));
msg.put("first", "系统测试商户账户已重置", "#000000");
msg.put("keyword1", "PINE", "#0000ff");
msg.put("keyword2", "账号密码重置", "#000000");
msg.put("keyword3", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss,z"), "#000000");

@ -15,6 +15,8 @@ public interface MailService {
String sendEmail(String title, String mailTos, String mailCcs, String content) throws URISyntaxException, IOException;
String sendEmailWhihBcc(String title, String mailTos, String mailBccs, String content) throws URISyntaxException, IOException;
String sendEmail(String title, String mailTos, String mailCcs, String content, List<JSONObject> attachFiles) throws URISyntaxException, IOException;
String sendRiskEmail(String title, String mailTos, String mailCcs,String mailBcc, String content, List<JSONObject> attachFiles, int order_type) throws URISyntaxException, IOException;

@ -180,6 +180,37 @@ public class MailServiceImp implements MailService {
}
}
@Override
public String sendEmailWhihBcc(String title, String mailTos, String mailBccs, String content) throws IOException {
NoticeBean noticeBean = new NoticeBean();
noticeBean.setTitle(title);
List<JSONObject> mailClients = new ArrayList<>();
JSONObject mailClient = new JSONObject();
mailClient.put("mailto", mailTos);
mailClient.put("mailcc", "");
mailClient.put("mailbcc", mailBccs);
mailClients.add(mailClient);
noticeBean.setMailClients(mailClients);
noticeBean.setContent(content);
noticeBean.setSenderAddress("info@royalpay.com.au");
noticeBean.setPassword("Rpay2018");
String postUrl = mailHost + "/mail/single?" + generateMailSignParam();
HttpRequestResult result = null;
try {
logger.info("===sendEmail===noticeBean:" + JSON.toJSON(noticeBean));
result = new HttpRequestGenerator(postUrl, RequestMethod.POST).setJSONEntity(noticeBean).setTimeout(60_000).execute();
if (result.isSuccess()) {
String mail_id = result.getResponseContentJSONObj().getString("mail_id");
return mail_id;
//System.out.println("send Mail=============="+mail_id);
} else {
throw new ServerErrorException("Error Connection");
}
} catch (URISyntaxException e) {
throw new ServerErrorException("Error Connection");
}
}
@Override
public List<JSONObject> checkEmailStatus(String emailId) {
String url = mailHost + "/mail/clients/" + emailId + "?" + generateMailSignParam();

@ -22,32 +22,15 @@ import java.util.List;
@Component
@ConditionalOnProperty(value = "app.run-tasks", havingValue = "true")
public class UpdatePartnerPasswordTask {
private Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private ClientManager clientManager;
@Resource
private SynchronizedScheduler synchronizedScheduler;
@Resource
private SysConfigManager sysConfigManager;
// private final static String EMAIL = "lily.tao@royalpay.com.au,bella.sun@royalpay.com.au,astro.dai@royalpay.com.au,taylor.dang@royalpay.com.au";
@Scheduled(cron = "0 0 9 28 * ?")
public void resetPartnerPassword() {
synchronizedScheduler.executeProcess("manage_task:resetPartnerPassword", 300_000, () -> {
//抄送人邮箱
JSONObject sysConfig = sysConfigManager.getSysConfig();
String ccMail = sysConfig.getString("reset_password.cc_list");
//账号白名单
String accountWhiteList = sysConfig.getString("reset_password.account_white_list");
if (StringUtils.isEmpty(ccMail)) {
throw new BadRequestException("抄送人不能为空");
}
if (accountWhiteList == null) {
accountWhiteList = "";
}
List<String> emailList = Arrays.asList(ccMail.split(","));
clientManager.updateAllPartnerPassword("PINE", emailList, accountWhiteList);
clientManager.updateAllPartnerPassword("PINE");
});
}
}

@ -1,5 +1,6 @@
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<script type="text/javascript" src="//res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
<script type="text/javascript" src="/static/templates/disable_wechat_menu.js?t=201990831928310"></script>
<style type="text/css">
table.gridtable {
font-family: verdana,arial,sans-serif;

Loading…
Cancel
Save