|
@ -2,14 +2,14 @@ package com.yihu.jw.hospital.task;
|
|
|
|
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.fasterxml.jackson.databind.ObjectMapper;
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
import com.yihu.jw.entity.wechat.WechatPushLog;
|
|
|
|
|
|
import com.yihu.jw.entity.base.wx.WxPushLogDO;
|
|
import com.yihu.jw.entity.wechat.WechatTemplate;
|
|
import com.yihu.jw.entity.wechat.WechatTemplate;
|
|
import com.yihu.jw.entity.wechat.WechatTemplateData;
|
|
import com.yihu.jw.entity.wechat.WechatTemplateData;
|
|
import com.yihu.jw.hospital.module.wx.dao.WechatPushLogDao;
|
|
|
|
import com.yihu.jw.hospital.utils.HttpUtil;
|
|
import com.yihu.jw.hospital.utils.HttpUtil;
|
|
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
|
|
import com.yihu.jw.hospital.utils.WeiXinAccessTokenUtils;
|
|
import com.yihu.jw.hospital.utils.WeiXinOpenIdUtils;
|
|
import com.yihu.jw.hospital.utils.WeiXinOpenIdUtils;
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
import com.yihu.jw.patient.dao.BasePatientDao;
|
|
|
|
import com.yihu.jw.wechat.dao.WxPushLogDao;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.apache.commons.lang3.StringUtils;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONArray;
|
|
import org.json.JSONException;
|
|
import org.json.JSONException;
|
|
@ -43,57 +43,62 @@ public class PushMsgTask {
|
|
private String putMesMethod;
|
|
private String putMesMethod;
|
|
@Value("${pushMes.redis_prescription_title}")
|
|
@Value("${pushMes.redis_prescription_title}")
|
|
private String redisQueue;
|
|
private String redisQueue;
|
|
// @Value("${putMesType.wechat}")
|
|
|
|
|
|
// @Value("${putMesType.wechat}")
|
|
private String putMesType;
|
|
private String putMesType;
|
|
|
|
|
|
//模板id
|
|
//模板id
|
|
// @Value("${wechat.message.template_sign_success}")
|
|
// @Value("${wechat.message.template_sign_success}")
|
|
private String template_sign_success;
|
|
private String template_sign_success;
|
|
// @Value("${wechat.message.template_sign_failed}")
|
|
|
|
|
|
// @Value("${wechat.message.template_sign_failed}")
|
|
private String template_sign_failed;
|
|
private String template_sign_failed;
|
|
// @Value("${wechat.message.template_consult_notice}")
|
|
|
|
|
|
// @Value("${wechat.message.template_consult_notice}")
|
|
private String template_consult_notice;
|
|
private String template_consult_notice;
|
|
// @Value("${wechat.message.template_health_notice}")
|
|
|
|
|
|
// @Value("${wechat.message.template_health_notice}")
|
|
private String template_health_notice;
|
|
private String template_health_notice;
|
|
// @Value("${wechat.message.template_termination}")
|
|
|
|
|
|
// @Value("${wechat.message.template_termination}")
|
|
private String template_termination;
|
|
private String template_termination;
|
|
// @Value("${wechat.message.template_appoint_success}")
|
|
|
|
|
|
// @Value("${wechat.message.template_appoint_success}")
|
|
private String template_appoint_success;
|
|
private String template_appoint_success;
|
|
// @Value("${wechat.message.template_appoint_failed}")
|
|
|
|
|
|
// @Value("${wechat.message.template_appoint_failed}")
|
|
private String template_appoint_failed;
|
|
private String template_appoint_failed;
|
|
// @Value("${wechat.message.template_expenses_remind}")
|
|
|
|
|
|
// @Value("${wechat.message.template_expenses_remind}")
|
|
private String template_expenses_remind;
|
|
private String template_expenses_remind;
|
|
// @Value("${wechat.message.template_healthy_article}")
|
|
|
|
|
|
// @Value("${wechat.message.template_healthy_article}")
|
|
private String template_healthy_article;
|
|
private String template_healthy_article;
|
|
// @Value("${wechat.message.template_doctor_change}")
|
|
|
|
|
|
// @Value("${wechat.message.template_doctor_change}")
|
|
private String template_doctor_change;
|
|
private String template_doctor_change;
|
|
// @Value("${wechat.message.template_doctor_survey}")
|
|
|
|
|
|
// @Value("${wechat.message.template_doctor_survey}")
|
|
private String template_doctor_survey;
|
|
private String template_doctor_survey;
|
|
// @Value("${wechat.message.template_doctor_audit}")
|
|
|
|
|
|
// @Value("${wechat.message.template_doctor_audit}")
|
|
private String template_doctor_audit;//审核结果通知
|
|
private String template_doctor_audit;//审核结果通知
|
|
// @Value("${wechat.message.template_doctor_service}")
|
|
|
|
|
|
// @Value("${wechat.message.template_doctor_service}")
|
|
private String template_doctor_service;//服务结果通知
|
|
private String template_doctor_service;//服务结果通知
|
|
// @Value("${wechat.message.template_physical_examination}")
|
|
|
|
|
|
// @Value("${wechat.message.template_physical_examination}")
|
|
private String template_physical_examination;//体检提醒
|
|
private String template_physical_examination;//体检提醒
|
|
// @Value("${wechat.message.doctor_invitel_template}")
|
|
|
|
|
|
// @Value("${wechat.message.doctor_invitel_template}")
|
|
private String doctor_invitel_template;
|
|
private String doctor_invitel_template;
|
|
// @Value("${wechat.message.template_deal_with}")
|
|
|
|
|
|
// @Value("${wechat.message.template_deal_with}")
|
|
private String template_deal_with;
|
|
private String template_deal_with;
|
|
// @Value("${wechat.message.template_patient_bind_device}")
|
|
|
|
|
|
// @Value("${wechat.message.template_patient_bind_device}")
|
|
private String template_patient_bind_device;
|
|
private String template_patient_bind_device;
|
|
// @Value("${wechat.message.template_healthbank_credit}")
|
|
|
|
|
|
// @Value("${wechat.message.template_healthbank_credit}")
|
|
private String template_healthbank_credit;
|
|
private String template_healthbank_credit;
|
|
// @Value("${wechat.message.template_rehabilitation_plan}")
|
|
|
|
|
|
// @Value("${wechat.message.template_rehabilitation_plan}")
|
|
private String template_rehabilitation_plan;
|
|
private String template_rehabilitation_plan;
|
|
// @Value("${wechat.message.template_process_feedback}")
|
|
|
|
|
|
// @Value("${wechat.message.template_process_feedback}")
|
|
private String template_process_feedback;
|
|
private String template_process_feedback;
|
|
// @Value("${wechat.message.template_birthday_wishes}")
|
|
|
|
|
|
// @Value("${wechat.message.template_birthday_wishes}")
|
|
private String template_birthday_wishes;//生日祝福
|
|
private String template_birthday_wishes;//生日祝福
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private StringRedisTemplate redisTemplate;
|
|
private StringRedisTemplate redisTemplate;
|
|
@Autowired
|
|
|
|
private WechatPushLogDao wechatPushLogDao;
|
|
|
|
|
|
|
|
|
|
// @Autowired
|
|
|
|
// private WechatPushLogDao wechatPushLogDao;
|
|
|
|
|
|
|
|
|
|
|
|
WxPushLogDao wxPushLogDao;
|
|
|
|
|
|
@Autowired
|
|
@Autowired
|
|
private WeiXinAccessTokenUtils accessTokenUtils;
|
|
private WeiXinAccessTokenUtils accessTokenUtils;
|
|
@Autowired
|
|
@Autowired
|
|
@ -293,6 +298,7 @@ public class PushMsgTask {
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
public boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
|
|
public boolean sendWeixinMessage(String access_token, int type, String openid, String name, JSONObject json) {
|
|
|
|
WxPushLogDO log = new WxPushLogDO();
|
|
try {
|
|
try {
|
|
if (StringUtils.isEmpty(openid)) {
|
|
if (StringUtils.isEmpty(openid)) {
|
|
logger.error("send wechat message failed:openid is empty");
|
|
logger.error("send wechat message failed:openid is empty");
|
|
@ -305,26 +311,26 @@ public class PushMsgTask {
|
|
logger.error("参数错误!error");
|
|
logger.error("参数错误!error");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
WechatPushLog log = new WechatPushLog();
|
|
|
|
log.setType(type);
|
|
|
|
log.setCreateTime(new Date());
|
|
|
|
log.setName(name);
|
|
|
|
log.setOpenid(openid);
|
|
log.setOpenid(openid);
|
|
if (!json.isNull("toUser")) {
|
|
|
|
log.setPatient(json.getString("toUser"));
|
|
|
|
}
|
|
|
|
|
|
log.setCreateTime(new Date());
|
|
|
|
// //这里没这些字段,后面看要不要补充
|
|
|
|
// log.setName(name);
|
|
|
|
// log.setType(type);
|
|
|
|
// if (!json.isNull("toUser")) {
|
|
|
|
// log.setPatient(json.getString("toUser"));
|
|
|
|
// }
|
|
log.setRequest(json.toString());
|
|
log.setRequest(json.toString());
|
|
String result = HttpUtil.sendPost(token_url, params);
|
|
String result = HttpUtil.sendPost(token_url, params);
|
|
JSONObject jsonResult = new JSONObject(result);
|
|
JSONObject jsonResult = new JSONObject(result);
|
|
log.setResponse(result);
|
|
log.setResponse(result);
|
|
if (Integer.parseInt(jsonResult.get("errcode").toString()) == 0) {
|
|
if (Integer.parseInt(jsonResult.get("errcode").toString()) == 0) {
|
|
logger.info("微信信息推送成功!success");
|
|
logger.info("微信信息推送成功!success");
|
|
log.setStatus(1);
|
|
|
|
wechatPushLogDao.save(log);
|
|
|
|
|
|
log.setStatus("1");
|
|
|
|
wxPushLogDao.save(log);
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
log.setStatus(0);
|
|
|
|
wechatPushLogDao.save(log);
|
|
|
|
|
|
log.setStatus("0");
|
|
|
|
wxPushLogDao.save(log);
|
|
logger.error("错误编码:" + jsonResult.get("errcode").toString() + " 错误提示:" + jsonResult.get("errmsg").toString());
|
|
logger.error("错误编码:" + jsonResult.get("errcode").toString() + " 错误提示:" + jsonResult.get("errmsg").toString());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@ -361,27 +367,29 @@ public class PushMsgTask {
|
|
logger.error("参数错误!error");
|
|
logger.error("参数错误!error");
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
WechatPushLog log = new WechatPushLog();
|
|
|
|
log.setType(type);
|
|
|
|
|
|
WxPushLogDO log = new WxPushLogDO();
|
|
|
|
|
|
log.setScene(scene);
|
|
log.setScene(scene);
|
|
log.setCreateTime(new Date());
|
|
log.setCreateTime(new Date());
|
|
log.setName(name);
|
|
|
|
log.setOpenid(openid);
|
|
log.setOpenid(openid);
|
|
if (!json.isNull("toUser")) {
|
|
|
|
log.setPatient(json.getString("toUser"));
|
|
|
|
}
|
|
|
|
|
|
// //这里没这些字段,后面看要不要补充
|
|
|
|
// log.setName(name);
|
|
|
|
// log.setType(type);
|
|
|
|
// if (!json.isNull("toUser")) {
|
|
|
|
// log.setPatient(json.getString("toUser"));
|
|
|
|
// }
|
|
log.setRequest(json.toString());
|
|
log.setRequest(json.toString());
|
|
String result = HttpUtil.sendPost(token_url, params);
|
|
String result = HttpUtil.sendPost(token_url, params);
|
|
JSONObject jsonResult = new JSONObject(result);
|
|
JSONObject jsonResult = new JSONObject(result);
|
|
log.setResponse(result);
|
|
log.setResponse(result);
|
|
if (Integer.parseInt(jsonResult.get("errcode").toString()) == 0) {
|
|
if (Integer.parseInt(jsonResult.get("errcode").toString()) == 0) {
|
|
logger.info("微信信息推送成功!success");
|
|
logger.info("微信信息推送成功!success");
|
|
log.setStatus(1);
|
|
|
|
wechatPushLogDao.save(log);
|
|
|
|
|
|
log.setStatus("1");
|
|
|
|
wxPushLogDao.save(log);
|
|
return true;
|
|
return true;
|
|
} else {
|
|
} else {
|
|
log.setStatus(0);
|
|
|
|
wechatPushLogDao.save(log);
|
|
|
|
|
|
log.setStatus("0");
|
|
|
|
wxPushLogDao.save(log);
|
|
logger.error("错误编码:" + jsonResult.get("errcode").toString() + " 错误提示:" + jsonResult.get("errmsg").toString());
|
|
logger.error("错误编码:" + jsonResult.get("errcode").toString() + " 错误提示:" + jsonResult.get("errmsg").toString());
|
|
return false;
|
|
return false;
|
|
}
|
|
}
|
|
@ -467,7 +475,7 @@ public class PushMsgTask {
|
|
} else if (json.has("agent") && ("0".equals(json.getString("agent")))) {
|
|
} else if (json.has("agent") && ("0".equals(json.getString("agent")))) {
|
|
// 发送给自己
|
|
// 发送给自己
|
|
temp.setUrl(url + "qygl/html/pay_flow.html?openid=" + openid + "&state=" + json.getString("doctor") + "&toUser=" + json.getString("toUser") + "&toName=" + name + "&isRenew=" + isRenew + "&signState=" + signState + "&represented=" + json.getString("represented") + "&signCode=" + json.getString("signCode"));
|
|
temp.setUrl(url + "qygl/html/pay_flow.html?openid=" + openid + "&state=" + json.getString("doctor") + "&toUser=" + json.getString("toUser") + "&toName=" + name + "&isRenew=" + isRenew + "&signState=" + signState + "&represented=" + json.getString("represented") + "&signCode=" + json.getString("signCode"));
|
|
}else {
|
|
|
|
|
|
} else {
|
|
temp.setUrl((String) json.get("url"));
|
|
temp.setUrl((String) json.get("url"));
|
|
}
|
|
}
|
|
}
|
|
}
|
|
@ -482,7 +490,7 @@ public class PushMsgTask {
|
|
if (json.has("content")) {
|
|
if (json.has("content")) {
|
|
keyword1.setValue(json.getString("content"));
|
|
keyword1.setValue(json.getString("content"));
|
|
keyword2.setValue(json.getString("doctorName"));
|
|
keyword2.setValue(json.getString("doctorName"));
|
|
}else {
|
|
|
|
|
|
} else {
|
|
keyword1.setValue(json.getString("first"));
|
|
keyword1.setValue(json.getString("first"));
|
|
keyword2.setValue(json.getString("remark"));
|
|
keyword2.setValue(json.getString("remark"));
|
|
}
|
|
}
|
|
@ -584,7 +592,7 @@ public class PushMsgTask {
|
|
if (json.has("doctorName")) {
|
|
if (json.has("doctorName")) {
|
|
keyword1.setValue(json.getString("doctorName"));
|
|
keyword1.setValue(json.getString("doctorName"));
|
|
keyword4.setValue(json.getString("content"));
|
|
keyword4.setValue(json.getString("content"));
|
|
}else {
|
|
|
|
|
|
} else {
|
|
keyword1.setValue(json.getString("first"));
|
|
keyword1.setValue(json.getString("first"));
|
|
keyword4.setValue(json.getString("remark"));
|
|
keyword4.setValue(json.getString("remark"));
|
|
}
|
|
}
|
|
@ -1176,7 +1184,7 @@ public class PushMsgTask {
|
|
/**
|
|
/**
|
|
* 根据type 匹配对应模板ID
|
|
* 根据type 匹配对应模板ID
|
|
*
|
|
*
|
|
* @param type 见WechatPushLog说明
|
|
|
|
|
|
* @param type 见WxPushLogDO说明
|
|
* @return
|
|
* @return
|
|
*/
|
|
*/
|
|
private String getTemplateId(int type) throws Exception {
|
|
private String getTemplateId(int type) throws Exception {
|