Merge branch 'master' of gitee.com:beijing_hongye_huicheng/lilishop

This commit is contained in:
Chopper711 2023-05-06 16:32:48 +08:00
commit fac10debd5
4 changed files with 93 additions and 84 deletions

View File

@ -39,7 +39,6 @@ public class WechatMessageExecute implements OrderStatusChangeEvent, TradeEvent
public void orderChange(OrderMessage orderMessage) { public void orderChange(OrderMessage orderMessage) {
switch (orderMessage.getNewStatus()) { switch (orderMessage.getNewStatus()) {
case PAID:
case UNDELIVERED: case UNDELIVERED:
case DELIVERED: case DELIVERED:
case STAY_PICKED_UP: case STAY_PICKED_UP:

View File

@ -217,7 +217,7 @@ public class ConnectServiceImpl extends ServiceImpl<ConnectMapper, Connect> impl
connectQueryDTO.getUnionType()) connectQueryDTO.getUnionType())
.eq(CharSequenceUtil.isNotEmpty(connectQueryDTO.getUnionId()), Connect::getUnionId, .eq(CharSequenceUtil.isNotEmpty(connectQueryDTO.getUnionId()), Connect::getUnionId,
connectQueryDTO.getUnionId()); connectQueryDTO.getUnionId());
return this.getOne(queryWrapper); return this.getOne(queryWrapper,false);
} }
@Override @Override

View File

@ -200,8 +200,9 @@ public class KdniaoPlugin implements LogisticsPlugin {
JSONObject obj = JSONObject.parseObject(result); JSONObject obj = JSONObject.parseObject(result);
log.info("电子面单响应:{}", result); log.info("电子面单响应:{}", result);
if (!"100".equals(obj.getString("ResultCode"))) { if (!"100".equals(obj.getString("ResultCode"))) {
resultMap.put("Reason",obj.getString("Reason")); // resultMap.put("Reason",obj.getString("Reason"));
return resultMap; throw new ServiceException(obj.getString("Reason"));
// return resultMap;
} }
JSONObject orderJson = JSONObject.parseObject(obj.getString("Order")); JSONObject orderJson = JSONObject.parseObject(obj.getString("Order"));

View File

@ -9,7 +9,6 @@ import cn.lili.common.exception.ServiceException;
import cn.lili.common.utils.DateUtil; import cn.lili.common.utils.DateUtil;
import cn.lili.common.utils.StringUtils; import cn.lili.common.utils.StringUtils;
import cn.lili.modules.connect.entity.Connect; import cn.lili.modules.connect.entity.Connect;
import cn.lili.modules.connect.entity.enums.ConnectEnum;
import cn.lili.modules.connect.entity.enums.SourceEnum; import cn.lili.modules.connect.entity.enums.SourceEnum;
import cn.lili.modules.connect.service.ConnectService; import cn.lili.modules.connect.service.ConnectService;
import cn.lili.modules.member.entity.dto.ConnectQueryDTO; import cn.lili.modules.member.entity.dto.ConnectQueryDTO;
@ -79,47 +78,54 @@ public class WechatMessageUtil {
if (order == null) { if (order == null) {
throw new ServiceException("订单" + sn + "不存在,发送微信公众号消息错误"); throw new ServiceException("订单" + sn + "不存在,发送微信公众号消息错误");
} }
//获取微信消息 if (ClientTypeEnum.H5.name().equals(order.getClientType())) {
LambdaQueryWrapper<WechatMessage> wechatMessageQueryWrapper = new LambdaQueryWrapper(); //获取微信消息
wechatMessageQueryWrapper.eq(WechatMessage::getOrderStatus, order.getOrderStatus()); LambdaQueryWrapper<WechatMessage> wechatMessageQueryWrapper = new LambdaQueryWrapper();
WechatMessage wechatMessage = wechatMessageService.getOne(wechatMessageQueryWrapper); wechatMessageQueryWrapper.eq(WechatMessage::getOrderStatus, order.getOrderStatus());
if (wechatMessage == null) { WechatMessage wechatMessage = wechatMessageService.getOne(wechatMessageQueryWrapper);
return;
}
Connect connect = connectService.queryConnect( if (wechatMessage == null) {
ConnectQueryDTO.builder().userId(order.getMemberId()).unionType(ConnectEnum.WECHAT.name()).build() log.error("未配置微信公众号消息");
); return;
if (connect == null) { }
return;
}
log.info("微信消息发送消息:{}", order.getMemberId() + "-" + sn); Connect connect = connectService.queryConnect(
//获取token ConnectQueryDTO.builder()
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.H5); .userId(order.getMemberId())
.unionType(SourceEnum.WECHAT_OFFIACCOUNT_OPEN_ID.name())
.build()
);
if (connect == null) {
return;
}
//发送url log.info("微信消息发送消息:{}", order.getMemberId() + "-" + sn);
String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token; //获取token
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.H5);
Map<String, Object> map = new HashMap<>(4); //发送url
//用户id String url = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" + token;
map.put("touser", connect.getUnionId());
//模版id
map.put("template_id", wechatMessage.getCode());
//模版中所需数据
map.put("data", createData(order, wechatMessage));
log.info("参数内容:" + JSONUtil.toJsonStr(map)); Map<String, Object> map = new HashMap<>(4);
String content = HttpUtil.post(url, JSONUtil.toJsonStr(map)); //用户id
JSONObject json = new JSONObject(content); map.put("touser", connect.getUnionId());
log.info("微信消息发送结果:" + content); //模版id
String errorMessage = json.getStr("errmsg"); map.put("template_id", wechatMessage.getCode());
String errcode = json.getStr("errcode"); //模版中所需数据
//发送失败 map.put("data", createData(order, wechatMessage));
if (!"0".equals(errcode)) {
log.error("消息发送失败:" + errorMessage); log.info("参数内容:" + JSONUtil.toJsonStr(map));
log.error("消息发送请求token" + token); String content = HttpUtil.post(url, JSONUtil.toJsonStr(map));
log.error("消息发送请求:" + map.get("data")); JSONObject json = new JSONObject(content);
log.info("微信消息发送结果:" + content);
String errorMessage = json.getStr("errmsg");
String errcode = json.getStr("errcode");
//发送失败
if (!"0".equals(errcode)) {
log.error("消息发送失败:" + errorMessage);
log.error("消息发送请求token" + token);
log.error("消息发送请求:" + map.get("data"));
}
} }
} }
@ -135,53 +141,56 @@ public class WechatMessageUtil {
if (order == null) { if (order == null) {
throw new ServiceException("订单" + sn + "不存在,发送订阅消息错误"); throw new ServiceException("订单" + sn + "不存在,发送订阅消息错误");
} }
//获取微信消息 if (ClientTypeEnum.WECHAT_MP.name().equals(order.getClientType())) {
LambdaQueryWrapper<WechatMPMessage> wechatMPMessageQueryWrapper = new LambdaQueryWrapper();
wechatMPMessageQueryWrapper.eq(WechatMPMessage::getOrderStatus, order.getOrderStatus());
WechatMPMessage wechatMPMessage = wechatMPMessageService.getOne(wechatMPMessageQueryWrapper);
if (wechatMPMessage == null) {
log.info("未配置微信消息订阅");
return;
}
Connect connect = connectService.queryConnect( //获取微信消息
ConnectQueryDTO.builder().userId(order.getMemberId()).unionType(SourceEnum.WECHAT_MP_OPEN_ID.name()).build() LambdaQueryWrapper<WechatMPMessage> wechatMPMessageQueryWrapper = new LambdaQueryWrapper();
); wechatMPMessageQueryWrapper.eq(WechatMPMessage::getOrderStatus, order.getOrderStatus());
if (connect == null) { WechatMPMessage wechatMPMessage = wechatMPMessageService.getOne(wechatMPMessageQueryWrapper);
return; if (wechatMPMessage == null) {
} log.info("未配置微信消息订阅");
return;
}
log.info("微信消息订阅消息发送:{}", order.getMemberId() + "-" + sn); Connect connect = connectService.queryConnect(
//获取token ConnectQueryDTO.builder().userId(order.getMemberId()).unionType(SourceEnum.WECHAT_MP_OPEN_ID.name()).build()
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP); );
if (connect == null) {
return;
}
//发送url log.info("微信消息订阅消息发送:{}", order.getMemberId() + "-" + sn);
String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + token; //获取token
String token = wechatAccessTokenUtil.cgiAccessToken(ClientTypeEnum.WECHAT_MP);
Map<String, Object> map = new HashMap<>(4); //发送url
//用户id String url = "https://api.weixin.qq.com/cgi-bin/message/subscribe/send?access_token=" + token;
map.put("touser", connect.getUnionId());
//模版id Map<String, Object> map = new HashMap<>(4);
map.put("template_id", wechatMPMessage.getCode()); //用户id
//模版中所需数据 map.put("touser", connect.getUnionId());
map.put("data", createData(order, wechatMPMessage)); //模版id
map.put("page", "pages/order/orderDetail?sn=" + order.getSn()); map.put("template_id", wechatMPMessage.getCode());
log.info("参数内容:" + JSONUtil.toJsonStr(map)); //模版中所需数据
String content = null; map.put("data", createData(order, wechatMPMessage));
try { map.put("page", "pages/order/orderDetail?sn=" + order.getSn());
content = HttpUtil.post(url, JSONUtil.toJsonStr(map)); log.info("参数内容:" + JSONUtil.toJsonStr(map));
} catch (Exception e) { String content = null;
log.error("微信消息发送错误", e); try {
} content = HttpUtil.post(url, JSONUtil.toJsonStr(map));
JSONObject json = new JSONObject(content); } catch (Exception e) {
log.info("微信消息发送结果:" + content); log.error("微信消息发送错误", e);
String errorMessage = json.getStr("errmsg"); }
String errcode = json.getStr("errcode"); JSONObject json = new JSONObject(content);
//发送失败 log.info("微信小程序消息发送结果:" + content);
if (!"0".equals(errcode)) { String errorMessage = json.getStr("errmsg");
log.error("消息发送失败:" + errorMessage); String errcode = json.getStr("errcode");
log.error("消息发送请求token" + token); //发送失败
log.error("消息发送请求:" + map.get("data")); if (!"0".equals(errcode)) {
log.error("消息发送失败:" + errorMessage);
log.error("消息发送请求token" + token);
log.error("消息发送请求:" + map.get("data"));
}
} }
} }