|  | @ -1,6 +1,9 @@
 | 
												
													
														
															|  | package com.yihu.wlyy.web.third.gateway.controller.doctor;
 |  | package com.yihu.wlyy.web.third.gateway.controller.doctor;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  | import com.yihu.wlyy.entity.doctor.profile.Doctor;
 | 
												
													
														
															|  | import com.yihu.wlyy.entity.patient.Patient;
 |  | import com.yihu.wlyy.entity.patient.Patient;
 | 
												
													
														
															|  | 
 |  | import com.yihu.wlyy.entity.wechat.WechatTemplateData;
 | 
												
													
														
															|  | 
 |  | import com.yihu.wlyy.repository.doctor.DoctorDao;
 | 
												
													
														
															|  | import com.yihu.wlyy.service.common.SMSService;
 |  | import com.yihu.wlyy.service.common.SMSService;
 | 
												
													
														
															|  | import com.yihu.wlyy.service.common.account.PatientService;
 |  | import com.yihu.wlyy.service.common.account.PatientService;
 | 
												
													
														
															|  | import com.yihu.wlyy.util.NetworkUtil;
 |  | import com.yihu.wlyy.util.NetworkUtil;
 | 
												
											
												
													
														
															|  | @ -10,6 +13,7 @@ import com.yihu.wlyy.wechat.util.WeiXinTempMsgSendUtils;
 | 
												
													
														
															|  | import io.swagger.annotations.Api;
 |  | import io.swagger.annotations.Api;
 | 
												
													
														
															|  | import io.swagger.annotations.ApiOperation;
 |  | import io.swagger.annotations.ApiOperation;
 | 
												
													
														
															|  | import io.swagger.annotations.ApiParam;
 |  | import io.swagger.annotations.ApiParam;
 | 
												
													
														
															|  | 
 |  | import org.apache.commons.lang3.StringUtils;
 | 
												
													
														
															|  | import org.json.JSONObject;
 |  | import org.json.JSONObject;
 | 
												
													
														
															|  | import org.slf4j.Logger;
 |  | import org.slf4j.Logger;
 | 
												
													
														
															|  | import org.slf4j.LoggerFactory;
 |  | import org.slf4j.LoggerFactory;
 | 
												
											
												
													
														
															|  | @ -19,8 +23,7 @@ import org.springframework.stereotype.Controller;
 | 
												
													
														
															|  | import org.springframework.web.bind.annotation.*;
 |  | import org.springframework.web.bind.annotation.*;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | import javax.servlet.http.HttpServletRequest;
 |  | import javax.servlet.http.HttpServletRequest;
 | 
												
													
														
															|  | import java.util.ArrayList;
 |  | 
 | 
												
													
														
															|  | import java.util.List;
 |  | 
 | 
												
													
														
															|  | 
 |  | import java.util.*;
 | 
												
													
														
															|  | import java.util.concurrent.ExecutionException;
 |  | import java.util.concurrent.ExecutionException;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | /**
 |  | /**
 | 
												
											
												
													
														
															|  | @ -40,6 +43,8 @@ public class GcMessageController {
 | 
												
													
														
															|  |     private PatientService patientService;
 |  |     private PatientService patientService;
 | 
												
													
														
															|  |     @Autowired
 |  |     @Autowired
 | 
												
													
														
															|  |     private SMSService smsService;
 |  |     private SMSService smsService;
 | 
												
													
														
															|  | 
 |  |     @Autowired
 | 
												
													
														
															|  | 
 |  |     private DoctorDao doctorDao;
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  |     @RequestMapping(value = "/sendWXTemplate", method = RequestMethod.POST)
 |  |     @RequestMapping(value = "/sendWXTemplate", method = RequestMethod.POST)
 | 
												
													
														
															|  |     @ApiOperation("给患者发送微信模板消息")
 |  |     @ApiOperation("给患者发送微信模板消息")
 | 
												
											
												
													
														
															|  | @ -101,4 +106,97 @@ public class GcMessageController {
 | 
												
													
														
															|  |             return new ResultBatchModel(BaseResultModel.statusEm.error_no_ip.getCode(), "获取IP失败", success, error, errorLiust);
 |  |             return new ResultBatchModel(BaseResultModel.statusEm.error_no_ip.getCode(), "获取IP失败", success, error, errorLiust);
 | 
												
													
														
															|  |         }
 |  |         }
 | 
												
													
														
															|  |     }
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 客服系统发送消息接口 居民没有有openID只发手机短信 有openID发微信模板消息、手机短信
 | 
												
													
														
															|  | 
 |  |      *
 | 
												
													
														
															|  | 
 |  |      * @param doctorCodes 医生code
 | 
												
													
														
															|  | 
 |  |      * @param content     消息内容限制字数70
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     @RequestMapping(value = "/sendMessage", method = RequestMethod.POST)
 | 
												
													
														
															|  | 
 |  |     @ApiOperation("客服系统发送消息接口")
 | 
												
													
														
															|  | 
 |  |     public ResultBatchModel sendMessage(
 | 
												
													
														
															|  | 
 |  |             @ApiParam(name = "doctorCodes", value = "医生code(批量逗号分割)", required = true) @RequestParam(value = "doctorCodes", required = true) String doctorCodes,
 | 
												
													
														
															|  | 
 |  |             @ApiParam(name = "content", value = "消息内容", required = true) @RequestParam(value = "content", required = true) String content) {
 | 
												
													
														
															|  | 
 |  |         Integer success = 0;
 | 
												
													
														
															|  | 
 |  |         Integer error = 0;
 | 
												
													
														
															|  | 
 |  |         List<String> errorLiust = new ArrayList<>();
 | 
												
													
														
															|  | 
 |  |         try {
 | 
												
													
														
															|  | 
 |  |             String templateId = "OqQXrb-e43_TJpq_70_K_y6vYJgY5mpjFYY4c5RWFP4";
 | 
												
													
														
															|  | 
 |  | //            String templateId = "";
 | 
												
													
														
															|  | 
 |  |             String url = "www.baidu.com";//要带基本地址
 | 
												
													
														
															|  | 
 |  |             String[] codeArr = doctorCodes.split(",");
 | 
												
													
														
															|  | 
 |  |             for (String code : codeArr) {
 | 
												
													
														
															|  | 
 |  |                 Doctor doctor = doctorDao.findByCode(code);
 | 
												
													
														
															|  | 
 |  |                 String openId = doctor.getOpenid();
 | 
												
													
														
															|  | 
 |  |                 String name = doctor.getName();
 | 
												
													
														
															|  | 
 |  |                 String mobile = doctor.getMobile();
 | 
												
													
														
															|  | 
 |  | //                String openId = "o7NFZw1QM4YR1O19mLjwfX1Hh11A";
 | 
												
													
														
															|  | 
 |  | //                String name = "吴家莲";
 | 
												
													
														
															|  | 
 |  | //                String mobile = "13611153674";
 | 
												
													
														
															|  | 
 |  |                 if (StringUtils.isEmpty(openId) && StringUtils.isNotEmpty(mobile)) {
 | 
												
													
														
															|  | 
 |  |                     try {
 | 
												
													
														
															|  | 
 |  |                         smsService.sendMsg(mobile, content);
 | 
												
													
														
															|  | 
 |  |                         success++;
 | 
												
													
														
															|  | 
 |  |                     } catch (Exception e) {
 | 
												
													
														
															|  | 
 |  |                         logger.error("mobile " + mobile + " send message error:" + e.getMessage());
 | 
												
													
														
															|  | 
 |  |                         error++;
 | 
												
													
														
															|  | 
 |  |                         errorLiust.add(mobile);
 | 
												
													
														
															|  | 
 |  |                     }
 | 
												
													
														
															|  | 
 |  |                 } else if (StringUtils.isNotEmpty(openId) && StringUtils.isNotEmpty(mobile)) {
 | 
												
													
														
															|  | 
 |  |                     try {
 | 
												
													
														
															|  | 
 |  |                         smsService.sendMsg(mobile, content);
 | 
												
													
														
															|  | 
 |  |                         success++;
 | 
												
													
														
															|  | 
 |  |                     } catch (Exception e) {
 | 
												
													
														
															|  | 
 |  |                         logger.error("mobile " + mobile + " send message error:" + e.getMessage());
 | 
												
													
														
															|  | 
 |  |                         error++;
 | 
												
													
														
															|  | 
 |  |                         errorLiust.add(mobile);
 | 
												
													
														
															|  | 
 |  |                     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |                     try {
 | 
												
													
														
															|  | 
 |  |                         JSONObject sendJson = packageTemplate("消息头","备注","续方提醒","2017年9月16日 18:00");
 | 
												
													
														
															|  | 
 |  |                         weiXinTempMsgSendUtils.sendTemplateMessage(templateId, openId, url, sendJson);
 | 
												
													
														
															|  | 
 |  |                         success++;
 | 
												
													
														
															|  | 
 |  |                     } catch (Exception e) {
 | 
												
													
														
															|  | 
 |  |                         logger.error("code " + code + " send Template error:" + e.getMessage());
 | 
												
													
														
															|  | 
 |  |                         error++;
 | 
												
													
														
															|  | 
 |  |                         errorLiust.add(code);
 | 
												
													
														
															|  | 
 |  |                     }
 | 
												
													
														
															|  | 
 |  |                 }
 | 
												
													
														
															|  | 
 |  |             }
 | 
												
													
														
															|  | 
 |  |             return new ResultBatchModel(success, error, errorLiust);
 | 
												
													
														
															|  | 
 |  |         } catch (Exception e) {
 | 
												
													
														
															|  | 
 |  |             return new ResultBatchModel(-1, "找不到该医生!", success, error, errorLiust);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |     /**
 | 
												
													
														
															|  | 
 |  |      * 构建微信模板内容消息体 默认字体黑色
 | 
												
													
														
															|  | 
 |  |      * @param first
 | 
												
													
														
															|  | 
 |  |      * @param remark
 | 
												
													
														
															|  | 
 |  |      * @param keywords
 | 
												
													
														
															|  | 
 |  |      * @return
 | 
												
													
														
															|  | 
 |  |      */
 | 
												
													
														
															|  | 
 |  |     public JSONObject packageTemplate(String first,String remark,String ... keywords) {
 | 
												
													
														
															|  | 
 |  |         JSONObject data = new JSONObject();
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | 
 |  |         Map keywordFirst = new HashMap();
 | 
												
													
														
															|  | 
 |  |         keywordFirst.put("color","#000000");
 | 
												
													
														
															|  | 
 |  |         keywordFirst.put("value",first);
 | 
												
													
														
															|  | 
 |  |         Map keywordRemark = new HashMap();
 | 
												
													
														
															|  | 
 |  |         keywordRemark.put("color","#000000");
 | 
												
													
														
															|  | 
 |  |         keywordRemark.put("value",remark);
 | 
												
													
														
															|  | 
 |  |         data.put("first",keywordFirst);
 | 
												
													
														
															|  | 
 |  |         data.put("remark",keywordRemark);
 | 
												
													
														
															|  | 
 |  |         for (int i=0;i<keywords.length;i++) {
 | 
												
													
														
															|  | 
 |  |             Map keyword1 = new HashMap();
 | 
												
													
														
															|  | 
 |  |             keyword1.put("color","#000000");
 | 
												
													
														
															|  | 
 |  |             keyword1.put("value",keywords[i]);
 | 
												
													
														
															|  | 
 |  |             data.put("keyword"+(i+1),keyword1);
 | 
												
													
														
															|  | 
 |  |         }
 | 
												
													
														
															|  | 
 |  |         System.out.println(data.toString());
 | 
												
													
														
															|  | 
 |  |         return data;
 | 
												
													
														
															|  | 
 |  |     }
 | 
												
													
														
															|  | 
 |  | 
 | 
												
													
														
															|  | }
 |  | }
 |