|
|
@@ -17,6 +17,8 @@ import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import me.chanjar.weixin.mp.api.WxMpService;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateData;
|
|
|
import me.chanjar.weixin.mp.bean.template.WxMpTemplateMessage;
|
|
|
+import org.springframework.beans.factory.annotation.Value;
|
|
|
+import org.springframework.scheduling.annotation.Async;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
|
|
|
import java.io.IOException;
|
|
|
@@ -34,11 +36,15 @@ import java.util.Map;
|
|
|
public class WeixinMPServiceImpl implements WeixinMPService {
|
|
|
|
|
|
private final MpMsgTemplateService mpMsgTemplateService;
|
|
|
-
|
|
|
private final MpRelationServiceImpl mpRelationService;
|
|
|
-
|
|
|
private final WxMpService wxMpService;
|
|
|
|
|
|
+ /**
|
|
|
+ * 小程序appid
|
|
|
+ */
|
|
|
+ @Value("${wechat.miniapp.appid}")
|
|
|
+ public String appid;
|
|
|
+
|
|
|
public WeixinMPServiceImpl(MpMsgTemplateService mpMsgTemplateService, MpRelationServiceImpl mpRelationService, WxMpService wxMpService) {
|
|
|
this.mpMsgTemplateService = mpMsgTemplateService;
|
|
|
this.mpRelationService = mpRelationService;
|
|
|
@@ -119,6 +125,7 @@ public class WeixinMPServiceImpl implements WeixinMPService {
|
|
|
}
|
|
|
|
|
|
@Override
|
|
|
+ @Async
|
|
|
public void sendMPTemplateMessage(String mpOpenid, String templateTitle, List<String> dataList) throws WxErrorException {
|
|
|
var template = getMPMsgTemplate(templateTitle);
|
|
|
CommUtil.asserts(template != null, "模板消息不存在");
|
|
|
@@ -132,6 +139,9 @@ public class WeixinMPServiceImpl implements WeixinMPService {
|
|
|
for (int i = 0; i < templateKeys.length; i++) {
|
|
|
templateMessage.addData(new WxMpTemplateData(templateKeys[i], dataList.get(i)));
|
|
|
}
|
|
|
+ if (CommUtil.isNotEmptyAndNull(template.getPagePath())) {
|
|
|
+ templateMessage.setMiniProgram(new WxMpTemplateMessage.MiniProgram(appid, template.getPagePath(), false));
|
|
|
+ }
|
|
|
wxMpService.getTemplateMsgService().sendTemplateMsg(templateMessage);
|
|
|
}
|
|
|
}
|