微信消息通知更新。
This commit is contained in:
parent
f3c0419987
commit
ee243b5d61
|
|
@ -0,0 +1,44 @@
|
|||
package com.ghy.web.controller;
|
||||
|
||||
|
||||
import com.ghy.common.dto.DataEntityDTO;
|
||||
import com.ghy.common.enums.WxMsgEnum;
|
||||
import com.ghy.common.utils.WechatMsgUtils;
|
||||
import org.springframework.web.bind.annotation.*;
|
||||
|
||||
import java.util.Date;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* @Author 但星霖
|
||||
* @Date 2023-09-28 10:42:56
|
||||
* 说明:
|
||||
*/
|
||||
@RestController
|
||||
@RequestMapping("/mesg/test")
|
||||
public class MesgTestController {
|
||||
|
||||
@GetMapping("/{openId}")
|
||||
public void edit(@PathVariable("openId") String openId){
|
||||
try {
|
||||
// 消息组装。
|
||||
Map<String, Object> paramsNew = new HashMap<>();
|
||||
// 订单编号
|
||||
paramsNew.put("character_string1", new DataEntityDTO("12312"));
|
||||
// 名称
|
||||
paramsNew.put("thing2", new DataEntityDTO("订单被拒通知"));
|
||||
// 预约时间
|
||||
paramsNew.put("data8", new DataEntityDTO(com.ghy.common.utils.DateUtils.parseDateToStr("yyyy年MM月dd日 HH:mm", new Date())));
|
||||
// 师傅姓名
|
||||
paramsNew.put("name3", new DataEntityDTO("测试"));
|
||||
// 服务区域
|
||||
paramsNew.put("thing4", new DataEntityDTO("成都市"));
|
||||
// 消息推送
|
||||
WechatMsgUtils.sendWeChatMsg(WechatMsgUtils.getToken(), openId, WxMsgEnum.TEXT, paramsNew);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -268,13 +268,21 @@ public class OrderController extends BaseController {
|
|||
Worker assignWorker = workerService.selectById(orderMaster.getWorkerId());
|
||||
// 消息组装。
|
||||
Map<String, Object> params = new HashMap<>();
|
||||
params.put("character string1", orderMaster.getCode());
|
||||
// 订单编号
|
||||
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", "有新订单,请及时处理!");
|
||||
// 预约时间
|
||||
params.put("data8", com.ghy.common.utils.DateUtils.parseDateToStr("yyyy年MM月dd日 HH:mm", orderMaster.getExpectTimeStart()));
|
||||
// 师傅姓名
|
||||
params.put("name3", assignWorker.getName());
|
||||
// 服务区域
|
||||
params.put("thing4", orderMaster.getAddress());
|
||||
// 消息推送
|
||||
WechatMsgUtils.sendWeChatMsg(WechatMsgUtils.getToken(), assignWorker.getOpenId(), WxMsgEnum.TEXT, params);
|
||||
} catch (Exception e) {
|
||||
// 暂时不做任何操作。
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
return AjaxResult.success("下单成功");
|
||||
}
|
||||
|
|
@ -433,6 +441,21 @@ public class OrderController extends BaseController {
|
|||
params.put("thing1", "新订单通知");
|
||||
params.put("thing5", "收到师傅派单,请及时处理!");
|
||||
wxMsgService.sendWxMsg(acceptWorker.getOpenId(), WxMsgEnum.ORDER_PLAN, params);
|
||||
|
||||
// 推送公众号通知数据。
|
||||
// 消息组装。
|
||||
Map<String, Object> paramsNew = new HashMap<>();
|
||||
// 订单编号
|
||||
paramsNew.put("character_string1", om.getCode());
|
||||
// 名称
|
||||
paramsNew.put("thing2", om.getGoodsName());
|
||||
// 预约时间
|
||||
paramsNew.put("data8", com.ghy.common.utils.DateUtils.parseDateToStr("yyyy年MM月dd日 HH:mm", om.getCreateTime()));
|
||||
// 服务区域
|
||||
paramsNew.put("thing4", om.getAddress());
|
||||
// 师傅姓名
|
||||
paramsNew.put("name3", acceptWorker.getName());
|
||||
WechatMsgUtils.sendWeChatMsg(WechatMsgUtils.getToken(), acceptWorker.getOpenId(), WxMsgEnum.TEXT, paramsNew);
|
||||
} catch (Exception e) {
|
||||
logger.error(e.getMessage(), e);
|
||||
}
|
||||
|
|
@ -525,6 +548,22 @@ public class OrderController extends BaseController {
|
|||
params.put("time1", com.ghy.common.utils.DateUtils.parseDateToStr("yyyy年MM月dd日 HH:mm", new Date()));
|
||||
params.put("thing5", "有新订单,请及时处理!");
|
||||
wxMsgService.sendWxMsg(worker.getOpenId(), WxMsgEnum.NEW_ORDER, params);
|
||||
|
||||
Worker assignWorker = workerService.selectById(orderMaster.getWorkerId());
|
||||
// 消息组装。
|
||||
Map<String, Object> paramsNew = new HashMap<>();
|
||||
// 订单编号
|
||||
paramsNew.put("character_string1", orderMaster.getCode());
|
||||
// 名称
|
||||
paramsNew.put("thing2", customer.getName());
|
||||
// 预约时间
|
||||
paramsNew.put("data8", com.ghy.common.utils.DateUtils.parseDateToStr("yyyy年MM月dd日 HH:mm", orderMaster.getExpectTimeStart()));
|
||||
// 师傅姓名
|
||||
paramsNew.put("name3", assignWorker.getName());
|
||||
// 服务区域
|
||||
paramsNew.put("thing4", orderMaster.getAddress());
|
||||
// 消息推送
|
||||
WechatMsgUtils.sendWeChatMsg(WechatMsgUtils.getToken(), assignWorker.getOpenId(), WxMsgEnum.TEXT, paramsNew);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -6,10 +6,7 @@ import com.ghy.common.core.controller.BaseController;
|
|||
import com.ghy.common.core.domain.AjaxResult;
|
||||
import com.ghy.common.core.page.TableDataInfo;
|
||||
import com.ghy.common.enums.*;
|
||||
import com.ghy.common.utils.AdapayUtils;
|
||||
import com.ghy.common.utils.ExceptionUtil;
|
||||
import com.ghy.common.utils.MoneyUtil;
|
||||
import com.ghy.common.utils.StringUtils;
|
||||
import com.ghy.common.utils.*;
|
||||
import com.ghy.common.utils.poi.ExcelUtil;
|
||||
import com.ghy.customer.domain.Customer;
|
||||
import com.ghy.customer.domain.CustomerAddress;
|
||||
|
|
@ -1038,6 +1035,22 @@ public class OrderDetailController extends BaseController {
|
|||
params.put("thing1", "订单被拒通知");
|
||||
params.put("thing5", "订单被拒绝,请及时处理!");
|
||||
wxMsgService.sendWxMsg(masterWorker.getOpenId(), WxMsgEnum.ORDER_PLAN, params);
|
||||
|
||||
Worker assignWorker = workerService.selectById(om.getWorkerId());
|
||||
// 消息组装。
|
||||
Map<String, Object> paramsNew = new HashMap<>();
|
||||
// 订单编号
|
||||
paramsNew.put("character_string1", om.getCode());
|
||||
// 名称
|
||||
paramsNew.put("thing2", "订单被拒通知");
|
||||
// 预约时间
|
||||
paramsNew.put("data8", com.ghy.common.utils.DateUtils.parseDateToStr("yyyy年MM月dd日 HH:mm", om.getExpectTimeStart()));
|
||||
// 师傅姓名
|
||||
paramsNew.put("name3", assignWorker.getName());
|
||||
// 服务区域
|
||||
paramsNew.put("thing4", om.getAddress());
|
||||
// 消息推送
|
||||
WechatMsgUtils.sendWeChatMsg(WechatMsgUtils.getToken(), assignWorker.getOpenId(), WxMsgEnum.TEXT, paramsNew);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -45,5 +45,5 @@ public class WxConfig {
|
|||
* 模版相关
|
||||
* 测试模版
|
||||
*/
|
||||
private String textTemplateId = null;
|
||||
private String textTemplateId = "lPqo3fXelyh47pFqv9n5RY9acCd0D8po8-xsgfCj8hY";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -0,0 +1,32 @@
|
|||
package com.ghy.common.dto;
|
||||
|
||||
import lombok.Data;
|
||||
|
||||
/**
|
||||
* @Author 但星霖
|
||||
* @Date 2023-09-28 21:45:16
|
||||
* 说明:微信内容消息dto
|
||||
*/
|
||||
@Data
|
||||
public class DataEntityDTO {
|
||||
|
||||
/**
|
||||
* 内容
|
||||
*/
|
||||
private String value;
|
||||
|
||||
/**
|
||||
* 字体颜色
|
||||
*/
|
||||
private String color;
|
||||
|
||||
public DataEntityDTO(String value){
|
||||
this.value = value;
|
||||
this.color = "#173177";
|
||||
}
|
||||
|
||||
public DataEntityDTO(String value, String color){
|
||||
this.value = value;
|
||||
this.color = color;
|
||||
}
|
||||
}
|
||||
|
|
@ -28,6 +28,9 @@ public class WechatMsgUtils {
|
|||
@Autowired
|
||||
private static WxConfig wxConfig;
|
||||
|
||||
static final String appid = "wx105ce607b514ff2a";
|
||||
static final String appsecret = "51df6f2d33bf639fa05891af7a69a56e";
|
||||
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
|
|
@ -36,7 +39,7 @@ public class WechatMsgUtils {
|
|||
*/
|
||||
public static String getToken() {
|
||||
// 接口地址拼接参数
|
||||
String getTokenApi = wxConfig.getGerTokenUrl() + wxConfig.getGrantTypeInToken() + "&appid=" + "wx404f2439a8c24e15" + "&secret=" + "49ade04a817067fe2d65ab2f17afce75";
|
||||
String getTokenApi = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=" + appid + "&secret=" + appsecret;
|
||||
String tokenJsonStr = doGetPost(getTokenApi, "GET", null);
|
||||
JSONObject tokenJson = JSONObject.parseObject(tokenJsonStr);
|
||||
String token = tokenJson.get("access_token").toString();
|
||||
|
|
@ -54,25 +57,21 @@ public class WechatMsgUtils {
|
|||
*/
|
||||
public static void sendWeChatMsg(String token, String userOpenId, WxMsgEnum mesType, Map<String, Object> dataMap) {
|
||||
// 接口地址
|
||||
String sendMsgApi = wxConfig.getSendMsgUrl() + token;
|
||||
String sendMsgApi = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;
|
||||
//整体参数map
|
||||
Map<String, Object> paramMap = new HashMap<String, Object>();
|
||||
//根据自己的模板定义内容和颜色
|
||||
// dataMap.put("first", new DataEntity("详细内容XXXXXXX", "#173177"));
|
||||
// dataMap.put("keyword1", new DataEntity("私有化部署XXX", "#173177"));
|
||||
// dataMap.put("keyword2", new DataEntity("2020-08-18XXX", "#173177"));
|
||||
// dataMap.put("remark", new DataEntity("申请成功XXX", "#173177"));
|
||||
paramMap.put("touser", userOpenId);
|
||||
switch (mesType) {
|
||||
case TEXT:
|
||||
paramMap.put("template_id", wxConfig.getTextTemplateId());
|
||||
paramMap.put("template_id", "qfBBrpSq9-JFZFyPo0YRLp3SQTLkIYRFH7A65k6kSVM");
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
paramMap.put("data", dataMap);
|
||||
String reposont = doGetPost(sendMsgApi, "POST", paramMap);
|
||||
log.info("用户:{}消息:{}推送成功。{}", userOpenId, dataMap.toString(), System.currentTimeMillis());
|
||||
log.info("reposont:{}", reposont);
|
||||
log.info("用户:{}消息:{}推送返回谁:{}", userOpenId, dataMap.toString(),reposont);
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
|||
Loading…
Reference in New Issue