add 风控调单微信模板推送

master
luoyang 6 years ago
parent b7a5ff6961
commit 38f51e2b81

@ -78,4 +78,8 @@ public interface ClientAccountMapper {
List<JSONObject> query(JSONObject params); List<JSONObject> query(JSONObject params);
List<JSONObject> partnerAndSubPartnerAccounts(@Param("client_id") int clientId); List<JSONObject> partnerAndSubPartnerAccounts(@Param("client_id") int clientId);
@AutoSql(type = SqlType.SELECT)
@AdvanceSelect(addonWhereClause = "is_valid=1 and (role=1 or role=2) and wechat_openid is not null", excludeColumns = {"salt", "password_hash"})
List<JSONObject> listRiskNoticeAccounts(@Param("client_id") int clientId);
} }

@ -67,6 +67,13 @@ public interface RiskBusinessService {
*/ */
void updateRiskEvent(JSONObject params); void updateRiskEvent(JSONObject params);
/**
*
* @param params
* @param channel
*/
void sendWxMess(JSONObject params, String channel, int result_type);
/** /**
* zip * zip
* @param riskId * @param riskId

@ -11,9 +11,7 @@ import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskEventMapper;
import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskFileMapper; import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskFileMapper;
import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskMaterialMapper; import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskMaterialMapper;
import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskOrdersMapper; import au.com.royalpay.payment.manage.mappers.riskbusiness.RiskOrdersMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientDeviceTokenMapper; import au.com.royalpay.payment.manage.mappers.system.*;
import au.com.royalpay.payment.manage.mappers.system.ClientMapper;
import au.com.royalpay.payment.manage.mappers.system.ClientBDMapper;
import au.com.royalpay.payment.manage.notice.core.MailService; import au.com.royalpay.payment.manage.notice.core.MailService;
import au.com.royalpay.payment.manage.pushMessage.APNSMessageHelper; import au.com.royalpay.payment.manage.pushMessage.APNSMessageHelper;
import au.com.royalpay.payment.manage.pushMessage.bean.AppManagerMessageBuilder; import au.com.royalpay.payment.manage.pushMessage.bean.AppManagerMessageBuilder;
@ -26,10 +24,15 @@ import au.com.royalpay.payment.manage.signin.beans.TodoNotice;
import au.com.royalpay.payment.manage.signin.core.ManagerTodoNoticeProvider; import au.com.royalpay.payment.manage.signin.core.ManagerTodoNoticeProvider;
import au.com.royalpay.payment.manage.tradelog.core.TradeLogService; import au.com.royalpay.payment.manage.tradelog.core.TradeLogService;
import au.com.royalpay.payment.manage.riskbusiness.enums.RiskOrderTypeEnum; import au.com.royalpay.payment.manage.riskbusiness.enums.RiskOrderTypeEnum;
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApi;
import au.com.royalpay.payment.tools.connections.mpsupport.MpWechatApiProvider;
import au.com.royalpay.payment.tools.connections.mpsupport.beans.TemplateMessage;
import au.com.royalpay.payment.tools.connections.mpsupport.exceptions.WechatException;
import au.com.royalpay.payment.tools.device.message.AppMessage; import au.com.royalpay.payment.tools.device.message.AppMessage;
import au.com.royalpay.payment.tools.device.message.AppMsgSender; import au.com.royalpay.payment.tools.device.message.AppMsgSender;
import au.com.royalpay.payment.tools.env.PlatformEnvironment; import au.com.royalpay.payment.tools.env.PlatformEnvironment;
import au.com.royalpay.payment.tools.exceptions.BadRequestException; import au.com.royalpay.payment.tools.exceptions.BadRequestException;
import au.com.royalpay.payment.tools.exceptions.event.WechatExceptionEvent;
import au.com.royalpay.payment.tools.locale.LocaleSupport; import au.com.royalpay.payment.tools.locale.LocaleSupport;
import au.com.royalpay.payment.tools.permission.enums.ManagerRole; import au.com.royalpay.payment.tools.permission.enums.ManagerRole;
import au.com.royalpay.payment.tools.exceptions.ServerErrorException; import au.com.royalpay.payment.tools.exceptions.ServerErrorException;
@ -49,6 +52,8 @@ import org.apache.poi.ss.usermodel.*;
import org.apache.poi.xssf.usermodel.XSSFWorkbook; import org.apache.poi.xssf.usermodel.XSSFWorkbook;
import org.slf4j.Logger; import org.slf4j.Logger;
import org.slf4j.LoggerFactory; import org.slf4j.LoggerFactory;
import org.springframework.context.ApplicationEventPublisher;
import org.springframework.context.ApplicationEventPublisherAware;
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;
@ -72,7 +77,7 @@ import java.util.concurrent.TimeUnit;
* @Date 2018/10/10 10:30 * @Date 2018/10/10 10:30
*/ */
@Service @Service
public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodoNoticeProvider { public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodoNoticeProvider, ApplicationEventPublisherAware {
private Logger logger = LoggerFactory.getLogger(RiskBusinessServiceImpl.class); private Logger logger = LoggerFactory.getLogger(RiskBusinessServiceImpl.class);
@ -118,6 +123,14 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
@Resource @Resource
private APNSMessageHelper apnsMessageHelper; private APNSMessageHelper apnsMessageHelper;
@Resource
private ManagerMapper managerMapper;
@Resource
private ClientAccountMapper clientAccountMapper;
@Resource
private MpWechatApiProvider mpWechatApiProvider;
private ApplicationEventPublisher publisher;
@Resource @Resource
public void setAppMsgSenders(AppMsgSender[] senders) { public void setAppMsgSenders(AppMsgSender[] senders) {
@ -366,6 +379,105 @@ public class RiskBusinessServiceImpl implements RiskBusinessService, ManagerTodo
riskEventMapper.update(params); riskEventMapper.update(params);
riskOrdersMapper.clearOrders(params.getString("risk_id")); riskOrdersMapper.clearOrders(params.getString("risk_id"));
setRiskOrders(params); setRiskOrders(params);
}
@Override
public void sendWxMess(JSONObject params, String channel, int result_type) {
String type = "禁用";
if (params.get("temporary_close_merchant") != null) {
if (params.getBoolean("temporary_close_merchant")) {
type = "临时禁用";
}
}
if (params.get("temporary_close_channel") != null) {
if (params.getBoolean("temporary_close_channel")) {
type = "临时禁用";
}
}
String clientMoniker = params.getString("client_moniker");
if (clientMoniker == null) {
return;
}
JSONObject client = clientMapper.findClientByMoniker(clientMoniker);
if (client == null) {
throw new InvalidShortIdException();
}
client.put("close_type", type);
client.put("result_type", result_type);
client.put("channel", channel);
String bd_id = client.getString("bd_user");
String[] bdIdArray = bd_id.split(",");
for (String bdId : bdIdArray) {
JSONObject bd = managerMapper.findById(bdId);
if (bd != null) {
if (bd.get("wx_openid")!=null){
if (StringUtils.isNotBlank(bd.getString("wx_openid"))) {
try {
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
TemplateMessage msg = initSendBDCloseChannelAndPartnerTemplate(bd.getString("wx_openid"), paymentApi.getTemplateId("risk-forbidden-channelAndPartner"),client);
paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) {
logger.error("Wechat Message Error,风控关闭通道" + e.getMessage());
publisher.publishEvent(new WechatExceptionEvent(this, e, "风控关闭通道"));
}
}
}
}
}
List<JSONObject> accounts = clientAccountMapper.listRiskNoticeAccounts(client.getIntValue("client_id"));
if (accounts != null) {
for (JSONObject account : accounts) {
if (account.get("wx_openid")!=null){
if (StringUtils.isNotBlank(account.getString("wx_openid"))) {
try {
MpWechatApi paymentApi = mpWechatApiProvider.getNewPaymentApi();
TemplateMessage msg = initSendPartnerCloseChannelAndPartnerTemplate(account.getString("wx_openid"), paymentApi.getTemplateId("risk-forbidden-channelAndPartner"),client);
paymentApi.sendTemplateMessage(msg);
} catch (WechatException e) {
logger.error("Wechat Message Error,风控关闭通道" + e.getMessage());
publisher.publishEvent(new WechatExceptionEvent(this, e, "风控关闭通道"));
}
}
}
}
}
}
private TemplateMessage initSendBDCloseChannelAndPartnerTemplate(String wxopenid, String templateId,JSONObject client) {
TemplateMessage msg = new TemplateMessage(wxopenid, templateId,null);
//1:关闭渠道;2:关闭商户
if (client.getIntValue("result_type") == 1) {
msg.put("first", "您的商户("+client.getString("client_moniker")+")" + client.getString("channel") + "支付渠道已"+client.getString("close_type"), "#000000");
}else {
msg.put("first", "您的商户("+client.getString("client_moniker")+")已"+client.getString("close_type"), "#000000");
}
msg.put("keyword1", client.getString("channel") + "风控调单", "#0000ff");
msg.put("keyword2", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"), "#000000");
msg.put("remark", "请联系商户尽快配合风控部门上传相应资料,以免影响支付", "#0000FF");
return msg;
}
private TemplateMessage initSendPartnerCloseChannelAndPartnerTemplate(String wxopenid, String templateId,JSONObject client) {
TemplateMessage msg = new TemplateMessage(wxopenid, templateId,null);
//1:关闭渠道;2:关闭商户
if (client.getIntValue("result_type") == 1) {
msg.put("first", "您的商户" + client.getString("channel") + "支付渠道已"+client.getString("close_type"), "#000000");
}else {
msg.put("first", "您的商户("+client.getString("client_moniker")+")已"+client.getString("close_type"), "#000000");
}
msg.put("keyword1", client.getString("channel") + "风控调单", "#0000ff");
msg.put("keyword2", DateFormatUtils.format(new Date(), "yyyy-MM-dd HH:mm:ss"), "#000000");
msg.put("remark", "请尽快配合风控部门上传相应资料,以免影响支付", "#0000FF");
return msg;
}
@Override
public void setApplicationEventPublisher(ApplicationEventPublisher applicationEventPublisher) {
this.publisher = applicationEventPublisher;
} }
/** /**

@ -131,8 +131,12 @@ public class RiskBusinessController {
@ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) { @ModelAttribute(CommonConsts.MANAGER_STATUS) JSONObject manager) {
clientManager.switchChannelPermission(manager, params.getString("client_moniker"), channel, channelFlag); clientManager.switchChannelPermission(manager, params.getString("client_moniker"), channel, channelFlag);
if (channelFlag) if (channelFlag) {
params.put("result_type", RiskResultTypeEnum.ALREADY_HANDLED.getResultType()); params.put("result_type", RiskResultTypeEnum.ALREADY_HANDLED.getResultType());
} else {
//1:禁用渠道;2:禁用商户
riskBusinessService.sendWxMess(params, channel, 1);
}
riskBusinessService.updateRiskEvent(params); riskBusinessService.updateRiskEvent(params);
} }
@ -143,6 +147,7 @@ public class RiskBusinessController {
String clientMoniker = params.getString("client_moniker"); String clientMoniker = params.getString("client_moniker");
if (isValid) { if (isValid) {
clientManager.disableClient(clientMoniker, manager); clientManager.disableClient(clientMoniker, manager);
riskBusinessService.sendWxMess(params, "-", 2);
Integer temporaryCloseMerchant = params.getInteger("temporary_close_merchant"); Integer temporaryCloseMerchant = params.getInteger("temporary_close_merchant");
if (temporaryCloseMerchant != 1) { if (temporaryCloseMerchant != 1) {
params.put("result_type", RiskResultTypeEnum.ALREADY_HANDLED.getResultType()); params.put("result_type", RiskResultTypeEnum.ALREADY_HANDLED.getResultType());

@ -32,6 +32,7 @@ public class WepayWechatApiImpl extends AbstractMpWechatClientApi implements MpW
registerTemplateId("daily-green-channel", "vjeNnggHnnRHvBP80lkEEtPk8ouf7JnvrQYDCyxqx4g"); registerTemplateId("daily-green-channel", "vjeNnggHnnRHvBP80lkEEtPk8ouf7JnvrQYDCyxqx4g");
registerTemplateId("client-postpone", "5eNJ5ZTKWitC1TJClb2coymtNCmOC7d86h0zCrxmGig"); registerTemplateId("client-postpone", "5eNJ5ZTKWitC1TJClb2coymtNCmOC7d86h0zCrxmGig");
registerTemplateId("test-merchant-password","cF_zIhB4VmjdOaDS2_RNVFforyywsKcfjS1yNNgYmWw"); registerTemplateId("test-merchant-password","cF_zIhB4VmjdOaDS2_RNVFforyywsKcfjS1yNNgYmWw");
registerTemplateId("risk-forbidden-channelAndPartner","g79Sf5FOQT6PoCvRVzm7YlgtzbZ_EUD1z6E4Xp2Jwp4");
} }
@Override @Override

Loading…
Cancel
Save