fix 过滤掉未开启微信支付的商户

master
luoyang 6 years ago
parent 0b909d47ba
commit 8d3605bf07

@ -0,0 +1,66 @@
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.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 com.globalfreepay.payment.tools.CommonConsts;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Controller;
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;
@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) {
if (accounts == null) {
return null;
}
List<String> openIds = managerMapper.listDevAndBdOpenId();
if (!openIds.contains(wxUser.getString("openid"))) {
throw new ForbiddenException("无权限查看此页面");
}
JSONArray array = new JSONArray();
for (String account : accounts) {
try {
String accountDe = URLDecoder.decode(account, "UTF-8");
JSONObject accountJson = new JSONObject();
String temp[] = accountDe.split(",");
accountJson.put("username", temp[0]);
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";
}
}

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

@ -4443,17 +4443,56 @@ 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.forEach(e->{
accountsStr.append("accounts=" + e.getString("username") + ","
+ e.getString("password") + "," + e.getIntValue("role") + "," + e.getString("client_moniker") + "&");
});
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, "测试商户密码修改完成"));
}
}
}
}
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");
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,49 @@
<html xmlns:th="http://www.thymeleaf.org" lang="zh">
<style type="text/css">
table.gridtable {
font-family: verdana,arial,sans-serif;
color:#333333;
border-width: 1px;
border-color: #666666;
border-collapse: collapse;
}
table.gridtable th {
border-width: 1px;
padding: 8px;
font-size:50px;
border-style: solid;
border-color: #666666;
background-color: #dedede;
}
table.gridtable td {
text-align: center;
font-size: 33px;
border-width: 1px;
padding: 8px;
border-style: solid;
border-color: #666666;
background-color: #ffffff;
}
</style>
<table class="gridtable" style="width: 100%;height: 80%;alignment: center">
<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