| 
					
				 | 
			
			
				@ -0,0 +1,72 @@ 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				package com.yihu.jw.care.service.dingding;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.alibaba.fastjson.JSONObject;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.util.DingdingUtil;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.care.util.MessageUtil;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.doctor.dao.BaseDoctorDao;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.entity.base.doctor.BaseDoctorDO;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import com.yihu.jw.restmodel.web.ObjEnvelop;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.apache.commons.lang3.StringUtils;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.beans.factory.annotation.Autowired;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				import org.springframework.stereotype.Service;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				/**
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @author xyq
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @create 2022-06-02 16:21
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 * @slogan 他化自在,我自逍遥
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				 */
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				@Service
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				public class DingDingMessageService {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private DingdingUtil dingdingUtil;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private BaseDoctorDao doctorDao;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    @Autowired
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    private MessageUtil messageUtil;
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    /**
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     *
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param sendId 发送者的钉钉id
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param receiverId 接收者的医生id
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param content 消息内容
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param msgtype 消息类型,text,link
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param url
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @param title
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     * @return
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				     */
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    public ObjEnvelop sendMessageToOne(String sendId, String receiverId, String content, String msgtype, String url, String title){
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //messageUtil.sendDoctorDingdingMessage(null,receiverId,"text",null,content,null,null);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(StringUtils.isBlank(receiverId)){
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getError("医生id不能为空");
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        BaseDoctorDO doctorById = doctorDao.findById(receiverId);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(doctorById == null || StringUtils.isBlank(doctorById.getYktDoctorId())){
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getError("接收者id不能为空");
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        receiverId = doctorById.getYktDoctorId();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject msg = new JSONObject();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        msg.put("msgtype",msgtype);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if("text".equals(msgtype)){
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject text = new JSONObject();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            text.put("content",content);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            msg.put("text",text);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else if("link".equals(msgtype)){
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            JSONObject link = new JSONObject();
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            link.put("messageUrl",url);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            link.put("title",title);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            link.put("text",content);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            link.put("picMediaId",DingdingUtil.picMediaId);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            msg.put("link",link);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        String s = dingdingUtil.sendP2pMsg(msg.toString(), receiverId,sendId);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        //String s = "{\\\"_RequestId\\\":\\\"da6c6a8716541404813972617d0011\\\",\\\"Message\\\":\\\"User not authorized to operate on the specified resource.\\\",\\\"success\\\":false,\\\"errorCode\\\":\\\"100\\\",\\\"HostId\\\":\\\"openplatform-pro.ding.zj.gov.cn\\\",\\\"Code\\\":\\\"Forbidden\\\",\\\"bizErrorCode\\\":\\\"OPF-B001-05-16-0002\\\",\\\"errorMsg\\\":\\\"User not authorized to operate on the specified resource.\\\",\\\"errorLevel\\\":\\\"error\\\"}";
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        s = s.replace("\\","");
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        JSONObject jsonObject = JSONObject.parseObject(s);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        if(jsonObject.getBooleanValue("success")){
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getSuccess("发送成功",jsonObject);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }else {
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				            return ObjEnvelop.getSuccess("发送失败",jsonObject,-1);
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				        }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				    }
 
			 | 
		
	
		
			
				 | 
				 | 
			
			
				}
 
			 |