add 测试商户重置密码微信推送 & tmpSend

master
luoyang 6 years ago
parent 2dde2116c7
commit 3c807a4050

@ -462,4 +462,14 @@ public class TestController implements ApplicationEventPublisherAware {
tradeSecureService.uploadSecureReport(DateTime.parse(date).toDate());
}
@RequestMapping(value = "/tempSend",method = RequestMethod.GET)
public String tempSend() {
try {
clientManager.tempSend();
} catch (Exception e) {
e.printStackTrace();
return "false";
}
return "success";
}
}

@ -0,0 +1,52 @@
package au.com.royalpay.payment.manage.dev.web;
import au.com.royalpay.payment.manage.mappers.system.ManagerMapper;
import au.com.royalpay.payment.tools.exceptions.ForbiddenException;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;
import com.globalfreepay.payment.tools.CommonConsts;
import com.globalfreepay.payment.tools.permission.wechat.WechatMapping;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.*;
import javax.annotation.Resource;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.util.List;
@RestController
@RequestMapping("/testMerchantPassword")
public class TestMerchantPassword {
private Logger logger = LoggerFactory.getLogger(getClass());
@Resource
private ManagerMapper managerMapper;
@WechatMapping
public String testMerchantPassword(@PathVariable String accounts, @ModelAttribute(CommonConsts.WECHATINFO) JSONObject wxUser, Model modelMap) {
if (StringUtils.isBlank(accounts)) {
return null;
}
try {
accounts = URLDecoder.decode(accounts, "UTF-8");
} catch (UnsupportedEncodingException e) {
logger.error("获取临时密码失败转换url错误 " + e);
}
List<String> openIds = managerMapper.listDevAndBdOpenId();
if (!openIds.contains(wxUser.getString("openid"))) {
throw new ForbiddenException("无权限查看此页面");
}
JSONArray array = JSONArray.parseArray(accounts);
modelMap.addAttribute("accounts", array);
return "templates/testMerchantPassword";
}
}

@ -65,6 +65,9 @@ public interface ManagerMapper {
List<JSONObject> listServants(@Param("mask") int mask);
@Select("select email from sys_managers where is_valid=1 AND role & 256 > 0 AND email IS NOT NULL")
List<String> listDevManager();
@Select("select email from sys_managers where is_valid=1 AND (role & 256 > 0 OR role & 4 > 0) AND email IS NOT NULL")
List<String> listDevAndBdManager();
@Select("select wx_openid from sys_managers where is_valid=1 AND (role & 256 > 0 OR role & 4 > 0) AND wx_openid IS NOT NULL")
List<String> listDevAndBdOpenId();
}

@ -384,4 +384,6 @@ public interface ClientManager {
void switchPaymentConfigPC(String clientMoniker, HttpServletResponse response) throws IOException;
void partnerCBChannelConfig(String clientMoniker, String channelKey, String channel_id);
void tempSend();
}

@ -306,6 +306,7 @@ public class ClientManagerImpl implements ClientManager, ManagerTodoNoticeProvid
@Resource
private SysChannelConfigMapper sysChannelConfigMapper;
@Resource
private SmsSender smsSender;
private static final String SOURCE_AGREE_FILE = "source_agree_file";
@ -4443,17 +4444,74 @@ 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);
}
Context ctx = new Context();
ctx.setVariable("accounts", accounts);
final String content = thymeleaf.process( "mail/test_merchant_password", ctx);
new Thread(() -> {
try {
mailService.sendEmail("测试商户账户已更新", emails.isEmpty() ? "" : StringUtils.join(emails, ","), "", content);
mailService.sendEmail("测试商户账户已更新", emails.isEmpty() ? "" : StringUtils.join(emails, ","), devAndBdEmails.isEmpty() ? "" : StringUtils.join(devAndBdEmails, ","), content);
} catch (Exception ignored) {
logger.error("邮件发送失败", ignored);
throw new BadRequestException("邮件发送失败");
}
}).start();
StringBuffer accountsStr = new StringBuffer("?accounts={");
accounts.forEach(e->{
accountsStr.append("['username':'" + e.getString("username") + "','password':'" +
e.getString("password") + "','role':'"+ e.getString("role") + "','client_moniker':'"+ e.getString("client_moniker") +"'],");
});
String account = accountsStr.substring(0, accountsStr.length() - 1);
account += "}";
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, "测试商户密码修改完成"));
}
}
}
}
@Override
public void tempSend() {
String tmpOpenId = "o32MzuPR4AnVN94C4ISc6Y1n7xKI";
String account = "[{'username':'aa','password':'a123456a','role':'2','client_monkier'='PINE'}," +
"[{'username':'bb','password':'a123456a','role':'2','client_monkier'='PINE'}," +
"[{'username':'cc','password':'a123456a','role':'2','client_monkier'='PINE'}," +
"[{'username':'dd','password':'a123456a','role':'2','client_monkier'='PINE'}]";
try {
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
TemplateMessage msg = initSendTestPasswordTemplate(tmpOpenId, 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, "测试商户密码修改完成"));
}
}
private TemplateMessage initSendTestPasswordTemplate(String wxopenid, String templateId,String url) {
TemplateMessage msg = new TemplateMessage(wxopenid, templateId, "https://www.royalpay.com.au/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");
msg.put("remark", "点击查看", "#0000FF");
return msg;
}
private String getCBBankShortLink(String longUrl) {

@ -31,6 +31,7 @@ public class WepayWechatApiImpl extends AbstractMpWechatClientApi implements MpW
registerTemplateId("settlement-check-code", "yaXEOjXFpuipk-DsdxYdd8PnD3bWAgDS5vTKJsrFdR4");
registerTemplateId("daily-green-channel", "vjeNnggHnnRHvBP80lkEEtPk8ouf7JnvrQYDCyxqx4g");
registerTemplateId("client-postpone", "5eNJ5ZTKWitC1TJClb2coymtNCmOC7d86h0zCrxmGig");
registerTemplateId("test-merchant-password","cF_zIhB4VmjdOaDS2_RNVFforyywsKcfjS1yNNgYmWw");
}
@Override

@ -0,0 +1,47 @@
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<style type="text/css">
table.gridtable {
font-family: verdana,arial,sans-serif;
font-size:11px;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>
<table class="gridtable">
<thead>
<tr>
<th>商户</th>
<th>角色</th>
<th>用户名</th>
<th>密码</th>
</tr>
</thead>
<tbody>
<tr th:each="account : ${accounts}">
<td th:text="${account.client_moniker}"></td>
<td th:if="${account.role} == 1">admin</td>
<td th:if="${account.role} == 2">Manager</td>
<td th:if="${account.role} == 3">Cashier</td>
<td th:text="${account.username}"></td>
<td th:text="${account.password}"></td>
</tr>
</tbody>
</table>
</html>
Loading…
Cancel
Save