|
@ -8,6 +8,7 @@ import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
|
|
|
import com.yihu.jw.entity.base.im.ConsultTeamDo;
|
|
|
import com.yihu.jw.entity.base.patient.BasePatientDO;
|
|
|
import com.yihu.jw.entity.base.wx.*;
|
|
|
import com.yihu.jw.entity.base.yx.YxTokenMappingDO;
|
|
|
import com.yihu.jw.entity.hospital.consult.WlyyHospitalSysDictDO;
|
|
|
import com.yihu.jw.entity.hospital.prescription.WlyyOutpatientDO;
|
|
|
import com.yihu.jw.entity.order.BusinessOrderDO;
|
|
@ -31,6 +32,7 @@ import com.yihu.jw.utils.CheckSumBuilder;
|
|
|
import com.yihu.jw.utils.RSAEncrypt;
|
|
|
import com.yihu.jw.utils.hibernate.HibenateUtils;
|
|
|
import com.yihu.jw.wechat.dao.*;
|
|
|
import com.yihu.jw.yx.dao.YxTokenMappingDao;
|
|
|
import org.apache.commons.collections.map.HashedMap;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.apache.http.NameValuePair;
|
|
@ -104,6 +106,8 @@ public class WxTemplateService {
|
|
|
private HttpClientUtil httpClientUtil;
|
|
|
@Autowired
|
|
|
private OutpatientDao outpatientDao;
|
|
|
@Autowired
|
|
|
private YxTokenMappingDao yxTokenMappingDao;
|
|
|
|
|
|
|
|
|
|
|
@ -153,7 +157,7 @@ public class WxTemplateService {
|
|
|
String miniprogramUrl = "";
|
|
|
config.setFirst(config.getFirst().replace("key1",sender_name+titleName));
|
|
|
if (wechatId.equalsIgnoreCase("xm_ykyy_wx")){
|
|
|
String token = yxToken(reciver_id,reciver_name);
|
|
|
String token = yxToken2(reciver_id,reciver_name);
|
|
|
miniprogramUrl = "pages/room/yunxin?role=patient&token="+token+"&uid="+basePatientDO.getId();
|
|
|
config.setPagepath(miniprogramUrl);
|
|
|
}
|
|
@ -185,7 +189,7 @@ public class WxTemplateService {
|
|
|
return "success";
|
|
|
}
|
|
|
|
|
|
public String yxToken(String userId,String channelName){
|
|
|
/* public String yxToken(String userId,String channelName){
|
|
|
WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("YXAPPKEY");
|
|
|
WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YXAPPSECRET");
|
|
|
if (sysDictDO==null){
|
|
@ -216,6 +220,103 @@ public class WxTemplateService {
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}*/
|
|
|
|
|
|
public String yxToken2(String userId,String channelName){
|
|
|
YxTokenMappingDO yxTokenMappingDO = yxTokenMappingDao.findMappingByAccid(userId);
|
|
|
if (yxTokenMappingDO!=null){
|
|
|
return yxTokenMappingDO.getToken();
|
|
|
}
|
|
|
WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("YXAPPKEY");
|
|
|
WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YXAPPSECRET");
|
|
|
if (sysDictDO==null){
|
|
|
return "找不到对应的key";
|
|
|
}
|
|
|
String appKey = sysDictDO.getDictValue();
|
|
|
String appSecret = hospitalSysDictDO.getDictValue();
|
|
|
String nonce = randomInt(10);
|
|
|
String curTime = String.valueOf((new Date()).getTime() / 1000L);
|
|
|
String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码
|
|
|
String url = "https://api.netease.im/nimserver/user/create.action";
|
|
|
Map<String,Object> httpPost = new HashedMap();
|
|
|
// 设置请求的header
|
|
|
httpPost.put("AppKey", appKey);
|
|
|
httpPost.put("Nonce", nonce);
|
|
|
httpPost.put("CurTime", curTime);
|
|
|
httpPost.put("CheckSum", checkSum);
|
|
|
httpPost.put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
|
|
|
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
|
|
nvps.add(new BasicNameValuePair("accid", userId));
|
|
|
YxTokenMappingDO yxTokenMappingDO1 = new YxTokenMappingDO();
|
|
|
if (StringUtils.isNoneBlank(channelName)){
|
|
|
nvps.add(new BasicNameValuePair("name",channelName));
|
|
|
yxTokenMappingDO1.setName(channelName);
|
|
|
}
|
|
|
String response = httpClientUtil.headerPost(url,nvps,"UTF-8",httpPost);
|
|
|
logger.info("返回日志"+response);
|
|
|
if(StringUtils.isNoneBlank(response)){
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
|
|
|
if (jsonObject.getString("code").equalsIgnoreCase("200")){
|
|
|
com.alibaba.fastjson.JSONObject jsonObject1 = com.alibaba.fastjson.JSONObject.parseObject(jsonObject.getString("info"));
|
|
|
if (StringUtils.isNoneBlank(jsonObject1.getString("token"))){
|
|
|
yxTokenMappingDO1.setAccid(userId);
|
|
|
yxTokenMappingDO1.setToken(jsonObject1.getString("token"));
|
|
|
yxTokenMappingDao.save(yxTokenMappingDO1);
|
|
|
}
|
|
|
return jsonObject1.getString("token");
|
|
|
}else if (jsonObject.getString("code").equalsIgnoreCase("414")&&jsonObject.getString("desc").contains("already")){
|
|
|
return refreshToken(userId);
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|
|
|
* 重置云信token
|
|
|
* @param userId
|
|
|
* @return
|
|
|
*/
|
|
|
public String refreshToken(String userId){
|
|
|
YxTokenMappingDO yxTokenMappingDO = yxTokenMappingDao.findMappingByAccid(userId);
|
|
|
if (yxTokenMappingDO!=null){
|
|
|
return yxTokenMappingDO.getToken();
|
|
|
}
|
|
|
WlyyHospitalSysDictDO sysDictDO = hospitalSysDictDao.findById("YXAPPKEY");
|
|
|
WlyyHospitalSysDictDO hospitalSysDictDO = hospitalSysDictDao.findById("YXAPPSECRET");
|
|
|
if (sysDictDO==null){
|
|
|
return "找不到对应的key";
|
|
|
}
|
|
|
String appKey = sysDictDO.getDictValue();
|
|
|
String appSecret = hospitalSysDictDO.getDictValue();
|
|
|
String nonce = randomInt(10);
|
|
|
String curTime = String.valueOf((new Date()).getTime() / 1000L);
|
|
|
String checkSum = CheckSumBuilder.getCheckSum(appSecret, nonce ,curTime);//参考 计算CheckSum的java代码
|
|
|
String url = "https://api.netease.im/nimserver/user/refreshToken.action";
|
|
|
Map<String,Object> httpPost = new HashedMap();
|
|
|
// 设置请求的header
|
|
|
httpPost.put("AppKey", appKey);
|
|
|
httpPost.put("Nonce", nonce);
|
|
|
httpPost.put("CurTime", curTime);
|
|
|
httpPost.put("CheckSum", checkSum);
|
|
|
httpPost.put("Content-Type", "application/x-www-form-urlencoded;charset=utf-8");
|
|
|
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
|
|
|
nvps.add(new BasicNameValuePair("accid", userId));
|
|
|
YxTokenMappingDO yxTokenMappingDO1 = new YxTokenMappingDO();
|
|
|
String response = httpClientUtil.headerPost(url,nvps,"UTF-8",httpPost);
|
|
|
logger.info("重置云信"+response);
|
|
|
if(StringUtils.isNoneBlank(response)){
|
|
|
com.alibaba.fastjson.JSONObject jsonObject = com.alibaba.fastjson.JSONObject.parseObject(response);
|
|
|
if (jsonObject.getString("code").equalsIgnoreCase("200")){
|
|
|
com.alibaba.fastjson.JSONObject jsonObject1 = com.alibaba.fastjson.JSONObject.parseObject(jsonObject.getString("info"));
|
|
|
if (StringUtils.isNoneBlank(jsonObject1.getString("token"))){
|
|
|
yxTokenMappingDO1.setAccid(userId);
|
|
|
yxTokenMappingDO1.setToken(jsonObject1.getString("token"));
|
|
|
yxTokenMappingDao.save(yxTokenMappingDO1);
|
|
|
}
|
|
|
return jsonObject1.getString("token");
|
|
|
}
|
|
|
}
|
|
|
return null;
|
|
|
}
|
|
|
|
|
|
/**
|