|
@@ -5,6 +5,7 @@ import lombok.extern.slf4j.Slf4j;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
|
import org.springframework.stereotype.Service;
|
|
|
import org.springframework.web.client.RestTemplate;
|
|
|
+import thyyxxk.wxservice_server.config.exception.BizException;
|
|
|
import thyyxxk.wxservice_server.dao.WxApiDao;
|
|
|
import thyyxxk.wxservice_server.entity.wxapi.PushMessageParam;
|
|
|
import thyyxxk.wxservice_server.utils.PropertiesUtil;
|
|
@@ -27,25 +28,28 @@ public class PushWxMessageService {
|
|
|
this.dao = dao;
|
|
|
}
|
|
|
|
|
|
- public void pushMessage2(PushMessageParam param) {
|
|
|
+ public String pushMessage2(PushMessageParam param) {
|
|
|
if (StringUtil.isBlank(param.getCardNo())) {
|
|
|
- return;
|
|
|
+ throw new BizException("患者就诊卡号不能为空");
|
|
|
}
|
|
|
- List<String> openidList = param.isCardNoPatientId() ?
|
|
|
- dao.selectOpenidByPatientId(param.getCardNo()) : dao.selectOpenidByIcCardNo(param.getCardNo());
|
|
|
+ List<String> openidList = dao.selectOpenidByCardNo(param.getCardNo());
|
|
|
if (null == openidList || openidList.isEmpty()) {
|
|
|
- log.info("未找到卡号【{}】的openid。", param.getCardNo());
|
|
|
- return;
|
|
|
+ throw new BizException("未找到卡号【" + param.getCardNo() + "】的openid");
|
|
|
}
|
|
|
RestTemplate template = new RestTemplate();
|
|
|
JSONObject content = param.getMsgContext();
|
|
|
String wxUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" +
|
|
|
PropertiesUtil.getLocalProperty("access_token");
|
|
|
+ String res = null;
|
|
|
for (String openid : openidList) {
|
|
|
content.replace("touser", openid);
|
|
|
- String res = template.postForObject(wxUrl, content, String.class);
|
|
|
- log.info("推送消息:内容:{},结果:{}", content, res);
|
|
|
+ res = template.postForObject(wxUrl, content, String.class);
|
|
|
+ log.info("推送消息1:内容:{},结果:{}", content, res);
|
|
|
}
|
|
|
+ if (null == res) {
|
|
|
+ throw new BizException("推送失败,网络异常");
|
|
|
+ }
|
|
|
+ return res;
|
|
|
}
|
|
|
|
|
|
public String pushMessage2(JSONObject msgContent) {
|
|
@@ -53,7 +57,7 @@ public class PushWxMessageService {
|
|
|
String wxUrl = "https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=" +
|
|
|
PropertiesUtil.getLocalProperty("access_token");
|
|
|
String res = template.postForObject(wxUrl, msgContent, String.class);
|
|
|
- log.info("推送消息:内容:{},结果:{}", msgContent, res);
|
|
|
+ log.info("推送消息2:内容:{},结果:{}", msgContent, res);
|
|
|
if (StringUtil.isBlank(res)) {
|
|
|
return "推送失败,未知的异常。";
|
|
|
}
|