Bladeren bron

Merge branch 'dev' of wujunjie/patient-co-management into dev

yeshijie 7 jaren geleden
bovenliggende
commit
b7c58e673c

+ 100 - 2
patient-co/patient-co-doctor-assistant/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcMessageController.java

@ -1,6 +1,9 @@
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.wechat.WechatTemplateData;
import com.yihu.wlyy.repository.doctor.DoctorDao;
import com.yihu.wlyy.service.common.SMSService;
import com.yihu.wlyy.service.common.account.PatientService;
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.ApiOperation;
import io.swagger.annotations.ApiParam;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -19,8 +23,7 @@ import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.*;
import javax.servlet.http.HttpServletRequest;
import java.util.ArrayList;
import java.util.List;
import java.util.*;
import java.util.concurrent.ExecutionException;
/**
@ -40,6 +43,8 @@ public class GcMessageController {
    private PatientService patientService;
    @Autowired
    private SMSService smsService;
    @Autowired
    private DoctorDao doctorDao;
    @RequestMapping(value = "/sendWXTemplate", method = RequestMethod.POST)
    @ApiOperation("给患者发送微信模板消息")
@ -101,4 +106,97 @@ public class GcMessageController {
            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;
    }
}

+ 3 - 3
patient-co/patient-co-doctor-assistant/src/main/resources/application-prod.yml

@ -25,11 +25,11 @@ im:
  data_base_name: im
wechat:
  appId: wxad04e9c4c5255acf
  appSecret: ae77c48ccf1af5d07069f5153d1ac8d3
  appId: wx088a4d8e8208e6ce
  appSecret: ab3cdd509fb76fd0149e8864c97e8ddb
  wechat_token: 27eb3bb24f149a7760cf1bb154b08040
  wechat_base_url: http%3a%2f%2fwww.xmtyw.cn%2fwlyy
  accId: gh_ffd64560fb21
  accId: gh_b0f086d0d2f5
  message:
   ##医生追加建议提醒 --签约邀请
   doctor_invitel_template: MQn79bx1ofb6hekhmRIuqLU7KjySJQzaBzrimgqVrzA

+ 1 - 1
patient-co/patient-co-doctor-assistant/src/main/resources/wechat/weixin_menu_feldsher.txt

@ -3,7 +3,7 @@
        {
            "name": "我的资料",
            "type": "view",
		    "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fgrzx%2fhtml%2fmy-detail.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
		    "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx088a4d8e8208e6ce&redirect_uri=http%3a%2f%2fwww.xmtyw.cn%2fwlyy%2fwx_doctor%2fhtml%2fhome%2fhtml%2fjumpApp.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
        }
    ]
}