微信消息推送优化
parent
aeb53568f6
commit
17b5476c03
|
|
@ -4,10 +4,12 @@ import com.njzscloud.supervisory.sys.log.utils.SpringBeanHolder;
|
|||
import org.springframework.boot.SpringApplication;
|
||||
import org.springframework.boot.autoconfigure.SpringBootApplication;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.scheduling.annotation.EnableAsync;
|
||||
import org.springframework.scheduling.annotation.EnableScheduling;
|
||||
|
||||
@EnableScheduling
|
||||
@SpringBootApplication
|
||||
@EnableAsync
|
||||
public class Main {
|
||||
public static void main(String[] args) {
|
||||
SpringApplication.run(Main.class, args);
|
||||
|
|
|
|||
|
|
@ -11,6 +11,7 @@ import java.time.LocalDateTime;
|
|||
|
||||
/**
|
||||
* 资金账户表
|
||||
* @author ljw
|
||||
*/
|
||||
@Getter
|
||||
@Setter
|
||||
|
|
@ -45,6 +46,11 @@ public class MoneyAccountEntity {
|
|||
*/
|
||||
private BigDecimal revenue;
|
||||
|
||||
/**
|
||||
* 附件地址
|
||||
*/
|
||||
private String fileUrl;
|
||||
|
||||
/**
|
||||
* 修改时间
|
||||
*/
|
||||
|
|
|
|||
|
|
@ -52,4 +52,14 @@ public class MoneyAccountResult {
|
|||
*/
|
||||
private Integer moneyType;
|
||||
|
||||
/**
|
||||
* 营收
|
||||
*/
|
||||
private BigDecimal revenue;
|
||||
|
||||
/**
|
||||
* 附件地址
|
||||
*/
|
||||
private String fileUrl;
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -27,7 +27,7 @@ public class MoneyBillQuartz {
|
|||
private final MoneyBillMapper moneyBillMapper;
|
||||
|
||||
// @Scheduled(cron = "0 0/5 * * * ?")//每1分钟一次
|
||||
@Scheduled(cron = "0 0 1 27 * ?")// 每月27号凌晨1点执行
|
||||
@Scheduled(cron = "0 0 1 1 * ?")// 每月1号凌晨1点执行
|
||||
public void syncAssetsDiscover() {
|
||||
generateMoneyBill();
|
||||
}
|
||||
|
|
|
|||
|
|
@ -183,7 +183,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|||
param.setTempType(TempType.TRANS_COMPANY.getVal());
|
||||
param.setSn(orderInfoEntity.getSn());
|
||||
param.setGoodsName(entity.getGoodsName());
|
||||
param.setStartAddress(cargoPlace.getAreaName() + cargoPlace.getTownName() + cargoPlace.getAddress());
|
||||
param.setStartAddress(cargoPlace.getAddress());
|
||||
wechatTemplateMessageService.sendTemplateMessage(param);
|
||||
} catch (Exception e) {
|
||||
log.error("通知失败", e);
|
||||
|
|
@ -703,7 +703,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|||
wechatTemplateMessageService.sendTemplateMessage(param);
|
||||
} else if (AuditStatus.BoHui.equals(auditStatus)) {
|
||||
param.setTempType(TempType.AUDIT_REJECT.getVal());
|
||||
param.setStartAddress(detail.getAreaName() + detail.getTownName() + detail.getAddress());
|
||||
param.setStartAddress(detail.getAddress());
|
||||
wechatTemplateMessageService.sendTemplateMessage(param);
|
||||
}
|
||||
} catch (Exception e) {
|
||||
|
|
@ -789,7 +789,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|||
param.setSn(orderInfo.getSn());
|
||||
param.setDriverName(driverEntity.getDriverName());
|
||||
OrderCargoPlaceEntity cargoPlace = orderCargoPlaceService.getById(orderInfo.getCargoPlaceId());
|
||||
param.setStartAddress(cargoPlace.getAreaName() + cargoPlace.getTownName() + cargoPlace.getAddress());
|
||||
param.setStartAddress(cargoPlace.getAddress());
|
||||
BizCompanyEntity companyEntity = bizCompanyService.getById(orderInfo.getStationId());
|
||||
param.setEndAddress(companyEntity.getStationName());
|
||||
wechatTemplateMessageService.sendTemplateMessage(param);
|
||||
|
|
@ -824,7 +824,7 @@ public class OrderInfoService extends ServiceImpl<OrderInfoMapper, OrderInfoEnti
|
|||
OrderGoodsEntity entity = orderGoodsService.getById(orderInfo.getGoodsId());
|
||||
param.setGoodsName(entity.getGoodsName());
|
||||
OrderCargoPlaceEntity cargoPlace = orderCargoPlaceService.getById(orderInfo.getCargoPlaceId());
|
||||
param.setStartAddress(cargoPlace.getAreaName() + cargoPlace.getTownName() + cargoPlace.getAddress());
|
||||
param.setStartAddress(cargoPlace.getAddress());
|
||||
wechatTemplateMessageService.sendTemplateMessage(param);
|
||||
} catch (Exception e) {
|
||||
log.error("通知失败", e);
|
||||
|
|
|
|||
|
|
@ -1,5 +1,8 @@
|
|||
package com.njzscloud.supervisory.wxPay.contant;
|
||||
|
||||
/**
|
||||
* @author ljw
|
||||
*/
|
||||
public class WxApiConfig {
|
||||
|
||||
public static final String APP_ID = "wxcf5b818c19c51c07";
|
||||
|
|
@ -8,7 +11,8 @@ public class WxApiConfig {
|
|||
|
||||
public static final String REDIRECT_URI = "https://supervisory.njzscloud.com/test/bind/index.html";
|
||||
|
||||
public static final String SCOPE = "snsapi_base"; // 静默授权,仅获取OpenID
|
||||
// 静默授权,仅获取OpenID
|
||||
public static final String SCOPE = "snsapi_base";
|
||||
// String scope = "snsapi_userinfo"; // 非静默授权,可获取用户昵称、头像等更多信息[citation:1]
|
||||
|
||||
public static final String ENC = "UTF-8";
|
||||
|
|
@ -21,5 +25,5 @@ public class WxApiConfig {
|
|||
|
||||
public static final String TICKET_URL = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=";
|
||||
|
||||
|
||||
public static final String XCX_APP_ID = "wx989ea47a5ddf9bfb";
|
||||
}
|
||||
|
|
|
|||
|
|
@ -28,6 +28,7 @@ import java.util.UUID;
|
|||
|
||||
/**
|
||||
* 微信消息推送服务实现类
|
||||
* @author ljw
|
||||
*/
|
||||
@Slf4j
|
||||
@Service
|
||||
|
|
@ -36,6 +37,21 @@ public class WechatTemplateMessageServiceImpl implements WechatTemplateMessageSe
|
|||
|
||||
private final UserService userService;
|
||||
|
||||
/**
|
||||
* 处理微信模板消息thing字段的字符长度限制(最多20个字符)
|
||||
* @param content 原始内容
|
||||
* @return 处理后的内容
|
||||
*/
|
||||
private String truncateForThingField(String content) {
|
||||
if (Strings.isNullOrEmpty(content)) {
|
||||
return content;
|
||||
}
|
||||
if (content.length() > 20) {
|
||||
return content.substring(0, 17) + "...";
|
||||
}
|
||||
return content;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void bind(String code) {
|
||||
// 使用Code换取Access Token和OpenID
|
||||
|
|
@ -116,17 +132,17 @@ public class WechatTemplateMessageServiceImpl implements WechatTemplateMessageSe
|
|||
data = new HashMap<>();
|
||||
data.put("character_string2", new TemplateData(param.getSn()));
|
||||
data.put("thing19", new TemplateData(param.getGoodsName()));
|
||||
data.put("thing4", new TemplateData(param.getStartAddress()));
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.TRANS_COMPANY_TEMP_ID, data, null, null);
|
||||
data.put("thing4", new TemplateData(truncateForThingField(param.getStartAddress())));
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.TRANS_COMPANY_TEMP_ID, data, null, "pages/basicPage/publicOrder");
|
||||
} else if (TempType.DRIVER.getVal().equals(param.getTempType())) {
|
||||
// 通知司机
|
||||
// 构建模板数据
|
||||
data = new HashMap<>();
|
||||
data.put("character_string5", new TemplateData(param.getSn()));
|
||||
data.put("thing7", new TemplateData(param.getDriverName()));
|
||||
data.put("thing2", new TemplateData(param.getStartAddress()));
|
||||
data.put("thing2", new TemplateData(truncateForThingField(param.getStartAddress())));
|
||||
data.put("thing3", new TemplateData(param.getEndAddress()));
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.DRIVER_TEMP_ID, data, null, null);
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.DRIVER_TEMP_ID, data, null, "pages/transportPage/jointOrder");
|
||||
} else if (TempType.AUDIT_PENDING.getVal().equals(param.getTempType())) {
|
||||
// 待审核
|
||||
// 构建模板数据
|
||||
|
|
@ -135,7 +151,7 @@ public class WechatTemplateMessageServiceImpl implements WechatTemplateMessageSe
|
|||
data.put("thing11", new TemplateData(param.getGoodsName()));
|
||||
data.put("thing9", new TemplateData(param.getCfCompanyName()));
|
||||
data.put("car_number13", new TemplateData(param.getLicensePlate()));
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.AUDIT_PENDING, data, null, null);
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.AUDIT_PENDING, data, null, "pages/adminPage/jianGuan");
|
||||
} else if (TempType.AUDIT_OK.getVal().equals(param.getTempType())) {
|
||||
// 审核通过
|
||||
// 构建模板数据
|
||||
|
|
@ -145,15 +161,15 @@ public class WechatTemplateMessageServiceImpl implements WechatTemplateMessageSe
|
|||
data.put("thing8", new TemplateData(param.getDriverName()));
|
||||
data.put("car_number7", new TemplateData(param.getLicensePlate()));
|
||||
data.put("thing3", new TemplateData(param.getEndAddress()));
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.AUDIT_OK, data, null, null);
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.AUDIT_OK, data, null, "pages/transportPage/jointOrder");
|
||||
} else if (TempType.AUDIT_REJECT.getVal().equals(param.getTempType())) {
|
||||
// 审核驳回
|
||||
// 构建模板数据
|
||||
data = new HashMap<>();
|
||||
data.put("character_string8", new TemplateData(param.getSn()));
|
||||
data.put("thing4", new TemplateData(param.getGoodsName()));
|
||||
data.put("thing2", new TemplateData(param.getStartAddress()));
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.AUDIT_REJECT, data, null, null);
|
||||
data.put("thing2", new TemplateData(truncateForThingField(param.getStartAddress())));
|
||||
sendMessage(userEntity.getOpenid(), TemplateID.AUDIT_REJECT, data, null, "pages/transportPage/jointOrder");
|
||||
}
|
||||
} else {
|
||||
log.info("未查询到用户信息或不存在openid,无法通知");
|
||||
|
|
@ -180,13 +196,16 @@ public class WechatTemplateMessageServiceImpl implements WechatTemplateMessageSe
|
|||
requestData.put("template_id", templateId);
|
||||
|
||||
if (url != null) {
|
||||
requestData.put("url", url); // 点击消息跳转的URL
|
||||
// 点击消息跳转的URL
|
||||
requestData.put("url", url);
|
||||
} else {
|
||||
requestData.put("url", "https://supervisory.njzscloud.com");
|
||||
}
|
||||
|
||||
if (miniProgram != null) {
|
||||
JSONObject miniProgramObj = new JSONObject();
|
||||
miniProgramObj.put("appid", miniProgram);
|
||||
miniProgramObj.put("pagepath", "pages/index/index");
|
||||
miniProgramObj.put("appid", WxApiConfig.XCX_APP_ID);
|
||||
miniProgramObj.put("pagepath", miniProgram);
|
||||
requestData.put("miniprogram", miniProgramObj);
|
||||
}
|
||||
|
||||
|
|
@ -201,7 +220,7 @@ public class WechatTemplateMessageServiceImpl implements WechatTemplateMessageSe
|
|||
dataObj.put(entry.getKey(), item);
|
||||
}
|
||||
requestData.put("data", dataObj);
|
||||
log.info(JSONObject.toJSONString(requestData));
|
||||
log.info("发送模板消息参数为:{}", JSONObject.toJSONString(requestData));
|
||||
|
||||
// 4. 发送请求
|
||||
RestTemplate restTemplate = new RestTemplate();
|
||||
|
|
|
|||
|
|
@ -9,6 +9,8 @@
|
|||
ma.user_id as userId,
|
||||
ma.station_id as stationId,
|
||||
ma.money,
|
||||
ma.revenue,
|
||||
ma.file_url,
|
||||
ma.modify_time as modifyTime,
|
||||
CASE
|
||||
WHEN ma.user_id IS NOT NULL THEN u.nickname
|
||||
|
|
@ -51,6 +53,8 @@
|
|||
ma.user_id as userId,
|
||||
ma.station_id as stationId,
|
||||
ma.money,
|
||||
ma.revenue,
|
||||
ma.file_url,
|
||||
ma.modify_time as modifyTime,
|
||||
CASE
|
||||
WHEN ma.user_id IS NOT NULL THEN u.nickname
|
||||
|
|
|
|||
Loading…
Reference in New Issue