From 60cb94d9dc1f08b85b0400b8bdf1043b7b6122bc Mon Sep 17 00:00:00 2001 From: "kuang.yife" Date: Sun, 26 Mar 2023 23:23:57 +0800 Subject: [PATCH] =?UTF-8?q?=E9=93=B6=E8=A1=8C=E5=8D=A1=E7=BB=91=E5=AE=9A?= =?UTF-8?q?=E4=B8=8D=E4=B8=8A=EF=BC=8C=E6=B6=88=E6=81=AF=E7=BB=9F=E4=B8=80?= =?UTF-8?q?=E9=80=9A=E7=9F=A5?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../customer/CustomerBankController.java | 4 ++ .../java/com/ghy/common/enums/WxMsgEnum.java | 51 +++++++++++++++++++ .../system/service/IMessageNoticeService.java | 14 +++++ .../com/ghy/system/service/IWxMsgService.java | 12 +++++ .../impl/IMessageNoticeServiceImpl.java | 21 ++++++++ .../system/service/impl/WxMsgServiceImpl.java | 39 ++++++++++++++ 6 files changed, 141 insertions(+) create mode 100644 ghy-common/src/main/java/com/ghy/common/enums/WxMsgEnum.java create mode 100644 ghy-system/src/main/java/com/ghy/system/service/IMessageNoticeService.java create mode 100644 ghy-system/src/main/java/com/ghy/system/service/impl/IMessageNoticeServiceImpl.java diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java index d0daea00..909d8023 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/customer/CustomerBankController.java @@ -51,6 +51,9 @@ public class CustomerBankController { if(adapayService == null){ adapayService = SpringUtils.getBean(AdapayService.class); } + if(customerBankService == null){ + customerBankService = SpringUtils.getBean(CustomerBankService.class); + } // 需要先检查一次memberId是否已存在,如果已存在则只需要绑卡即可 Map member = adapayService.queryMember(merchant.getDeptId(), memberId); if (AdapayStatusEnum.succeeded.code.equals(member.get("status")) && memberId.equals(member.get("member_id"))) { @@ -88,6 +91,7 @@ public class CustomerBankController { customerBank.setSettleAccount(1); customerBankService.insertCustomerBank(customerBank); + } return AjaxResult.success(); } diff --git a/ghy-common/src/main/java/com/ghy/common/enums/WxMsgEnum.java b/ghy-common/src/main/java/com/ghy/common/enums/WxMsgEnum.java new file mode 100644 index 00000000..c91807af --- /dev/null +++ b/ghy-common/src/main/java/com/ghy/common/enums/WxMsgEnum.java @@ -0,0 +1,51 @@ +package com.ghy.common.enums; + +/** + * 微信消息通知枚举 + * @author clunt + */ + +public enum WxMsgEnum { + + /** 任务大厅订单通知 */ + PUBLIC_ORDER("", ""), + /** 新订单通知 */ + NEW_ORDER("",""), + /** 超时消息通知 */ + OVER_TIME("","8I5BnJMfwj-Z7udhNm9Z-kdjdg4__MV5ug1x8KKsbc0"), + /** 今日单消息通知 */ + TODAY_ORDER("", ""), + /** 明日单通知 */ + TOMORROW_ORDER("", ""), + /** 不同意排单通知 */ + NOT_AGREE_PLAIN("", ""), + /** 不同意完单通知 */ + NOT_AGREE_FINISH("",""), + /** 子师傅拒绝接单/退单通知 */ + DETAIL_REJECT("", "") + ; + + private String type; + private String tempCode; + + WxMsgEnum(String type, String tempCode) { + this.type = type; + this.tempCode = tempCode; + } + + public String getType() { + return type; + } + + public void setType(String type) { + this.type = type; + } + + public String getTempCode() { + return tempCode; + } + + public void setTempCode(String tempCode) { + this.tempCode = tempCode; + } +} diff --git a/ghy-system/src/main/java/com/ghy/system/service/IMessageNoticeService.java b/ghy-system/src/main/java/com/ghy/system/service/IMessageNoticeService.java new file mode 100644 index 00000000..e381f178 --- /dev/null +++ b/ghy-system/src/main/java/com/ghy/system/service/IMessageNoticeService.java @@ -0,0 +1,14 @@ +package com.ghy.system.service; + +/** + * 消息通知 + * @author clunt + */ +public interface IMessageNoticeService { + + /** + * 今日单/明日单通知 + */ + public void noticeTodayOrder(); + +} diff --git a/ghy-system/src/main/java/com/ghy/system/service/IWxMsgService.java b/ghy-system/src/main/java/com/ghy/system/service/IWxMsgService.java index d07c01a0..133735cb 100644 --- a/ghy-system/src/main/java/com/ghy/system/service/IWxMsgService.java +++ b/ghy-system/src/main/java/com/ghy/system/service/IWxMsgService.java @@ -1,6 +1,9 @@ package com.ghy.system.service; import com.ghy.common.enums.OrderStatus; +import com.ghy.common.enums.WxMsgEnum; + +import java.util.Map; /** * @author 但星霖 @@ -21,4 +24,13 @@ public interface IWxMsgService { * @return 是否推送成功 */ Boolean sendMsg(String openId, String remind, String orderId, String name, OrderStatus orderStatus, Long time); + + /** + * 推送微信消息 + * @param openId 微信唯一识别 + * @param wxMsgEnum 消息类型 * 用户查找模版id + * @param params 模版内容 + */ + void sendWxMsg(String openId, WxMsgEnum wxMsgEnum, Map params); + } diff --git a/ghy-system/src/main/java/com/ghy/system/service/impl/IMessageNoticeServiceImpl.java b/ghy-system/src/main/java/com/ghy/system/service/impl/IMessageNoticeServiceImpl.java new file mode 100644 index 00000000..890c37c6 --- /dev/null +++ b/ghy-system/src/main/java/com/ghy/system/service/impl/IMessageNoticeServiceImpl.java @@ -0,0 +1,21 @@ +package com.ghy.system.service.impl; + +import com.ghy.system.service.IMessageNoticeService; +import com.ghy.system.service.IWxMsgService; +import lombok.extern.slf4j.Slf4j; +import org.springframework.beans.factory.annotation.Autowired; +import org.springframework.stereotype.Service; + + +@Slf4j +@Service +public class IMessageNoticeServiceImpl implements IMessageNoticeService { + + @Autowired + private IWxMsgService wxMsgService; + + @Override + public void noticeTodayOrder() { + + } +} diff --git a/ghy-system/src/main/java/com/ghy/system/service/impl/WxMsgServiceImpl.java b/ghy-system/src/main/java/com/ghy/system/service/impl/WxMsgServiceImpl.java index 57efe383..4f6c5f47 100644 --- a/ghy-system/src/main/java/com/ghy/system/service/impl/WxMsgServiceImpl.java +++ b/ghy-system/src/main/java/com/ghy/system/service/impl/WxMsgServiceImpl.java @@ -3,6 +3,7 @@ package com.ghy.system.service.impl; import com.alibaba.fastjson.JSON; import com.alibaba.fastjson.JSONObject; import com.ghy.common.enums.OrderStatus; +import com.ghy.common.enums.WxMsgEnum; import com.ghy.common.utils.DateUtils; import com.ghy.system.config.WxMsgConfig; import com.ghy.system.service.IWxMsgService; @@ -57,6 +58,21 @@ public class WxMsgServiceImpl implements IWxMsgService { return false; } + @Override + public void sendWxMsg(String openId, WxMsgEnum wxMsgEnum, Map params) { + WxMsgConfig wxMsgConfig = buildMsgDto(openId, wxMsgEnum, params); + String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + getAccessToken(); + log.info("微信消息通知请求 url: {} , 参数: {}",url, wxMsgConfig); + JSONObject responseData = postData(url, wxMsgConfig); + log.info("微信消息通知请求参数:{}", JSON.toJSONString(responseData)); + Integer errorCode = responseData.getInteger("errcode"); + String errorMessage = responseData.getString("errmsg"); + if (errorCode == 0) { + log.info("用户:" + "openId" + "消息推送成功"); + } else { + log.error("微信消息通知失败,errcode:{},errorMessage:{}", errorCode, errorMessage); + } + } /** * 获取acctoken @@ -122,6 +138,29 @@ public class WxMsgServiceImpl implements IWxMsgService { } + + private WxMsgConfig buildMsgDto(String openId, WxMsgEnum wxMsgEnum, Map params) { + // 基础数据添加。 + JSONObject jsonObject = new JSONObject(); + for (Map.Entry objectEntry : params.entrySet()) { + JSONObject model = new JSONObject(); + model.put("value", objectEntry.getValue()); + jsonObject.put(objectEntry.getKey(), jsonObject); + } + /** + * 消息推送配置参数拼接 + */ + WxMsgConfig wxMsgConfig = new WxMsgConfig(); + // openId + wxMsgConfig.setTouser(openId); + // 模板id + wxMsgConfig.setTemplate_id(wxMsgEnum.getTempCode()); + // 数据data + wxMsgConfig.setData(jsonObject); + return wxMsgConfig; + + } + /** * 发送请求 *