use of me.chanjar.weixin.mp.bean.template.WxMpTemplateData in project summer by foxsugar.
the class MenuHandler method handle_clear.
private WxMpXmlOutMessage handle_clear(WxMpXmlMessage wxMessage, WxMpService wxService) {
WxMpUser wxMpUser = null;
try {
wxMpUser = wxService.getUserService().userInfo(wxMessage.getFromUser());
String unionId = wxMpUser.getUnionId();
String openId = wxMpUser.getOpenId();
Long agentId = gameAgentService.getGameAgentDao().getUserIdByUnionId(unionId);
if (agentId == null || agentId == 0) {
return new TextBuilder().build("代理不存在", wxMessage, wxService);
}
// gameAgent 是否已经生成ticket
AgentBean agentBean = RedisManager.getAgentRedisService().getAgentBean(agentId);
// 金额小于 100 不能提
if (agentBean.getRebate() < 100) {
return new TextBuilder().build("金额小于100,不能提现", wxMessage, wxService);
}
double rebate = agentBean.getRebate();
// 不能大于20000
if (rebate > 20000) {
rebate = 20000;
}
Double amount = rebate * 100;
DecimalFormat df = new DecimalFormat("######0.00");
// 到账金额
double amountInt = Double.valueOf(df.format(amount / 100));
// 手续费
// double poundage = Double.valueOf(df.format((rebate *100 - amountInt *100)/100));
double poundage = 0;
long tradeId = createOrderId();
String ip = Utils.getLocalIp();
EntPayRequest wxEntPayRequest = new EntPayRequest();
wxEntPayRequest.setAppid(wechatConfig.getMpAppId());
wxEntPayRequest.setMchId(wechatConfig.getMchId());
wxEntPayRequest.setNonceStr(Sha1Util.getNonceStr());
wxEntPayRequest.setPartnerTradeNo("" + tradeId);
wxEntPayRequest.setOpenid(openId);
wxEntPayRequest.setCheckName("NO_CHECK");
// 金额 为分
wxEntPayRequest.setAmount(amount.intValue());
wxEntPayRequest.setDescription("提现");
wxEntPayRequest.setSpbillCreateIp(ip);
try {
EntPayResult wxEntPayResult = payService.getEntPayService().entPay(wxEntPayRequest);
if ("SUCCESS".equals(wxEntPayResult.getResultCode().toUpperCase()) && "SUCCESS".equals(wxEntPayResult.getReturnCode().toUpperCase())) {
this.logger.info("企业对个人付款成功!\n付款信息:\n" + wxEntPayResult.toString());
RedisManager.getAgentRedisService().addRebate(agentId, -rebate, null, null);
// 充值记录
Charge charge = new Charge();
charge.setOrderId("" + tradeId);
charge.setUserid(agentId);
charge.setMoney(rebate);
charge.setMoney_point(rebate);
charge.setStatus(1);
charge.setSp_ip(ip);
charge.setRecharge_source("11");
// 充值类型
charge.setChargeType(0);
charge.setCreatetime(new Date());
chargeService.save(charge);
// redis 提现记录
RedisManager.getLogRedisService().logTakeOutNum(rebate);
SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss.SSS");
WxMpTemplateMessage templateMessage = WxMpTemplateMessage.builder().toUser(wxMpUser.getOpenId()).templateId("fT9wgjkN5Wfm8dtbPQiozDg7uftEaE6AoMq3YLDeUxc").url("").build();
String date = dateFormat.format(new Date());
templateMessage.addData(new WxMpTemplateData("first", "您申请的提现金额已到帐.")).addData(new WxMpTemplateData("keyword1", date)).addData(new WxMpTemplateData("keyword2", "提现到零钱")).addData(new WxMpTemplateData("keyword3", "" + amountInt)).addData(new WxMpTemplateData("remark", "感谢您的使用"));
wxService.getTemplateMsgService().sendTemplateMsg(templateMessage);
// 发送消息
return null;
// {{first.DATA}}{{fi
// 申请时间:{{keyword1.DATA}}
// 提现方式:{{keyword2.DATA}}
// 提现金额:{{keyword3.DATA}}
// 手续费用:{{keyword4.DATA}}
// 到账金额:{{keyword5.DATA}}
// {{remark.DATA}}
} else {
this.logger.error("err_code: " + wxEntPayResult.getErrCode() + " err_code_des: " + wxEntPayResult.getErrCodeDes());
}
} catch (Exception e) {
e.printStackTrace();
}
} catch (WxErrorException e) {
logger.error("提现出错", e);
return new TextBuilder().build(e.getMessage(), wxMessage, wxService);
} catch (SocketException e) {
e.printStackTrace();
}
return null;
}
use of me.chanjar.weixin.mp.bean.template.WxMpTemplateData in project fw-cloud-framework by liuweijw.
the class MessageServiceImpl method sendWeixinTemplateMessage.
@Override
@Deprecated
public boolean sendWeixinTemplateMessage(WxTemplateEnum wxTemplateEnum, MsgBean msgBean) throws WxErrorException {
if (null == wxTemplateEnum || null == msgBean)
return false;
WxMpTemplateMessageBuilder templateMessage = WxMpTemplateMessage.builder();
templateMessage.templateId(wxTemplateEnum.getTemplateId());
if (!StringHelper.isBlank(msgBean.getLinkUrl()))
templateMessage.url(msgBean.getLinkUrl());
List<WxMpTemplateData> data = new ArrayList<WxMpTemplateData>();
if (WxTemplateEnum.PUT_ORDER_SUC == wxTemplateEnum) {
/**
* {{first.DATA}} 商家名称:{{keyword1.DATA}} 下单时间:{{keyword2.DATA}} 商品明细:{{keyword3.DATA}} 订单金额:{{keyword4.DATA}} {{remark.DATA}}
*/
data.add(new WxMpTemplateData("first", msgBean.getFirst(), "#173177"));
data.add(new WxMpTemplateData("keyword1", msgBean.getKeyword1(), "#173177"));
data.add(new WxMpTemplateData("keyword2", msgBean.getKeyword2(), "#173177"));
data.add(new WxMpTemplateData("keyword3", msgBean.getKeyword3(), "#173177"));
data.add(new WxMpTemplateData("keyword4", msgBean.getKeyword4(), "#173177"));
data.add(new WxMpTemplateData("remark", msgBean.getRemark(), "#173177"));
} else if (WxTemplateEnum.PUT_ORDER_MSG == wxTemplateEnum) {
/**
* {{first.DATA}} 订单号:{{keyword1.DATA}} 金额:{{keyword2.DATA}} 时间:{{keyword3.DATA}} 买家:{{keyword4.DATA}} 联系方式:{{keyword5.DATA}} {{remark.DATA}}
*/
data.add(new WxMpTemplateData("first", msgBean.getFirst(), "#173177"));
data.add(new WxMpTemplateData("keyword1", msgBean.getKeyword1(), "#173177"));
data.add(new WxMpTemplateData("keyword2", msgBean.getKeyword2(), "#173177"));
data.add(new WxMpTemplateData("keyword3", msgBean.getKeyword3(), "#173177"));
data.add(new WxMpTemplateData("keyword4", msgBean.getKeyword4(), "#173177"));
data.add(new WxMpTemplateData("keyword5", msgBean.getKeyword5(), "#173177"));
data.add(new WxMpTemplateData("remark", msgBean.getRemark(), "#173177"));
} else if (WxTemplateEnum.PAY_ORDER_SUC == wxTemplateEnum) {
/**
* {{first.DATA}} 商品名称:{{keyword1.DATA}} 订单编号:{{keyword2.DATA}} 支付金额:{{keyword3.DATA}} {{remark.DATA}}
*/
data.add(new WxMpTemplateData("first", msgBean.getFirst(), "#173177"));
data.add(new WxMpTemplateData("keyword1", msgBean.getKeyword1(), "#173177"));
data.add(new WxMpTemplateData("keyword2", msgBean.getKeyword2(), "#173177"));
data.add(new WxMpTemplateData("keyword3", msgBean.getKeyword3(), "#173177"));
data.add(new WxMpTemplateData("remark", msgBean.getRemark(), "#173177"));
} else if (WxTemplateEnum.PUT_ORDER_CANCEL == wxTemplateEnum) {
/**
* {{first.DATA}} 订单编号:{{keyword1.DATA}} 订单金额:{{keyword2.DATA}} {{remark.DATA}}
*/
data.add(new WxMpTemplateData("first", msgBean.getFirst(), "#173177"));
data.add(new WxMpTemplateData("keyword1", msgBean.getKeyword1(), "#173177"));
data.add(new WxMpTemplateData("keyword2", msgBean.getKeyword2(), "#173177"));
data.add(new WxMpTemplateData("remark", msgBean.getRemark(), "#173177"));
} else if (WxTemplateEnum.PUT_ORDER_MODIFY == wxTemplateEnum) {
/**
* {{first.DATA}} 门店名称:{{keyword1.DATA}} 订单编号:{{keyword2.DATA}} 修改内容:{{keyword3.DATA}} 修改时间:{{keyword4.DATA}} {{remark.DATA}}
*/
data.add(new WxMpTemplateData("first", msgBean.getFirst(), "#173177"));
data.add(new WxMpTemplateData("keyword1", msgBean.getKeyword1(), "#173177"));
data.add(new WxMpTemplateData("keyword2", msgBean.getKeyword2(), "#173177"));
data.add(new WxMpTemplateData("keyword3", msgBean.getKeyword3(), "#173177"));
data.add(new WxMpTemplateData("keyword4", msgBean.getKeyword4(), "#173177"));
data.add(new WxMpTemplateData("remark", msgBean.getRemark(), "#173177"));
}
templateMessage.data(data);
WxMpTemplateMessage toMessage = null;
List<String> toUsers = msgBean.getToUser();
if (null != toUsers && toUsers.size() > 0) {
for (String toUser : toUsers) {
templateMessage.toUser(toUser.trim());
toMessage = templateMessage.build();
log.info("|send template msg start|" + toMessage.toString());
String returnMsg = wxMpService.getTemplateMsgService().sendTemplateMsg(toMessage);
log.info("|send template msg end |" + returnMsg);
}
}
return true;
}
use of me.chanjar.weixin.mp.bean.template.WxMpTemplateData in project fw-cloud-framework by liuweijw.
the class MessageServiceImpl method sendWeixinCurrencyTemplateMessage.
@Override
public boolean sendWeixinCurrencyTemplateMessage(MsgBean msgBean) throws WxErrorException {
if (null == msgBean)
throw new WxErrorException(WxError.builder().errorCode(500).errorMsg("消息内容不能为空").build());
if (StringHelper.isBlank(msgBean.getTemplateId()))
throw new WxErrorException(WxError.builder().errorCode(500).errorMsg("消息内容不能为空").build());
WxMpTemplateMessageBuilder templateMessage = WxMpTemplateMessage.builder();
templateMessage.templateId(msgBean.getTemplateId());
if (!StringHelper.isBlank(msgBean.getLinkUrl()))
templateMessage.url(msgBean.getLinkUrl());
List<WxMpTemplateData> data = new ArrayList<WxMpTemplateData>();
if (StringHelper.isNotBlank(msgBean.getFirst()))
data.add(new WxMpTemplateData("first", msgBean.getFirst(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword1()))
data.add(new WxMpTemplateData("keyword1", msgBean.getKeyword1(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword2()))
data.add(new WxMpTemplateData("keyword2", msgBean.getKeyword2(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword3()))
data.add(new WxMpTemplateData("keyword3", msgBean.getKeyword3(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword4()))
data.add(new WxMpTemplateData("keyword4", msgBean.getKeyword4(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getKeyword5()))
data.add(new WxMpTemplateData("keyword5", msgBean.getKeyword5(), "#173177"));
if (StringHelper.isNotBlank(msgBean.getRemark()))
data.add(new WxMpTemplateData("remark", msgBean.getRemark(), "#173177"));
templateMessage.data(data);
WxMpTemplateMessage toMessage = null;
List<String> toUsers = msgBean.getToUser();
if (null != toUsers && toUsers.size() > 0) {
for (String toUser : toUsers) {
templateMessage.toUser(toUser.trim());
toMessage = templateMessage.build();
log.info("|send template msg start|" + toMessage.toString());
String returnMsg = wxMpService.getTemplateMsgService().sendTemplateMsg(toMessage);
log.info("|send template msg end |" + returnMsg);
}
}
return true;
}
Aggregations