| @@ -8,3 +8,8 @@ INSERT INTO `mallink`.`wx_msg_validationcode_model`(`id`, `tenant_id`, `parent_t | |||||
| -- INSERT INTO `mallink`.`wx_msg_validationcode_model`(`id`, `tenant_id`, `parent_tenant_id`, `type`, `name`, `signature`, `content`, `createtime`, `status`, `minutes`, `model_id`, `email_bg_img`, `open`, `msg_type`, `role_type`, `model_code`) VALUES (666429058237590158, '1028', NULL, 32, '抖音购买通知', '富茂', '您已成功购买[${name}],可在“抖音app>我>右上角≡>我的订单>查看全部”,务必到店之后进行核销,谨防上当受骗。http://ob4.cn/${sortUrl}', '2022-03-29 10:57:59', 1, 0, NULL, NULL, 0, 1, 0, 'SMS_237590158'); | -- INSERT INTO `mallink`.`wx_msg_validationcode_model`(`id`, `tenant_id`, `parent_tenant_id`, `type`, `name`, `signature`, `content`, `createtime`, `status`, `minutes`, `model_id`, `email_bg_img`, `open`, `msg_type`, `role_type`, `model_code`) VALUES (666429058237590158, '1028', NULL, 32, '抖音购买通知', '富茂', '您已成功购买[${name}],可在“抖音app>我>右上角≡>我的订单>查看全部”,务必到店之后进行核销,谨防上当受骗。http://ob4.cn/${sortUrl}', '2022-03-29 10:57:59', 1, 0, NULL, NULL, 0, 1, 0, 'SMS_237590158'); | ||||
| INSERT INTO `mallink`.`wx_template_msg`(`id`, `tenant_id`, `parent_tenant_id`, `template_id`, `type`, `custom_param`, `create_date`, `update_date`, `on_off`) VALUES (1506450152111814573, '1028', NULL, 'MSG1313619f9822f740ceb30d99db03484fb16dd1814573', 60, null, '2022-03-31 09:57:59', '2022-03-31 09:57:59', 0); | |||||
| @@ -48,4 +48,21 @@ public class WxMsgController extends BaseController { | |||||
| return new ResultData(page); | return new ResultData(page); | ||||
| } | } | ||||
| @ApiOperation("模板分页列表接口") | |||||
| @GetMapping("ttTemplateList") | |||||
| @ApiImplicitParams({ | |||||
| @ApiImplicitParam(name = "pageNum", value = "页数", dataType = "int", paramType = "query", required = true), | |||||
| @ApiImplicitParam(name = "pageSize", value = "每页条数", dataType = "int", paramType = "query", required = true)}) | |||||
| public ResultData ttTemplateList(@ModelAttribute WxTemplateMsg wxTemplateMsg, Integer pageNum, Integer pageSize) { | |||||
| logger.debug("[" + getIpAddr() + "] WxMsgController::list"); | |||||
| if (null == wxTemplateMsg) wxTemplateMsg = new WxTemplateMsg(); | |||||
| wxTemplateMsg.updateTenantInfo(getTenantInfo()); | |||||
| List<Integer> types = new ArrayList<>(); | |||||
| types.add(EnumTemplateType.TT_SEND_COUPON_REMIND.getCode()); | |||||
| wxTemplateMsg.setTypes(types); | |||||
| wxTemplateMsg.setIsc(true); | |||||
| final PageInfo<WxTemplateMsg> page = wxTemplateMsgService.listAsPageForMiniApp(wxTemplateMsg, pageNum, pageSize); | |||||
| return new ResultData(page); | |||||
| } | |||||
| } | } | ||||
| @@ -31,4 +31,7 @@ public class SmartAppMsg extends BaseMsg { | |||||
| private String gotopage; | private String gotopage; | ||||
| @io.swagger.annotations.ApiModelProperty(value="小程序模板参数列表",name="dataList") | @io.swagger.annotations.ApiModelProperty(value="小程序模板参数列表",name="dataList") | ||||
| private List<String> dataList; | private List<String> dataList; | ||||
| @io.swagger.annotations.ApiModelProperty(value="tt小程序模板参数列表",name="dataJson") | |||||
| private String dataJson; | |||||
| } | } | ||||
| @@ -1,12 +1,10 @@ | |||||
| package com.iformall.douyin.miniapp.api.bean; | package com.iformall.douyin.miniapp.api.bean; | ||||
| import cn.binarywang.wx.miniapp.constant.WxMaConstants; | |||||
| import cn.binarywang.wx.miniapp.util.json.WxMaGsonBuilder; | |||||
| import com.alibaba.fastjson.JSONObject; | |||||
| import com.google.gson.JsonObject; | |||||
| import lombok.*; | import lombok.*; | ||||
| import java.io.Serializable; | import java.io.Serializable; | ||||
| import java.util.ArrayList; | |||||
| import java.util.List; | |||||
| /** | /** | ||||
| * 订阅消息. | * 订阅消息. | ||||
| @@ -64,31 +62,10 @@ public class TtMaSubscribeMessage implements Serializable { | |||||
| * 描述: 模板内容,不填则下发空模板 | * 描述: 模板内容,不填则下发空模板 | ||||
| * </pre> | * </pre> | ||||
| */ | */ | ||||
| private List<Data> data; | |||||
| public TtMaSubscribeMessage addData(Data datum) { | |||||
| if (this.data == null) { | |||||
| this.data = new ArrayList<>(); | |||||
| } | |||||
| this.data.add(datum); | |||||
| return this; | |||||
| } | |||||
| private JsonObject data; | |||||
| public String toJson() { | public String toJson() { | ||||
| return TtMaGsonBuilder.create().toJson(this); | return TtMaGsonBuilder.create().toJson(this); | ||||
| } | } | ||||
| @lombok.Data | |||||
| @NoArgsConstructor | |||||
| @AllArgsConstructor | |||||
| public static class Data implements Serializable { | |||||
| private static final long serialVersionUID = 1L; | |||||
| private String name; | |||||
| private String value; | |||||
| } | |||||
| } | } | ||||
| @@ -25,18 +25,7 @@ public class TtMaSubscribeMessageGsonAdapter implements JsonSerializer<TtMaSubsc | |||||
| messageJson.addProperty("page", message.getPage()); | messageJson.addProperty("page", message.getPage()); | ||||
| } | } | ||||
| JsonObject data = new JsonObject(); | |||||
| messageJson.add("data", data); | |||||
| if (message.getData() == null) { | |||||
| return messageJson; | |||||
| } | |||||
| for (TtMaSubscribeMessage.Data datum : message.getData()) { | |||||
| JsonObject dataJson = new JsonObject(); | |||||
| dataJson.addProperty("value", datum.getValue()); | |||||
| data.add(datum.getName(), dataJson); | |||||
| } | |||||
| messageJson.add("data", message.getData()); | |||||
| return messageJson; | return messageJson; | ||||
| } | } | ||||
| @@ -19,6 +19,8 @@ public enum EnumTemplateType { | |||||
| CREDIT_UPD_REMIND(50, "积分变更提醒","310"), // 小程序 | CREDIT_UPD_REMIND(50, "积分变更提醒","310"), // 小程序 | ||||
| SEND_COUPON_REMIND(51, "优惠券到账提醒","3209"), // 小程序 | SEND_COUPON_REMIND(51, "优惠券到账提醒","3209"), // 小程序 | ||||
| TT_SEND_COUPON_REMIND(60, "优惠券到账提醒",""), // 抖音小程序 | |||||
| AUDIT_MESSAGE(101, "公众号审核结果通知",""), // 公众号 | AUDIT_MESSAGE(101, "公众号审核结果通知",""), // 公众号 | ||||
| VERIFY_RESULT(102, "公众号卡券核销通知",""), // 公众号 | VERIFY_RESULT(102, "公众号卡券核销通知",""), // 公众号 | ||||
| GIFT_MESSAGE(103, "公众号购票成功通知",""), // 公众号 | GIFT_MESSAGE(103, "公众号购票成功通知",""), // 公众号 | ||||
| @@ -41,6 +41,8 @@ public interface WxMsgService { | |||||
| void addMsgCallback(WxMsg wxmsg, String batchNo); | void addMsgCallback(WxMsg wxmsg, String batchNo); | ||||
| void batchSendAppinfo(WxMsg wxMsg); | void batchSendAppinfo(WxMsg wxMsg); | ||||
| void batchSendTtAppinfo(WxMsg msg); | |||||
| void batchSendMsg(WxMsg wxMsg, WxMsgConfig wxMsgConfig, WxCouponInject couponInject); | void batchSendMsg(WxMsg wxMsg, WxMsgConfig wxMsgConfig, WxCouponInject couponInject); | ||||
| } | } | ||||
| @@ -80,8 +80,6 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||||
| @Lazy | @Lazy | ||||
| @Autowired | @Autowired | ||||
| WxAppinfoService wxAppinfoService; | WxAppinfoService wxAppinfoService; | ||||
| @Autowired | |||||
| WxAuthorizerInfoMapper authorizerInfoMapper; | |||||
| @Lazy | @Lazy | ||||
| @Autowired | @Autowired | ||||
| @@ -89,14 +87,6 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||||
| @Autowired | @Autowired | ||||
| WxCouponMerchantMapper wxCouponMerchantMapper; | WxCouponMerchantMapper wxCouponMerchantMapper; | ||||
| @Lazy | |||||
| @Autowired | |||||
| WxTemplateMsgService wxTemplateMsgService; | |||||
| @Lazy | |||||
| @Autowired | |||||
| private WxMsgService wxMsgService; | |||||
| @Autowired | @Autowired | ||||
| WxCouponMapper wxCouponMapper; | WxCouponMapper wxCouponMapper; | ||||
| @@ -590,27 +580,11 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||||
| return bRet; | return bRet; | ||||
| } | } | ||||
| private void sendMsgForSendCoupon(TenantEntity tenantEntity, WxCouponSend send, WxCouponOrder couponOrder, WxCUserBasicInfo user) { | |||||
| WxCUser wcuQ = new WxCUser(); | |||||
| wcuQ.updateTenantInfo(tenantEntity); | |||||
| wcuQ.setUserId(couponOrder.getCUserId()); | |||||
| List<WxCUser> list = wxCUserMapper.findList(wcuQ); | |||||
| if(list != null && list.size() > 0){ | |||||
| for (WxCUser cuser:list) { | |||||
| //发订阅消息 | |||||
| sendCouponRemind(send, couponOrder, cuser); | |||||
| // 发送微信模板消息(公众号模板消息/小程序统一消息/小程序模板消息) | |||||
| sendMpMsgForSendCoupon(send, couponOrder, cuser); | |||||
| } | |||||
| } | |||||
| private void sendMsgForSendCoupon(TenantEntity tenantEntity,WxCouponSend send, WxCouponOrder couponOrder, WxCUserBasicInfo user) { | |||||
| // 发送短信 | // 发送短信 | ||||
| if (send.getSendSms().equals(EnumCouponSendSms.YES.getCode())) { | if (send.getSendSms().equals(EnumCouponSendSms.YES.getCode())) { | ||||
| logger.info("》》》》》》》》》》》"); | |||||
| logger.info("场景投放发送短信开始"); | |||||
| logger.info("》》》》》》》》》》》"); | |||||
| logger.info("》》》场景投放发送短信开始》》》"); | |||||
| //券名 | //券名 | ||||
| String title = send.getTitle(); | String title = send.getTitle(); | ||||
| //找出用户手机号 | //找出用户手机号 | ||||
| @@ -621,7 +595,7 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||||
| String appName = ""; | String appName = ""; | ||||
| if(payw.getType() == null) { | if(payw.getType() == null) { | ||||
| WxAppinfo appinfoQ = new WxAppinfo(); | WxAppinfo appinfoQ = new WxAppinfo(); | ||||
| appinfoQ.setPlat(EnumPayWay.PAY_WAY_WECHAT.getPlat().getCode()); | |||||
| // appinfoQ.setPlat(EnumPayWay.PAY_WAY_WECHAT.getPlat().getCode()); | |||||
| appinfoQ.updateTenantInfo(tenantEntity); | appinfoQ.updateTenantInfo(tenantEntity); | ||||
| appinfoQ.setType(EnumAppType.C.getCode()); | appinfoQ.setType(EnumAppType.C.getCode()); | ||||
| List<WxAppinfo> appList = wxAppinfoService.getList(appinfoQ); | List<WxAppinfo> appList = wxAppinfoService.getList(appinfoQ); | ||||
| @@ -641,142 +615,8 @@ public class WxCouponSendServiceImpl implements WxCouponSendService { | |||||
| wxMsgRecord.updateTenantInfo(tenantEntity); | wxMsgRecord.updateTenantInfo(tenantEntity); | ||||
| wxMsgRecord.setDynamicContentMap(msgReplaceMap); | wxMsgRecord.setDynamicContentMap(msgReplaceMap); | ||||
| mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | mqBaseProducer.sendMessage(wxMsgRecord, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | ||||
| logger.info("》》》》》》》》》》》"); | |||||
| logger.info("场景投放发送短信结束"); | |||||
| logger.info("》》》》》》》》》》》"); | |||||
| } | |||||
| } | |||||
| private void sendCouponRemind(WxCouponSend send, WxCouponOrder couponOrder,WxCUser cuser){ | |||||
| try { | |||||
| WxTemplateMsg temp = new WxTemplateMsg(); | |||||
| temp.updateTenantInfo(send); | |||||
| temp.setType(EnumTemplateType.SEND_COUPON_REMIND.getCode()); | |||||
| temp = wxTemplateMsgService.getByObj(temp); | |||||
| if(temp.getId() != null){ | |||||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||||
| WxMsg msg = new WxMsg(); | |||||
| msg.updateTenantInfo(send); | |||||
| msg.setPhones(cuser.getOpenId()); | |||||
| msg.setModelId(temp.getId()); | |||||
| Map<String,String> map = new HashMap<>(); | |||||
| map.put("thing1",send.getTitle()); | |||||
| map.put("time3",dateFormat.format(couponOrder.getCreateDate())); | |||||
| map.put("time4",dateFormat.format(couponOrder.getExpiredTime())); | |||||
| map.put("thing5","你的优惠券已到账!请立即使用"); | |||||
| if(EnumCouponType.COUPON_TINGCHE.getCode().equals(couponOrder.getCouponType()) | |||||
| || EnumCouponType.COUPON_CREDIT_PARK.getCode().equals(couponOrder.getCouponType())){ | |||||
| map.put("goToPage","pages/index/index?type=in"); | |||||
| }else{ | |||||
| map.put("goToPage","pages/index/index?type=mc"); | |||||
| } | |||||
| msg.setMsg(JSONObject.toJSONString(map)); | |||||
| wxMsgService.batchSendAppinfo(msg); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| // e.printStackTrace(); | |||||
| logger.error("发卷消息发送异常"); | |||||
| } | |||||
| } | |||||
| private boolean sendMpMsgForSendCoupon(WxCouponSend send, WxCouponOrder couponOrder, WxCUser user) { | |||||
| // 发送 公众号 模板消息 | |||||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||||
| String gotopage = Constant.mainPageUrl + "?type=mc"; | |||||
| // 7. 公众号消息 | |||||
| if (StringUtils.isNotBlank(user.getMpAppId()) && | |||||
| StringUtils.isNotBlank(user.getMpOpenId()) && | |||||
| user.getMpSubscribe().equals(EnumUserIsSubscribe.YES.getCode())) { | |||||
| // 检查是否超限 | |||||
| WxMsgLimit msgLimit = new WxMsgLimit(); | |||||
| msgLimit.updateTenantInfo(couponOrder); | |||||
| msgLimit.setType(EnumMsgLimitType.WXCHAT_OPENID_SEND.getCode()); | |||||
| msgLimit.setLimitId(user.getMpOpenId()); | |||||
| if (wxMsgLimitService.checkIsLimit(msgLimit)) { | |||||
| logger.error("用户公众号模板消息超限" + user.getId()); | |||||
| return true; | |||||
| } | |||||
| // 已关注公众号 | |||||
| /** | |||||
| * 购票成功通知 | |||||
| * {first.DATA}} | |||||
| * 订单号:{{keyword1.DATA}} | |||||
| * 兑换券:{{keyword2.DATA}} | |||||
| * 订单详情:{{keyword3.DATA}} | |||||
| * 有效期至:{{keyword4.DATA}} | |||||
| * 购买数量:{{keyword5.DATA}} | |||||
| * {{remark.DATA}} | |||||
| */ | |||||
| MpAppMsg mpAppMsg = new MpAppMsg(); | |||||
| mpAppMsg.setMsgType(EnumMsgRecordType.PUBLIC.getCode()); | |||||
| mpAppMsg.setAppId(user.getMpAppId()); | |||||
| mpAppMsg.setTo(user.getMpOpenId()); | |||||
| mpAppMsg.setMiniAppId(user.getAppId()); | |||||
| mpAppMsg.setMiniPagePath(gotopage); | |||||
| mpAppMsg.updateTenantInfo(couponOrder); | |||||
| mpAppMsg.setTemplateType(EnumTemplateType.GIFT_MESSAGE.getCode()); | |||||
| mpAppMsg.setDataList(Lists.newArrayList( | |||||
| user.getNickName(), | |||||
| String.valueOf(couponOrder.getOrderId()), | |||||
| couponOrder.getId().toString(), | |||||
| send.getTitle(), | |||||
| dateFormat.format(couponOrder.getExpiredTime()), | |||||
| "1", | |||||
| user.getNickName() | |||||
| )); | |||||
| try { | |||||
| mqBaseProducer.sendMessage(mpAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| } catch (Exception e) { | |||||
| logger.error("购票成功-公众号-模板消息发送失败: " + e.getMessage()); | |||||
| //throw new MallinkException(ErrorCode.MP_TEMPLATE_SEND_FAILED); | |||||
| } | |||||
| } else { | |||||
| // 可能未关注公众号, 用户可能收不到 | |||||
| // 8. 微信小程序-统一消息 | |||||
| // 检查是否超限 | |||||
| WxMsgLimit msgLimit = new WxMsgLimit(); | |||||
| msgLimit.updateTenantInfo(couponOrder); | |||||
| msgLimit.setType(EnumMsgLimitType.WEAPP_OPENID_SEND.getCode()); | |||||
| msgLimit.setLimitId(user.getOpenId()); | |||||
| if (wxMsgLimitService.checkIsLimit(msgLimit)) { | |||||
| logger.error("用户小程序统一模板消息超限:" + user.getId()); | |||||
| return true; | |||||
| } | |||||
| // 获取小程序关联的服务号 | |||||
| WxAuthorizerInfo authQ = new WxAuthorizerInfo(); | |||||
| authQ.setAuthorizerAppid(user.getAppId()); | |||||
| authQ.updateTenantInfo(couponOrder); | |||||
| WxAuthorizerInfo weappInfo = authorizerInfoMapper.findMp(authQ); | |||||
| if (weappInfo != null) { | |||||
| AppUniformMsg appUniformMsg = new AppUniformMsg(); | |||||
| appUniformMsg.setMsgType(EnumMsgRecordType.SMART_APP_UNIFORM.getCode()); | |||||
| appUniformMsg.setAppId(user.getAppId()); | |||||
| appUniformMsg.setTo(user.getOpenId()); | |||||
| appUniformMsg.setTemplateType(EnumTemplateType.GIFT_MESSAGE.getCode()); | |||||
| appUniformMsg.setPagePath(gotopage); | |||||
| appUniformMsg.setMpAppId(weappInfo.getAuthorizerAppid()); | |||||
| appUniformMsg.setDataList(Lists.newArrayList( | |||||
| user.getNickName(), | |||||
| String.valueOf(couponOrder.getOrderId()), | |||||
| couponOrder.getId().toString(), | |||||
| send.getTitle(), | |||||
| dateFormat.format(couponOrder.getExpiredTime()), | |||||
| "1", | |||||
| user.getNickName() | |||||
| )); | |||||
| try { | |||||
| mqBaseProducer.sendMessage(appUniformMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| } catch (Exception e) { | |||||
| logger.error("核销-公众号-模板消息发送失败: " + e.getMessage()); | |||||
| //throw new MallinkException(ErrorCode.UNIFORM_SEND_FAILED); | |||||
| } | |||||
| } | |||||
| logger.info("》》》场景投放发送短信结束》》》"); | |||||
| } | } | ||||
| return false; | |||||
| } | } | ||||
| @Override | @Override | ||||
| @@ -15,6 +15,7 @@ import com.iformall.domain.po.*; | |||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| import com.iformall.domain.po.msg.SmartAppMsg; | import com.iformall.domain.po.msg.SmartAppMsg; | ||||
| import com.iformall.domain.po.msg.WxMsg; | import com.iformall.domain.po.msg.WxMsg; | ||||
| import com.iformall.domain.po.tt.TtCUser; | |||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.mapper.*; | import com.iformall.mapper.*; | ||||
| @@ -85,6 +86,10 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| @Autowired | @Autowired | ||||
| WxCUserService wxCUserService; | WxCUserService wxCUserService; | ||||
| @Lazy | |||||
| @Autowired | |||||
| TtCUserService ttCUserService; | |||||
| @Override | @Override | ||||
| public PageInfo<WxMsg> listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxMsg> listAsPage(WxMsg record, Integer pageIndex, Integer pageSize) { | ||||
| PageHelper.startPage(pageIndex, pageSize); | PageHelper.startPage(pageIndex, pageSize); | ||||
| @@ -504,6 +509,82 @@ public class WxMsgServiceImpl implements WxMsgService { | |||||
| } | } | ||||
| @Override | |||||
| public void batchSendTtAppinfo(WxMsg msg) { | |||||
| TenantEntity tenantEntity = new TenantEntity(); | |||||
| tenantEntity.setTenantId(msg.getTenantId()); | |||||
| tenantEntity.setParentTenantId(msg.getParentTenantId()); | |||||
| WxAppinfo cAppInfo = wxAppinfoService.getCAppInfo(tenantEntity, EnumAppPlat.TOUTIAO); | |||||
| SmartAppMsg smartAppMsg = new SmartAppMsg(); | |||||
| smartAppMsg.updateTenantInfo(tenantEntity); | |||||
| smartAppMsg.setMsgType(EnumMsgRecordType.SMART_APP_TO.getCode()); | |||||
| smartAppMsg.setAppId(cAppInfo.getAppId()); | |||||
| WxTemplateMsg wxTemplateMsg = wxTemplateMsgMapper.selectById(msg.getModelId()); | |||||
| // if(1 == wxTemplateMsg.getOnOff().intValue()){ | |||||
| // logger.error("订阅消息模板关闭。"); | |||||
| // return; | |||||
| // } | |||||
| smartAppMsg.setTemplateType(wxTemplateMsg.getType()); | |||||
| JSONObject customParam = JSON.parseObject(msg.getMsg()); | |||||
| String goToPage = customParam.getString("goToPage"); | |||||
| if(StringUtils.isBlank(goToPage)){ | |||||
| goToPage = "pages/index/index?type=in";//默认首页 | |||||
| } | |||||
| smartAppMsg.setGotopage(goToPage); | |||||
| if(wxTemplateMsg.getType() == EnumTemplateType.TT_SEND_COUPON_REMIND.getCode()){ | |||||
| smartAppMsg.setDataJson(msg.getMsg()); | |||||
| }else{ | |||||
| return; | |||||
| } | |||||
| if(StringUtils.isNotBlank(msg.getPhones())){ | |||||
| smartAppMsg.setTo(msg.getPhones()); | |||||
| mqBaseProducer.sendMessage(smartAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| // String[] split = wxMsg.getPhones().split(","); | |||||
| // int length = split.length; | |||||
| // int extra = length % 1000; | |||||
| // int extracount = extra > 0 ? (length / 1000 + 1) : (length / 1000); | |||||
| // int index = extracount - 1; | |||||
| // for (int i = 0; i < extracount; i++) { | |||||
| // if (extra > 0 && i == index) { | |||||
| // List<String> phoneList = Arrays.asList(split).subList(i * 1000, length); | |||||
| // String phones = StringUtils.join(phoneList, ","); | |||||
| // smartAppMsg.setTo(phones); | |||||
| // mqBaseProducer.sendMessage(smartAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| // } else { | |||||
| // List<String> phoneList = Arrays.asList(split).subList(i * 1000, (i + 1) * 1000); | |||||
| // String phones = StringUtils.join(phoneList, ","); | |||||
| // smartAppMsg.setTo(phones); | |||||
| // mqBaseProducer.sendMessage(smartAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| // } | |||||
| // } | |||||
| }else{ | |||||
| TtCUser ttCUserQ = new TtCUser(); | |||||
| ttCUserQ.updateTenantInfo(tenantEntity); | |||||
| PageInfo<String> openIdPage = ttCUserService.listOpenIdAsPage(ttCUserQ, 1, 1000); | |||||
| msg.setExpectSendNumber((int) openIdPage.getTotal()); | |||||
| if(openIdPage.getTotal() == 0){ | |||||
| return; | |||||
| } | |||||
| String phones = StringUtils.join(openIdPage.getList(), ","); | |||||
| smartAppMsg.setTo(phones); | |||||
| mqBaseProducer.sendMessage(smartAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| if(openIdPage.getPages() > 1){ | |||||
| for(int i=2;i<=openIdPage.getPages();i++){ | |||||
| openIdPage = ttCUserService.listOpenIdAsPage(ttCUserQ, i, 1000); | |||||
| phones = StringUtils.join(openIdPage.getList(), ","); | |||||
| smartAppMsg.setTo(phones); | |||||
| mqBaseProducer.sendMessage(smartAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| @Override | @Override | ||||
| public void addMsgCallback(WxMsg wxmsg, String batchNo) { | public void addMsgCallback(WxMsg wxmsg, String batchNo) { | ||||
| @@ -16,11 +16,13 @@ import java.util.stream.Collectors; | |||||
| import javax.servlet.http.HttpServletRequest; | import javax.servlet.http.HttpServletRequest; | ||||
| import javax.servlet.http.HttpServletResponse; | import javax.servlet.http.HttpServletResponse; | ||||
| import com.google.common.collect.Lists; | |||||
| import com.iformall.domain.po.*; | import com.iformall.domain.po.*; | ||||
| import com.iformall.domain.po.msg.FmInsideOrderPushMsg; | |||||
| import com.iformall.domain.po.msg.WxMsgRecord; | |||||
| import com.iformall.domain.po.msg.*; | |||||
| import com.iformall.domain.po.tt.TtCUser; | |||||
| import com.iformall.domain.vo.*; | import com.iformall.domain.vo.*; | ||||
| import com.iformall.enums.*; | import com.iformall.enums.*; | ||||
| import com.iformall.mapper.*; | |||||
| import com.iformall.service.*; | import com.iformall.service.*; | ||||
| import com.iformall.service.order.OrderAdapterService; | import com.iformall.service.order.OrderAdapterService; | ||||
| import com.iformall.service.order.OrderFactory; | import com.iformall.service.order.OrderFactory; | ||||
| @@ -30,6 +32,7 @@ import com.iformall.service.order.entity.WxComposeOrder; | |||||
| import com.iformall.service.order.util.OrderHelper; | import com.iformall.service.order.util.OrderHelper; | ||||
| import com.iformall.service.pay.PayServiceFactory; | import com.iformall.service.pay.PayServiceFactory; | ||||
| import com.iformall.utils.*; | |||||
| import org.apache.commons.lang3.StringUtils; | import org.apache.commons.lang3.StringUtils; | ||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| @@ -55,31 +58,8 @@ import com.iformall.domain.dto.OrderComposeSaveDto; | |||||
| import com.iformall.domain.dto.OrderSaveDto; | import com.iformall.domain.dto.OrderSaveDto; | ||||
| import com.iformall.domain.dto.WxSharingOrderDto; | import com.iformall.domain.dto.WxSharingOrderDto; | ||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| import com.iformall.domain.po.msg.FmInsideOrderSuccessMsg; | |||||
| import com.iformall.exception.MallinkException; | import com.iformall.exception.MallinkException; | ||||
| import com.iformall.mapper.WxAppinfoMapper; | |||||
| import com.iformall.mapper.WxBatchOrderMapper; | |||||
| import com.iformall.mapper.WxCUserBasicInfoMapper; | |||||
| import com.iformall.mapper.WxCUserMapper; | |||||
| import com.iformall.mapper.WxCardInfoMapper; | |||||
| import com.iformall.mapper.WxCouponChannelMapper; | |||||
| import com.iformall.mapper.WxCouponMapper; | |||||
| import com.iformall.mapper.WxCouponMerchantMapper; | |||||
| import com.iformall.mapper.WxCouponOrderMapper; | |||||
| import com.iformall.mapper.WxCouponPasswordMapper; | |||||
| import com.iformall.mapper.WxMallMapper; | |||||
| import com.iformall.mapper.WxMerchantBUserMapper; | |||||
| import com.iformall.mapper.WxMerchantMapper; | |||||
| import com.iformall.mapper.WxOrderGroupMapper; | |||||
| import com.iformall.mapper.WxOrderMapper; | |||||
| import com.iformall.mapper.WxOrderPressMapper; | |||||
| import com.iformall.mapper.WxPayAccountMapper; | |||||
| import com.iformall.mapper.WxPayOrderMapper; | |||||
| import com.iformall.mq.MqBaseProducer; | import com.iformall.mq.MqBaseProducer; | ||||
| import com.iformall.utils.DateUtils; | |||||
| import com.iformall.utils.PressUtils; | |||||
| import com.iformall.utils.RedisLock; | |||||
| import com.iformall.utils.Utility; | |||||
| @Service | @Service | ||||
| @@ -105,6 +85,9 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| @Autowired | @Autowired | ||||
| WxCUserMapper wxCUserMapper; | WxCUserMapper wxCUserMapper; | ||||
| @Autowired | |||||
| TtCUserMapper ttCUserMapper; | |||||
| @Autowired | @Autowired | ||||
| WxCouponMapper wxCouponMapper; | WxCouponMapper wxCouponMapper; | ||||
| @@ -192,6 +175,9 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| @Autowired | @Autowired | ||||
| private WxCouponPasswordMapper couponPasswordMapper; | private WxCouponPasswordMapper couponPasswordMapper; | ||||
| @Autowired | |||||
| WxAuthorizerInfoMapper authorizerInfoMapper; | |||||
| @Autowired | @Autowired | ||||
| ExcelService excelService; | ExcelService excelService; | ||||
| @@ -219,6 +205,14 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| @Lazy | @Lazy | ||||
| @Autowired | @Autowired | ||||
| WxMerchantService wxMerchantService; | WxMerchantService wxMerchantService; | ||||
| @Lazy | |||||
| @Autowired | |||||
| WxTemplateMsgService wxTemplateMsgService; | |||||
| @Lazy | |||||
| @Autowired | |||||
| private WxMsgService wxMsgService; | |||||
| @Override | @Override | ||||
| public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | public PageInfo<WxOrder> listAsPage(WxOrder record, Integer pageIndex, Integer pageSize) { | ||||
| @@ -1412,67 +1406,73 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| /// 储值卡信息添加 | /// 储值卡信息添加 | ||||
| if (isCard) { | if (isCard) { | ||||
| Integer fee = 0; | |||||
| WxCardInfo cardInfo = new WxCardInfo(); | |||||
| cardInfo.setId(couponOrder.getId()); | |||||
| cardInfo.updateTenantInfo(order); | |||||
| cardInfo.setCouponId(order.getProductId()); | |||||
| cardInfo.setAmount(coupon.getPrice()); | |||||
| cardInfo.setSaleAmount(coupon.getSalePrice()); | |||||
| cardInfo.setRemainingAmount(coupon.getPrice()); | |||||
| if (!coupon.checkIsFree()) { | |||||
| //判断该transctionId是否已经存在,如果存在,则不添加 | |||||
| WxCardInfo cardInfoq = new WxCardInfo(); | |||||
| cardInfoq.setTransactionId(payOrder.getTransactionId()); | |||||
| List<WxCardInfo> cardInfoList = wxCardInfoMapper.findList(cardInfoq); | |||||
| if (null != cardInfoList && cardInfoList.size() > 0) { | |||||
| //do nothing | |||||
| }else { | |||||
| // 有价卡 | |||||
| cardInfo.setTransactionId(payOrder.getTransactionId()); | |||||
| if (payOrder.getShareAmount() != null) { | |||||
| // 开启分账 | |||||
| WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); | |||||
| fee = share.getRealPayMent() - share.getShareAmount(); | |||||
| cardInfo.setShareFeeAmount(share.getShareAmount()); | |||||
| cardInfo.setRemainingShareFeeAmount(share.getShareAmount()); | |||||
| cardInfo.setRateAmount(share.getRateAmount()); | |||||
| } else { | |||||
| // 未开启分账 | |||||
| Integer orderRealPayMent = payOrder.getChildOrderShare(order.getId()).getRealPayMent(); | |||||
| fee = OrderHelper.getMallCharge(orderRealPayMent, payAccount); | |||||
| Integer shareAmount = orderRealPayMent - fee; | |||||
| cardInfo.setShareFeeAmount(shareAmount); | |||||
| cardInfo.setRemainingShareFeeAmount(shareAmount); | |||||
| cardInfo.setRateAmount(OrderHelper.getRateAmount(orderRealPayMent, fee, payAccount)); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| // 免费卡 | |||||
| cardInfo.setShareFeeAmount(0); | |||||
| cardInfo.setRemainingShareFeeAmount(0); | |||||
| cardInfo.setRateAmount(0); | |||||
| if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | |||||
| WxCouponPassword updateCPwd = new WxCouponPassword(); | |||||
| updateCPwd.setId(couponPasswordId); | |||||
| updateCPwd.setCardId(cardInfo.getId()); | |||||
| updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||||
| couponPasswordMapper.updateById(updateCPwd); | |||||
| } | |||||
| } | |||||
| cardInfo.setServiceFeeAmount(fee); | |||||
| cardInfo.setCreateDate(curr); | |||||
| cardInfo.setUpdateDate(curr); | |||||
| cardInfo.setSupportTransfer(coupon.getSupportTransfer()); | |||||
| //检查卡是否下架,如果是,不可转赠 | |||||
| WxCouponChannel wxCouponChannel = wxCouponChannelMapper.selectById(order.getCouponChannelId(),order.getTenantId()); | |||||
| if (wxCouponChannel != null && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode())) { | |||||
| cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); | |||||
| } | |||||
| wxCardInfoMapper.insert(cardInfo); | |||||
| } | |||||
| Integer fee = 0; | |||||
| WxCardInfo cardInfo = new WxCardInfo(); | |||||
| cardInfo.setId(couponOrder.getId()); | |||||
| cardInfo.updateTenantInfo(order); | |||||
| cardInfo.setCouponId(order.getProductId()); | |||||
| cardInfo.setAmount(coupon.getPrice()); | |||||
| cardInfo.setSaleAmount(coupon.getSalePrice()); | |||||
| cardInfo.setRemainingAmount(coupon.getPrice()); | |||||
| if (!coupon.checkIsFree()) { | |||||
| //判断该transctionId是否已经存在,如果存在,则不添加 | |||||
| WxCardInfo cardInfoq = new WxCardInfo(); | |||||
| cardInfoq.setTransactionId(payOrder.getTransactionId()); | |||||
| List<WxCardInfo> cardInfoList = wxCardInfoMapper.findList(cardInfoq); | |||||
| if (null != cardInfoList && cardInfoList.size() > 0) { | |||||
| //do nothing | |||||
| }else { | |||||
| // 有价卡 | |||||
| cardInfo.setTransactionId(payOrder.getTransactionId()); | |||||
| if (payOrder.getShareAmount() != null) { | |||||
| // 开启分账 | |||||
| WxComposeChildOrderShare share = payOrder.getChildOrderShare(order.getId()); | |||||
| fee = share.getRealPayMent() - share.getShareAmount(); | |||||
| cardInfo.setShareFeeAmount(share.getShareAmount()); | |||||
| cardInfo.setRemainingShareFeeAmount(share.getShareAmount()); | |||||
| cardInfo.setRateAmount(share.getRateAmount()); | |||||
| } else { | |||||
| // 未开启分账 | |||||
| Integer orderRealPayMent = payOrder.getChildOrderShare(order.getId()).getRealPayMent(); | |||||
| fee = OrderHelper.getMallCharge(orderRealPayMent, payAccount); | |||||
| Integer shareAmount = orderRealPayMent - fee; | |||||
| cardInfo.setShareFeeAmount(shareAmount); | |||||
| cardInfo.setRemainingShareFeeAmount(shareAmount); | |||||
| cardInfo.setRateAmount(OrderHelper.getRateAmount(orderRealPayMent, fee, payAccount)); | |||||
| } | |||||
| } | |||||
| } else { | |||||
| // 免费卡 | |||||
| cardInfo.setShareFeeAmount(0); | |||||
| cardInfo.setRemainingShareFeeAmount(0); | |||||
| cardInfo.setRateAmount(0); | |||||
| if (coupon.getPasswordSupport().equals(EnumCouponPasswordSupport.SUPPORTED.getCode())) { | |||||
| WxCouponPassword updateCPwd = new WxCouponPassword(); | |||||
| updateCPwd.setId(couponPasswordId); | |||||
| updateCPwd.setCardId(cardInfo.getId()); | |||||
| updateCPwd.setStatus(EnumCouponPasswordStatus.USED.getCode()); | |||||
| couponPasswordMapper.updateById(updateCPwd); | |||||
| } | |||||
| } | |||||
| cardInfo.setServiceFeeAmount(fee); | |||||
| cardInfo.setCreateDate(curr); | |||||
| cardInfo.setUpdateDate(curr); | |||||
| cardInfo.setSupportTransfer(coupon.getSupportTransfer()); | |||||
| //检查卡是否下架,如果是,不可转赠 | |||||
| WxCouponChannel wxCouponChannel = wxCouponChannelMapper.selectById(order.getCouponChannelId(),order.getTenantId()); | |||||
| if (wxCouponChannel != null && wxCouponChannel.getStatus().equals(EnumCouponChannelStatus.STATUS_TAKE_OFFF.getCode())) { | |||||
| cardInfo.setSupportTransfer(EnumCouponTransfer.NO.getCode()); | |||||
| } | |||||
| wxCardInfoMapper.insert(cardInfo); | |||||
| } | |||||
| try{ | |||||
| sendMsgForCouponOrder(couponOrder,coupon); | |||||
| }catch(Exception e){ | |||||
| logger.info("卷到账提醒error"+e.getMessage()); | |||||
| } | |||||
| return couponOrder; | return couponOrder; | ||||
| } | } | ||||
| @@ -1563,9 +1563,231 @@ public class WxOrderServiceImpl implements WxOrderService { | |||||
| } | } | ||||
| wxCardInfoMapper.insert(cardInfo); | wxCardInfoMapper.insert(cardInfo); | ||||
| } | } | ||||
| try{ | |||||
| sendMsgForCouponOrder(couponOrder,coupon); | |||||
| }catch(Exception e){ | |||||
| logger.info("卷到账提醒error"+e.getMessage()); | |||||
| } | |||||
| return couponOrder; | return couponOrder; | ||||
| } | } | ||||
| //卷到账消息 | |||||
| private void sendMsgForCouponOrder(WxCouponOrder couponOrder, WxCoupon coupon) { | |||||
| if(EnumPayWay.PAY_WAY_NOT_UNPAY_GIFTLIST.getCode().equals(couponOrder.getPayVendor())){ | |||||
| logger.info("礼包子券 不发提醒"); | |||||
| return; | |||||
| } | |||||
| if(EnumCouponType.CARD_MULTIMCH.getCode().equals(coupon.getType()) | |||||
| || EnumCouponType.COUPON_GIFT.getCode().equals(coupon.getType()) | |||||
| || EnumCouponType.COUPON_DISTRIBUTION.getCode().equals(coupon.getType()) | |||||
| || EnumCouponType.COUPON_PREORDER.getCode().equals(coupon.getType()) | |||||
| ){ | |||||
| logger.info("购物卡,券礼包,可配送商品,预购商品 不发提醒"); | |||||
| return; | |||||
| } | |||||
| boolean isSendTt = false; | |||||
| boolean isSendWx = false; | |||||
| if(EnumPayWay.PAY_WAY_TT.getCode().equals(couponOrder.getPayVendor())){ | |||||
| isSendTt = true; | |||||
| }else if(EnumPayWay.PAY_WAY_WECHAT.getCode().equals(couponOrder.getPayVendor())){ | |||||
| isSendWx = true; | |||||
| }else{ | |||||
| isSendTt = true; | |||||
| isSendWx = true; | |||||
| } | |||||
| if(isSendTt){ | |||||
| TtCUser tcuQ = new TtCUser(); | |||||
| tcuQ.updateTenantInfo(coupon); | |||||
| tcuQ.setUserId(couponOrder.getCUserId()); | |||||
| List<TtCUser> list = ttCUserMapper.findList(tcuQ); | |||||
| if(list != null && list.size() > 0){ | |||||
| for (TtCUser cuser:list) { | |||||
| //发订阅消息 | |||||
| sendCouponRemind(couponOrder,coupon, cuser); | |||||
| } | |||||
| } | |||||
| } | |||||
| if(isSendWx){ | |||||
| WxCUser wcuQ = new WxCUser(); | |||||
| wcuQ.updateTenantInfo(coupon); | |||||
| wcuQ.setUserId(couponOrder.getCUserId()); | |||||
| List<WxCUser> list = wxCUserMapper.findList(wcuQ); | |||||
| if(list != null && list.size() > 0){ | |||||
| for (WxCUser cuser:list) { | |||||
| //发订阅消息 | |||||
| sendCouponRemind(couponOrder,coupon, cuser); | |||||
| // 发送微信模板消息(公众号模板消息/小程序统一消息/小程序模板消息) | |||||
| sendMpMsgForSendCoupon(couponOrder,coupon, cuser); | |||||
| } | |||||
| } | |||||
| } | |||||
| } | |||||
| private void sendCouponRemind(WxCouponOrder couponOrder,WxCoupon coupon,WxCUser cuser){ | |||||
| try { | |||||
| WxTemplateMsg temp = new WxTemplateMsg(); | |||||
| temp.updateTenantInfo(coupon); | |||||
| temp.setType(EnumTemplateType.SEND_COUPON_REMIND.getCode()); | |||||
| temp = wxTemplateMsgService.getByObj(temp); | |||||
| if(temp.getId() != null){ | |||||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||||
| WxMsg msg = new WxMsg(); | |||||
| msg.updateTenantInfo(coupon); | |||||
| msg.setPhones(cuser.getOpenId()); | |||||
| msg.setModelId(temp.getId()); | |||||
| Map<String,String> map = new HashMap<>(); | |||||
| map.put("thing1",coupon.getTitle()); | |||||
| map.put("time3",dateFormat.format(couponOrder.getCreateDate())); | |||||
| map.put("time4",dateFormat.format(couponOrder.getExpiredTime())); | |||||
| map.put("thing5","你的优惠券已到账!请立即使用"); | |||||
| if(EnumCouponType.COUPON_TINGCHE.getCode().equals(couponOrder.getCouponType()) | |||||
| || EnumCouponType.COUPON_CREDIT_PARK.getCode().equals(couponOrder.getCouponType())){ | |||||
| map.put("goToPage","pages/index/index?type=in"); | |||||
| }else{ | |||||
| map.put("goToPage","pages/index/index?type=mc"); | |||||
| } | |||||
| msg.setMsg(JSONObject.toJSONString(map)); | |||||
| wxMsgService.batchSendAppinfo(msg); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| // e.printStackTrace(); | |||||
| logger.error("发卷消息发送异常"); | |||||
| } | |||||
| } | |||||
| private void sendCouponRemind(WxCouponOrder couponOrder,WxCoupon coupon,TtCUser cuser){ | |||||
| try { | |||||
| WxTemplateMsg temp = new WxTemplateMsg(); | |||||
| temp.updateTenantInfo(coupon); | |||||
| temp.setType(EnumTemplateType.TT_SEND_COUPON_REMIND.getCode()); | |||||
| temp = wxTemplateMsgService.getByObj(temp); | |||||
| if(temp.getId() != null){ | |||||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||||
| WxMsg msg = new WxMsg(); | |||||
| msg.updateTenantInfo(coupon); | |||||
| msg.setPhones(cuser.getOpenId()); | |||||
| msg.setModelId(temp.getId()); | |||||
| Map<String,String> map = new HashMap<>(); | |||||
| map.put("优惠券名称",coupon.getTitle()); | |||||
| map.put("过期时间",dateFormat.format(couponOrder.getExpiredTime())); | |||||
| map.put("备注","你的优惠券已到账!请立即使用"); | |||||
| if(EnumCouponType.COUPON_TINGCHE.getCode().equals(couponOrder.getCouponType()) | |||||
| || EnumCouponType.COUPON_CREDIT_PARK.getCode().equals(couponOrder.getCouponType())){ | |||||
| map.put("goToPage","pages/index/index?type=in"); | |||||
| }else{ | |||||
| map.put("goToPage","pages/index/index?type=mc"); | |||||
| } | |||||
| msg.setMsg(JSONObject.toJSONString(map)); | |||||
| wxMsgService.batchSendTtAppinfo(msg); | |||||
| } | |||||
| } catch (Exception e) { | |||||
| // e.printStackTrace(); | |||||
| logger.error("发卷消息发送异常"); | |||||
| } | |||||
| } | |||||
| private boolean sendMpMsgForSendCoupon(WxCouponOrder couponOrder,WxCoupon coupon, WxCUser user) { | |||||
| // 发送 公众号 模板消息 | |||||
| SimpleDateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); | |||||
| String gotopage = Constant.mainPageUrl + "?type=mc"; | |||||
| // 7. 公众号消息 | |||||
| if (StringUtils.isNotBlank(user.getMpAppId()) && | |||||
| StringUtils.isNotBlank(user.getMpOpenId()) && | |||||
| user.getMpSubscribe().equals(EnumUserIsSubscribe.YES.getCode())) { | |||||
| // 检查是否超限 | |||||
| WxMsgLimit msgLimit = new WxMsgLimit(); | |||||
| msgLimit.updateTenantInfo(couponOrder); | |||||
| msgLimit.setType(EnumMsgLimitType.WXCHAT_OPENID_SEND.getCode()); | |||||
| msgLimit.setLimitId(user.getMpOpenId()); | |||||
| if (wxMsgLimitService.checkIsLimit(msgLimit)) { | |||||
| logger.error("用户公众号模板消息超限" + user.getId()); | |||||
| return true; | |||||
| } | |||||
| // 已关注公众号 | |||||
| /** | |||||
| * 购票成功通知 | |||||
| * {first.DATA}} | |||||
| * 订单号:{{keyword1.DATA}} | |||||
| * 兑换券:{{keyword2.DATA}} | |||||
| * 订单详情:{{keyword3.DATA}} | |||||
| * 有效期至:{{keyword4.DATA}} | |||||
| * 购买数量:{{keyword5.DATA}} | |||||
| * {{remark.DATA}} | |||||
| */ | |||||
| MpAppMsg mpAppMsg = new MpAppMsg(); | |||||
| mpAppMsg.setMsgType(EnumMsgRecordType.PUBLIC.getCode()); | |||||
| mpAppMsg.setAppId(user.getMpAppId()); | |||||
| mpAppMsg.setTo(user.getMpOpenId()); | |||||
| mpAppMsg.setMiniAppId(user.getAppId()); | |||||
| mpAppMsg.setMiniPagePath(gotopage); | |||||
| mpAppMsg.updateTenantInfo(couponOrder); | |||||
| mpAppMsg.setTemplateType(EnumTemplateType.GIFT_MESSAGE.getCode()); | |||||
| mpAppMsg.setDataList(Lists.newArrayList( | |||||
| user.getNickName(), | |||||
| String.valueOf(couponOrder.getOrderId()), | |||||
| couponOrder.getId().toString(), | |||||
| coupon.getTitle(), | |||||
| dateFormat.format(couponOrder.getExpiredTime()), | |||||
| "1", | |||||
| user.getNickName() | |||||
| )); | |||||
| try { | |||||
| mqBaseProducer.sendMessage(mpAppMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| } catch (Exception e) { | |||||
| logger.error("购票成功-公众号-模板消息发送失败: " + e.getMessage()); | |||||
| //throw new MallinkException(ErrorCode.MP_TEMPLATE_SEND_FAILED); | |||||
| } | |||||
| } else { | |||||
| // 可能未关注公众号, 用户可能收不到 | |||||
| // 8. 微信小程序-统一消息 | |||||
| // 检查是否超限 | |||||
| WxMsgLimit msgLimit = new WxMsgLimit(); | |||||
| msgLimit.updateTenantInfo(couponOrder); | |||||
| msgLimit.setType(EnumMsgLimitType.WEAPP_OPENID_SEND.getCode()); | |||||
| msgLimit.setLimitId(user.getOpenId()); | |||||
| if (wxMsgLimitService.checkIsLimit(msgLimit)) { | |||||
| logger.error("用户小程序统一模板消息超限:" + user.getId()); | |||||
| return true; | |||||
| } | |||||
| // 获取小程序关联的服务号 | |||||
| WxAuthorizerInfo authQ = new WxAuthorizerInfo(); | |||||
| authQ.setAuthorizerAppid(user.getAppId()); | |||||
| authQ.updateTenantInfo(couponOrder); | |||||
| WxAuthorizerInfo weappInfo = authorizerInfoMapper.findMp(authQ); | |||||
| if (weappInfo != null) { | |||||
| AppUniformMsg appUniformMsg = new AppUniformMsg(); | |||||
| appUniformMsg.setMsgType(EnumMsgRecordType.SMART_APP_UNIFORM.getCode()); | |||||
| appUniformMsg.setAppId(user.getAppId()); | |||||
| appUniformMsg.setTo(user.getOpenId()); | |||||
| appUniformMsg.setTemplateType(EnumTemplateType.GIFT_MESSAGE.getCode()); | |||||
| appUniformMsg.setPagePath(gotopage); | |||||
| appUniformMsg.setMpAppId(weappInfo.getAuthorizerAppid()); | |||||
| appUniformMsg.setDataList(Lists.newArrayList( | |||||
| user.getNickName(), | |||||
| String.valueOf(couponOrder.getOrderId()), | |||||
| couponOrder.getId().toString(), | |||||
| coupon.getTitle(), | |||||
| dateFormat.format(couponOrder.getExpiredTime()), | |||||
| "1", | |||||
| user.getNickName() | |||||
| )); | |||||
| try { | |||||
| mqBaseProducer.sendMessage(appUniformMsg, EnumMsgMqTopic.DEFAULT.getCode(), EnumMsgMqTag.DEFAULT.getCode(), EnumMsgMqKey.DEFAULT.getCode()); | |||||
| } catch (Exception e) { | |||||
| logger.error("核销-公众号-模板消息发送失败: " + e.getMessage()); | |||||
| //throw new MallinkException(ErrorCode.UNIFORM_SEND_FAILED); | |||||
| } | |||||
| } | |||||
| } | |||||
| return false; | |||||
| } | |||||
| @Override | @Override | ||||
| @Transactional(propagation = Propagation.NESTED, readOnly = false, rollbackFor = {Exception.class}) | @Transactional(propagation = Propagation.NESTED, readOnly = false, rollbackFor = {Exception.class}) | ||||
| public WxCouponOrder sendFreeCouponToUser(Long userId,TenantEntity tenantinfo, Long couponId, WxCouponSendVo wxCouponSendVo,EnumPayWay payWay,Long merchantId,Long bUserId) { | public WxCouponOrder sendFreeCouponToUser(Long userId,TenantEntity tenantinfo, Long couponId, WxCouponSendVo wxCouponSendVo,EnumPayWay payWay,Long merchantId,Long bUserId) { | ||||
| @@ -6,26 +6,27 @@ import cn.binarywang.wx.miniapp.constant.WxMaConstants; | |||||
| import com.alibaba.fastjson.JSON; | import com.alibaba.fastjson.JSON; | ||||
| import com.alibaba.fastjson.JSONArray; | import com.alibaba.fastjson.JSONArray; | ||||
| import com.alibaba.fastjson.JSONObject; | import com.alibaba.fastjson.JSONObject; | ||||
| import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper; | |||||
| import com.google.gson.JsonParser; | |||||
| import com.iformall.domain.po.WxAppinfo; | import com.iformall.domain.po.WxAppinfo; | ||||
| import com.iformall.domain.po.WxTemplateMsg; | import com.iformall.domain.po.WxTemplateMsg; | ||||
| import com.iformall.domain.po.base.TenantEntity; | import com.iformall.domain.po.base.TenantEntity; | ||||
| import com.iformall.domain.po.msg.BaseMsg; | import com.iformall.domain.po.msg.BaseMsg; | ||||
| import com.iformall.domain.po.msg.SmartAppMsg; | import com.iformall.domain.po.msg.SmartAppMsg; | ||||
| import com.iformall.douyin.miniapp.api.TtMaService; | |||||
| import com.iformall.douyin.miniapp.api.bean.TtMaSubscribeMessage; | |||||
| import com.iformall.enums.EnumTemplateType; | |||||
| import com.iformall.mapper.WxCUserMapper; | import com.iformall.mapper.WxCUserMapper; | ||||
| import com.iformall.mapper.WxTemplateMsgMapper; | import com.iformall.mapper.WxTemplateMsgMapper; | ||||
| import com.iformall.service.WxAppinfoService; | import com.iformall.service.WxAppinfoService; | ||||
| import com.iformall.service.msg.MsgSendService; | import com.iformall.service.msg.MsgSendService; | ||||
| import com.iformall.service.wechat.FmOpenService; | import com.iformall.service.wechat.FmOpenService; | ||||
| import com.iformall.utils.MaUtil; | import com.iformall.utils.MaUtil; | ||||
| import me.chanjar.weixin.common.error.WxErrorException; | |||||
| import org.slf4j.Logger; | import org.slf4j.Logger; | ||||
| import org.slf4j.LoggerFactory; | import org.slf4j.LoggerFactory; | ||||
| import org.springframework.beans.factory.annotation.Autowired; | import org.springframework.beans.factory.annotation.Autowired; | ||||
| import org.springframework.stereotype.Service; | import org.springframework.stereotype.Service; | ||||
| import java.util.ArrayList; | import java.util.ArrayList; | ||||
| import java.util.Arrays; | |||||
| import java.util.List; | import java.util.List; | ||||
| /** | /** | ||||
| @@ -60,23 +61,12 @@ public class SendSmartAppMsgServiceImpl implements MsgSendService { | |||||
| tenantEntity.setTenantId(smartAppMsg.getTenantId()); | tenantEntity.setTenantId(smartAppMsg.getTenantId()); | ||||
| tenantEntity.setParentTenantId(smartAppMsg.getParentTenantId()); | tenantEntity.setParentTenantId(smartAppMsg.getParentTenantId()); | ||||
| WxTemplateMsg msg = null; | |||||
| WxMaSubscribeMessage subscribeMessage; | |||||
| // WxMaTemplateMessage templateMessage; | |||||
| WxMaService wxMaService = null; | |||||
| if(isFmOpen) { | |||||
| wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(smartAppMsg.getAppId()); | |||||
| } else { | |||||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(smartAppMsg.getAppId()); | |||||
| wxMaService = maUtil.getWeappService(appInfo); | |||||
| } | |||||
| //查询信息模板 | //查询信息模板 | ||||
| WxTemplateMsg msgQ = new WxTemplateMsg(); | WxTemplateMsg msgQ = new WxTemplateMsg(); | ||||
| msgQ.updateTenantInfo(tenantEntity); | msgQ.updateTenantInfo(tenantEntity); | ||||
| msgQ.setType(smartAppMsg.getTemplateType()); | msgQ.setType(smartAppMsg.getTemplateType()); | ||||
| List<WxTemplateMsg> list = wxTemplateMsgMapper.findList(msgQ); | List<WxTemplateMsg> list = wxTemplateMsgMapper.findList(msgQ); | ||||
| WxTemplateMsg msg = null; | |||||
| if (list.size() > 0) { | if (list.size() > 0) { | ||||
| msg = list.get(0); | msg = list.get(0); | ||||
| } | } | ||||
| @@ -86,63 +76,75 @@ public class SendSmartAppMsgServiceImpl implements MsgSendService { | |||||
| return; | return; | ||||
| } | } | ||||
| if(0 == msg.getOnOff().intValue()){ | if(0 == msg.getOnOff().intValue()){ | ||||
| JSONObject customParam = JSON.parseObject(msg.getCustomParam()); | |||||
| // String url = customParam.getString("url"); | |||||
| // String emphasis = customParam.getString("emphasis"); | |||||
| // build template data list | |||||
| List<String> dataList = smartAppMsg.getDataList(); | |||||
| JSONArray indexArr = customParam.getJSONArray("index"); | |||||
| List<WxMaSubscribeMessage.Data> dataTempList = new ArrayList<>(); | |||||
| for(int i=0;i<indexArr.size();i++) { | |||||
| String key = indexArr.getString(i); | |||||
| String value = dataList.get(i); | |||||
| WxMaSubscribeMessage.Data templateData = new WxMaSubscribeMessage.Data(key, value); | |||||
| dataTempList.add(templateData); | |||||
| } | |||||
| // List<WxMaTemplateData> dataTempList = new ArrayList<>(); | |||||
| // for(int i=0;i<indexArr.size();i++) { | |||||
| // String key = indexArr.getString(i); | |||||
| // String value = customParam.getString(key); | |||||
| // value = value.replace("{"+key+"}", dataList.get(i)); | |||||
| // WxMaTemplateData templateData = new WxMaTemplateData(key, value); | |||||
| // dataTempList.add(templateData); | |||||
| // } | |||||
| // templateMessage = WxMaTemplateMessage.builder() | |||||
| // .toUser(smartAppMsg.getTo()) | |||||
| // .formId(smartAppMsg.getFormId()) // 微信支付的formId是prepayId | |||||
| // .page(smartAppMsg.getGotopage()) | |||||
| // .data(dataTempList) | |||||
| // .templateId(msg.getTemplateId()) | |||||
| // .emphasisKeyword(emphasis) | |||||
| // .build(); | |||||
| // wxMaService.getMsgService().sendTemplateMsg(templateMessage); | |||||
| String[] split = smartAppMsg.getTo().split(","); | |||||
| for (String to:split) { | |||||
| try { | |||||
| subscribeMessage = WxMaSubscribeMessage.builder() | |||||
| .templateId(msg.getTemplateId()) | |||||
| .toUser(to) | |||||
| .page(smartAppMsg.getGotopage()) | |||||
| .lang(WxMaConstants.MiniprogramLang.ZH_CN) | |||||
| .miniprogramState(WxMaConstants.MiniprogramState.FORMAL) | |||||
| .page(smartAppMsg.getGotopage()) | |||||
| .data(dataTempList) | |||||
| .build(); | |||||
| WxAppinfo appInfo = wxAppinfoService.getByAppId(smartAppMsg.getAppId()); | |||||
| if(EnumTemplateType.TT_SEND_COUPON_REMIND.getCode().equals(msg.getType())){ | |||||
| //发抖音 | |||||
| TtMaService ttappService = maUtil.getTtappService(appInfo); | |||||
| TtMaSubscribeMessage subscribeMessage; | |||||
| String[] split = smartAppMsg.getTo().split(","); | |||||
| for (String to:split) { | |||||
| try { | |||||
| subscribeMessage = TtMaSubscribeMessage.builder() | |||||
| .appId(appInfo.getAppId()) | |||||
| .tplId(msg.getTemplateId()) | |||||
| .openId(to) | |||||
| .page(smartAppMsg.getGotopage()) | |||||
| .data(new JsonParser().parse(smartAppMsg.getDataJson()).getAsJsonObject()) | |||||
| .build(); | |||||
| ttappService.getMsgService().sendSubscribeMsg(subscribeMessage); | |||||
| // wxCUserMapper.updateMsgCountDown(tenantEntity.getTenantId(),to); | |||||
| } catch (Exception e) { | |||||
| logger.error("openId:"+to+"-----发送订阅消息失败"); | |||||
| } | |||||
| } | |||||
| }else | |||||
| // if(EnumTemplateType.ACTIVITY_REMIND.getCode().equals(msg.getType()) | |||||
| // || EnumTemplateType.LIVE_REMIND.getCode().equals(msg.getType()) | |||||
| // || EnumTemplateType.CREDIT_UPD_REMIND.getCode().equals(msg.getType()) | |||||
| // || EnumTemplateType.SEND_COUPON_REMIND.getCode().equals(msg.getType())) | |||||
| { | |||||
| WxMaService wxMaService = null; | |||||
| if(isFmOpen) { | |||||
| wxMaService = openService.getWxOpenComponentService().getWxMaServiceByAppid(smartAppMsg.getAppId()); | |||||
| } else { | |||||
| wxMaService = maUtil.getWeappService(appInfo); | |||||
| } | |||||
| //发微信 | |||||
| JSONObject customParam = JSON.parseObject(msg.getCustomParam()); | |||||
| List<String> dataList = smartAppMsg.getDataList(); | |||||
| JSONArray indexArr = customParam.getJSONArray("index"); | |||||
| List<WxMaSubscribeMessage.Data> dataTempList = new ArrayList<>(); | |||||
| for(int i=0;i<indexArr.size();i++) { | |||||
| String key = indexArr.getString(i); | |||||
| String value = dataList.get(i); | |||||
| WxMaSubscribeMessage.Data templateData = new WxMaSubscribeMessage.Data(key, value); | |||||
| dataTempList.add(templateData); | |||||
| } | |||||
| wxMaService.getMsgService().sendSubscribeMsg(subscribeMessage); | |||||
| WxMaSubscribeMessage subscribeMessage; | |||||
| String[] split = smartAppMsg.getTo().split(","); | |||||
| for (String to:split) { | |||||
| try { | |||||
| subscribeMessage = WxMaSubscribeMessage.builder() | |||||
| .templateId(msg.getTemplateId()) | |||||
| .toUser(to) | |||||
| .page(smartAppMsg.getGotopage()) | |||||
| .lang(WxMaConstants.MiniprogramLang.ZH_CN) | |||||
| .miniprogramState(WxMaConstants.MiniprogramState.FORMAL) | |||||
| .data(dataTempList) | |||||
| .build(); | |||||
| wxMaService.getMsgService().sendSubscribeMsg(subscribeMessage); | |||||
| // wxCUserMapper.updateMsgCountDown(tenantEntity.getTenantId(),to); | // wxCUserMapper.updateMsgCountDown(tenantEntity.getTenantId(),to); | ||||
| } catch (Exception e) { | |||||
| logger.error("openId:"+to+"-----发送订阅消息失败"); | |||||
| } catch (Exception e) { | |||||
| logger.error("openId:"+to+"-----发送订阅消息失败"); | |||||
| } | |||||
| } | } | ||||
| } | } | ||||
| } | } | ||||
| } | } | ||||