From b5a09dfd7140dba2b411f8a95ea9520791945268 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E4=BD=86=E6=98=9F=E9=9C=96?= <729219176@qq.com> Date: Thu, 28 Sep 2023 09:55:21 +0800 Subject: [PATCH] =?UTF-8?q?=E5=BE=AE=E4=BF=A1=E6=B6=88=E6=81=AF=E9=80=9A?= =?UTF-8?q?=E7=9F=A5=E6=9B=B4=E6=96=B0=E3=80=82?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../web/controller/order/OrderController.java | 14 +++++++ ghy-common/pom.xml | 10 +++++ .../java/com/ghy/common/config/WxConfig.java | 40 +++++++++++++------ .../java/com/ghy/common/enums/WxMsgEnum.java | 4 +- pom.xml | 12 ++++++ 5 files changed, 67 insertions(+), 13 deletions(-) diff --git a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java index 63f5a73f..0bdb146a 100644 --- a/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java +++ b/ghy-admin/src/main/java/com/ghy/web/controller/order/OrderController.java @@ -4,6 +4,7 @@ import com.ghy.common.core.controller.BaseController; import com.ghy.common.core.domain.AjaxResult; import com.ghy.common.core.domain.entity.SysUser; import com.ghy.common.enums.*; +import com.ghy.common.utils.WechatMsgUtils; import com.ghy.customer.domain.Customer; import com.ghy.customer.domain.CustomerAddress; import com.ghy.customer.service.CustomerAddressService; @@ -257,6 +258,19 @@ public class OrderController extends BaseController { orderGoodsService.insertOrderGoods(orderGoods); }); + // 推送公众号通知数据。 + try{ + Worker assignWorker = workerService.selectById(orderMaster.getWorkerId()); + // 消息组装。 + Map params = new HashMap<>(); + params.put("character string1", orderMaster.getCode()); + params.put("thing2", customer.getName()); + params.put("data8", com.ghy.common.utils.DateUtils.parseDateToStr("yyyy年MM月dd日 HH:mm", new Date())); + params.put("thing4", "有新订单,请及时处理!"); + WechatMsgUtils.sendWeChatMsg(WechatMsgUtils.getToken(), assignWorker.getOpenId(), WxMsgEnum.TEXT, params); + }catch (Exception e){ + // 暂时不做任何操作。 + } return AjaxResult.success("下单成功"); } diff --git a/ghy-common/pom.xml b/ghy-common/pom.xml index a1029ff3..95af9b3e 100644 --- a/ghy-common/pom.xml +++ b/ghy-common/pom.xml @@ -145,6 +145,16 @@ httpclient + + + org.wso2.apache.httpcomponents + httpmime + + + org.wso2.apache.httpcomponents + httpclient + + \ No newline at end of file diff --git a/ghy-common/src/main/java/com/ghy/common/config/WxConfig.java b/ghy-common/src/main/java/com/ghy/common/config/WxConfig.java index 1728d065..d0b9d4f6 100644 --- a/ghy-common/src/main/java/com/ghy/common/config/WxConfig.java +++ b/ghy-common/src/main/java/com/ghy/common/config/WxConfig.java @@ -1,5 +1,6 @@ package com.ghy.common.config; +import lombok.Data; import org.springframework.boot.context.properties.ConfigurationProperties; import org.springframework.stereotype.Component; @@ -7,27 +8,42 @@ import org.springframework.stereotype.Component; * 七牛云配置 * @author clunt */ +@Data @Component @ConfigurationProperties(prefix = "wx") public class WxConfig { + /** + * appId + */ public String appId; + /** + * secret + */ public String secret; - public String getAppId() { - return appId; - } + /** + * 授权形式 + * get Token grant_type + */ + private String grantTypeInToken = "client_credential"; - public void setAppId(String appId) { - this.appId = appId; - } + /** + * 获取用户Token url + * get Token url + */ + private String gerTokenUrl = "https://api.weixin.qq.com/cgi-bin/token?grant_type="; - public String getSecret() { - return secret; - } + /** + * 发送消息api + */ + private String sendMsgUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token="; - public void setSecret(String secret) { - this.secret = secret; - } + + /** + * 模版相关 + * 测试模版 + */ + private String textTemplateId = null; } 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 index 5c434a31..b26bf25e 100644 --- a/ghy-common/src/main/java/com/ghy/common/enums/WxMsgEnum.java +++ b/ghy-common/src/main/java/com/ghy/common/enums/WxMsgEnum.java @@ -12,7 +12,9 @@ public enum WxMsgEnum { /** 新订单通知 */ NEW_ORDER("","gFoPAYF4J6Y_O5OzzNUbvMxTrsAS7aUWffdNH42xhzM"), /** 商城端消息通知 */ - CUSTOMER_ORDER("", "JtsGFPDjYhL2GbHfKxvTJaR_lLp8xLyw8VeR01Y0JHM") + CUSTOMER_ORDER("", "JtsGFPDjYhL2GbHfKxvTJaR_lLp8xLyw8VeR01Y0JHM"), + /** 测试 **/ + TEXT("", "JtsGFPDjYhL2GbHfKxvTJaR_lLp8xLyw8VeR01Y0JHM"), ; /** 超时消息通知 */ // OVER_TIME("","8I5BnJMfwj-Z7udhNm9Z-kdjdg4__MV5ug1x8KKsbc0"), diff --git a/pom.xml b/pom.xml index 2698500c..c66fdf59 100644 --- a/pom.xml +++ b/pom.xml @@ -332,6 +332,18 @@ ${wxpay.version} + + + org.wso2.apache.httpcomponents + httpmime + 4.3.1.wso2v1 + + + org.wso2.apache.httpcomponents + httpclient + 4.3.1.wso2v1 + +