|
@@ -13,6 +13,8 @@ import com.factory.wx.entity.res.FunctionsRes;
|
|
|
import com.factory.wx.mapper.WxMapper;
|
|
|
import com.factory.wx.service.WxPlanService;
|
|
|
import com.factory.wx.service.WxService;
|
|
|
+import org.slf4j.Logger;
|
|
|
+import org.slf4j.LoggerFactory;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.beans.factory.annotation.Value;
|
|
|
import org.springframework.stereotype.Service;
|
|
@@ -30,6 +32,8 @@ import java.util.List;
|
|
|
@Transactional(rollbackFor = Exception.class)
|
|
|
public class WxServiceImpl implements WxService {
|
|
|
|
|
|
+ private final static Logger LOGGER = LoggerFactory.getLogger(WxServiceImpl.class);
|
|
|
+
|
|
|
@Value("${wx.minprogram.appsecret}")
|
|
|
private String appsecret;
|
|
|
|
|
@@ -91,23 +95,28 @@ public class WxServiceImpl implements WxService {
|
|
|
|
|
|
@Override
|
|
|
public void sendWechatMessage(SendMsgReq sendMsgReq) {
|
|
|
- String openId = wxMapper.selectOne(Wrappers.<UsUserWechat>lambdaQuery().eq(UsUserWechat::getUserId, sendMsgReq.getToUserId())).getOpenid();
|
|
|
- if (!openId.isEmpty()) {
|
|
|
- AppEntry appEntry = AppEntry.builder().appId(appid).secret(appsecret).build();
|
|
|
- HashMap<String, ValEntry> dataMap = new HashMap();
|
|
|
- dataMap.put("thing1", ValEntry.builder().value(sendMsgReq.getContent()).build());
|
|
|
- dataMap.put("thing2", ValEntry.builder().value(sendMsgReq.getTitle()).build());
|
|
|
- dataMap.put("time3", ValEntry.builder().value(sendMsgReq.getEndTime()).build());
|
|
|
- String fromUserName = wxPlanService.getUserNameById(sendMsgReq.getFromUserId());
|
|
|
- dataMap.put("thing4", ValEntry.builder().value(fromUserName).build());
|
|
|
- TemplateEntry tpl = TemplateEntry.builder()
|
|
|
- .template_id(templateId)
|
|
|
- .touser(openId)
|
|
|
- .page(page)
|
|
|
- .miniprogram_state(miniprogramState)
|
|
|
- .data(dataMap)
|
|
|
- .build();
|
|
|
- PushWxMessage.sendMessage(appEntry, tpl);
|
|
|
+ try {
|
|
|
+ String openId = wxMapper.selectOne(Wrappers.<UsUserWechat>lambdaQuery().eq(UsUserWechat::getUserId, sendMsgReq.getToUserId())).getOpenid();
|
|
|
+ if (!openId.isEmpty()) {
|
|
|
+ AppEntry appEntry = AppEntry.builder().appId(appid).secret(appsecret).build();
|
|
|
+ HashMap<String, ValEntry> dataMap = new HashMap();
|
|
|
+ dataMap.put("thing1", ValEntry.builder().value(sendMsgReq.getContent()).build());
|
|
|
+ dataMap.put("thing2", ValEntry.builder().value(sendMsgReq.getTitle()).build());
|
|
|
+ dataMap.put("time3", ValEntry.builder().value(sendMsgReq.getEndTime()).build());
|
|
|
+ String fromUserName = wxPlanService.getUserNameById(sendMsgReq.getFromUserId());
|
|
|
+ dataMap.put("thing4", ValEntry.builder().value(fromUserName).build());
|
|
|
+ TemplateEntry tpl = TemplateEntry.builder()
|
|
|
+ .template_id(templateId)
|
|
|
+ .touser(openId)
|
|
|
+ .page(page)
|
|
|
+ .miniprogram_state(miniprogramState)
|
|
|
+ .data(dataMap)
|
|
|
+ .build();
|
|
|
+ PushWxMessage.sendMessage(appEntry, tpl);
|
|
|
+ }
|
|
|
+ } catch (Exception e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ LOGGER.error("下发微信消息异常");
|
|
|
}
|
|
|
}
|
|
|
}
|