Преглед на файлове

Merge branch 'srdev' of http://192.168.1.220:10080/Amoy/patient-co-management into srdev

trick9191 преди 7 години
родител
ревизия
8e709014eb

+ 4 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/concern/ConcernService.java

@ -58,6 +58,10 @@ public class ConcernService extends BaseService {
    @Transactional
    public boolean addConcern(
            String patientCode, String doctorCode, Integer concernSource) {
        ConcernDO concernDO=  concernDao.findByPatientAndDoctor(patientCode,doctorCode);
        if(concernDO!=null){
            return false;
        }
        Patient patient = patientDao.findByCode(patientCode);
        Doctor doctor = doctorDao.findByCodeWithLock(doctorCode);

+ 0 - 227
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/util/SendNews.java

@ -1,227 +0,0 @@
package com.yihu.wlyy.util;
import com.yihu.wlyy.entity.security.AccessToken;
import com.yihu.wlyy.repository.patient.PatientDao;
import com.yihu.wlyy.repository.security.AccessTokenDao;
import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.service.common.account.AccessTokenService;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import org.json.JSONArray;
import org.json.JSONObject;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.jdbc.core.JdbcTemplate;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springside.modules.utils.Clock;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.text.SimpleDateFormat;
import java.util.List;
import java.util.Map;
import java.util.Properties;
import static sun.management.Agent.error;
/**
 * Created by Reece on 2017/5/20.
 */
@Component
public class SendNews {
    private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
    @Autowired
    private HttpClientUtil HttpClientUtil;
    @Value("${wechat.wechat_base_url}")
    private String wechat_base_url;
    @Value("${wechat.appId}")
    private String appId;
    @Value("${images.sign_path}")
    private String sign_path;
    /**
     * 模拟form表单的形式 ,上传文件 以输出流的形式把文件写入到url中,然后用输入流来获取url的响应
     *
     * @param url      请求地址 form表单url地址
     * @param filePath 文件在服务器保存路径
     * @return String 上传的图片地址
     * @throws IOException
     */
    public  String uploadImage(String url, String filePath) throws IOException {
        String result = null;
        File file = new File(filePath);
        System.out.println("file  ====> " + file);
        if (!file.exists() || !file.isFile()) {
            throw new IOException("文件不存在");
        }
        /**
         * 第一部分
         */
        URL urlObj = new URL(url);
        // 连接
        HttpURLConnection con = (HttpURLConnection) urlObj.openConnection();
        /**
         * 设置关键值
         */
        con.setRequestMethod("POST"); // 以Post方式提交表单,默认get方式
        con.setDoInput(true);
        con.setDoOutput(true);
        con.setUseCaches(false); // post方式不能使用缓存
        // 设置请求头信息
        con.setRequestProperty("Connection", "Keep-Alive");
        con.setRequestProperty("Charset", "UTF-8");
        // 设置边界
        String BOUNDARY = "---------------------------" + System.currentTimeMillis();
        con.setRequestProperty("Content-Type", "multipart/form-data; boundary="
                + BOUNDARY);
        // 请求正文信息
        // 第一部分:
        StringBuilder sb = new StringBuilder();
        sb.append("--"); // 必须多两道线
        sb.append(BOUNDARY);
        sb.append("\r\n");
        sb.append("Content-Disposition: form-data;name=\"media\";filename=\""
                + file.getName() + "\"\r\n");
        sb.append("Content-Type:application/octet-stream\r\n\r\n");
        byte[] head = sb.toString().getBytes("utf-8");
        // 获得输出流
        OutputStream out = new DataOutputStream(con.getOutputStream());
        // 输出表头
        out.write(head);
        // 文件正文部分
        // 把文件已流文件的方式 推入到url中
        DataInputStream in = new DataInputStream(new FileInputStream(file));
        int bytes = 0;
        byte[] bufferOut = new byte[1024];
        while ((bytes = in.read(bufferOut)) != -1) {
            out.write(bufferOut, 0, bytes);
        }
        in.close();
        // 结尾部分
        byte[] foot = ("\r\n--" + BOUNDARY + "--\r\n").getBytes("utf-8");// 定义最后数据分隔线
        out.write(foot);
        out.flush();
        out.close();
        StringBuffer buffer = new StringBuffer();
        BufferedReader reader = null;
        try {
            // 定义BufferedReader输入流来读取URL的响应
            reader = new BufferedReader(new InputStreamReader(
                    con.getInputStream()));
            String line = null;
            while ((line = reader.readLine()) != null) {
                buffer.append(line);
            }
            if (result == null) {
                result = buffer.toString();
            }
        } catch (IOException e) {
            System.out.println("发送POST请求出现异常!" + e);
            e.printStackTrace();
            throw new IOException("数据读取异常");
        } finally {
            if (reader != null) {
                reader.close();
            }
        }
        return result;
    }
    /**
     * 上传图文消息文字素材
     *
     * @param accessToken
     * @param data        图文消息文字素材内容
     * @return
     */
    public  String uploadNesText(String accessToken, String url, JSONObject data) throws Exception {
        url = url.replaceFirst("ACCESS_TOKEN", accessToken);
        //上传的图文消息数据,其中thumb_media_id是文件上传图片上传的id
        String result = HttpClientUtil.postBody(url, data);
        return result;
    }
    /**
     * 发送图文消息
     *
     * @param accessToken
     * @param openidData  群发图文消息内容
     * @return
     */
    public  String sendNewspMessage(String accessToken, String url, JSONObject openidData) throws Exception {
        url = url.replace("ACCESS_TOKEN", accessToken);
        String json = HttpClientUtil.postBody(url, openidData);
        return json;
    }
    public  void sendNews(String accessToken, List<String> openIds) throws Exception {
        // 配置信息
        Properties systemConf = SystemConf.getInstance().getSystemProperties();
        //本地上传图片的路径及跳转路径
        String renewPath = systemConf.getProperty("renew_path");
        String renewUrl = systemConf.getProperty("patient_sign_again_url");
        renewUrl = renewUrl.replaceAll("\\{server\\}", wechat_base_url);
        renewUrl = renewUrl.replaceAll("\\{appId\\}", appId);
        renewUrl = renewUrl.replaceAll("amp;","");
        renewUrl = renewUrl.replaceAll(";","&");
        String signPath = sign_path;
        String signUrl = systemConf.getProperty("doctor_subscribe_url");
        signUrl = signUrl.replaceAll("\\{server\\}", wechat_base_url);
        signUrl = signUrl.replaceAll("\\{appId\\}", appId);
        signUrl = signUrl.replaceAll("amp;","");
        signUrl = signUrl.replaceAll(";","&");
        String getMediaUrl = "http://file.api.weixin.qq.com/cgi-bin/media/upload?access_token=ACCESS_TOKEN&type=image";//由sendUrl获取远程图片的mediaId
        String mediaurl = "https://api.weixin.qq.com/cgi-bin/media/uploadnews?access_token=ACCESS_TOKEN";//ACCESS_TOKEN是获取到的access_token
        String groupUrl = "https://api.weixin.qq.com/cgi-bin/message/mass/send?access_token=ACCESS_TOKEN";//根据openid发群发消息地址
        getMediaUrl = getMediaUrl.replace("ACCESS_TOKEN", accessToken);
        String renewImage = this.uploadImage(getMediaUrl, renewPath);
        String signImage = this.uploadImage(getMediaUrl, signPath);
        JSONObject newsTextData = new JSONObject();
        JSONArray newsText = new JSONArray();
//            续签图文
        JSONObject data = new JSONObject();
        data.put("thumb_media_id", new JSONObject(renewImage).get("media_id"));
        data.put("content_source_url", renewUrl);
        data.put("content", "家庭医生续签提醒");
        data.put("title", "家庭医生续签提醒");
        data.put("show_cover_pic", 1);
//            签约图文
        JSONObject data1 = new JSONObject();
        data1.put("thumb_media_id", new JSONObject(signImage).get("media_id"));
        data1.put("content_source_url", signUrl);
        data1.put("content", "欢迎关注厦门i健康,快来签约家庭医生吧~");
        data1.put("title", "欢迎关注厦门i健康,快来签约家庭医生吧~");
        data1.put("show_cover_pic", 1);
        newsText.put(data1);
        newsText.put(data);
        newsTextData.put("articles", newsText);
        String media = this.uploadNesText(accessToken, mediaurl, newsTextData);
        JSONObject news = new JSONObject();
        JSONObject mapnews = new JSONObject();
        mapnews.put("media_id", new JSONObject(media).get("media_id"));
        news.put("touser", openIds);
        news.put("mpnews", mapnews);
        news.put("msgtype", "mpnews");
        news.put("send_ignore_reprint", 1);
        this.sendNewspMessage(accessToken, groupUrl, news);
    }
}

+ 2 - 2
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/patient/consult/ConsultController.java

@ -571,7 +571,7 @@ public class ConsultController extends WeixinBaseController {
    @ResponseBody
    @ApiOperation("已关注的医生列表")
    public String concernDoctorList(
            @ApiParam(name = "hospitalCode", value = "医院code", defaultValue = "350200")
            @ApiParam(name = "hospitalCode", value = "医院code", defaultValue = "49229004X")
            @RequestParam(value = "hospitalCode", required = false) String hospitalCode,
            @ApiParam(name = "page", value = "第几页", defaultValue = "")
            @RequestParam(value = "page", required = false) Integer page,
@ -636,7 +636,7 @@ public class ConsultController extends WeixinBaseController {
    @ResponseBody
    @ApiOperation("医生列表")
    public String doctorList(
            @ApiParam(name = "hospitalCode", value = "医院code", defaultValue = "350200")
            @ApiParam(name = "hospitalCode", value = "医院code", defaultValue = "49229004X")
            @RequestParam(value = "hospitalCode", required = false) String hospitalCode,
            @ApiParam(name = "dept", value = "科室代码", defaultValue = "1")
            @RequestParam(value = "dept", required = false) String dept,

+ 3 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/wx/WechatCoreController.java

@ -188,16 +188,18 @@ public class WechatCoreController extends WeixinBaseController {
            String readTxt = "";
            // 读取微信菜单
            while ((readTxt = bufferedReader.readLine()) != null) {
                System.out.println(readTxt);
                params += readTxt;
            }
            bufferedReader.close();
            reader.close();
            // 替换服务器地址、APPID
            logger.info("wechat_base_url:"+wechat_base_url);
            logger.info("appId:"+appId);
            params = params.replaceAll("server_url", wechat_base_url);
            params = params.replaceAll("appId", appId);
            // 请求微信接口创建菜单
            System.out.println(params);
            String jsonStr = HttpUtil.sendPost(url, params);
            JSONObject result = new JSONObject(jsonStr);
            if (result != null && result.get("errcode").toString().equals("0") && result.getString("errmsg").equals("ok")) {

+ 40 - 40
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/wechat/process/WeiXinEventProcess.java

@ -132,23 +132,23 @@ public class WeiXinEventProcess {
        articles.add(articleConsult);
        Map<String, String> articleBooking = new HashMap<>();
        // 图文URL
        String urlBooking = systemConf.getProperty("patient_booking_url");
        // 图文消息图片URL
        String picUrlBooking = systemConf.getProperty("patient_booking_pic_url");
        // URL设置服务器URL、AppId
        urlBooking = urlBooking.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        picUrlBooking = picUrlBooking.replace("{server}", serverUrl);
        articleBooking.put("Url", urlBooking);
        articleBooking.put("Title", "预约挂号功能使用说明");
        articleBooking.put("Description", "功能使用说明");
        articleBooking.put("PicUrl", picUrlBooking);
        articles.add(articleBooking);
//        Map<String, String> articleBooking = new HashMap<>();
//        // 图文URL
//        String urlBooking = systemConf.getProperty("patient_booking_url");
//        // 图文消息图片URL
//        String picUrlBooking = systemConf.getProperty("patient_booking_pic_url");
//        // URL设置服务器URL、AppId
//        urlBooking = urlBooking.replace("{server}", wechat_base_url)
//                .replace("{appId}", appId);
//        //图片地址
//        picUrlBooking = picUrlBooking.replace("{server}", serverUrl);
//
//        articleBooking.put("Url", urlBooking);
//        articleBooking.put("Title", "预约挂号功能使用说明");
//        articleBooking.put("Description", "功能使用说明");
//        articleBooking.put("PicUrl", picUrlBooking);
//
//        articles.add(articleBooking);
        Map<String, String> articleDevice = new HashMap<>();
        // 图文URL
@ -549,23 +549,23 @@ public class WeiXinEventProcess {
        articles.add(articleConsult);
        Map<String, String> articleBooking = new HashMap<>();
        // 图文URL
        String urlBooking = systemConf.getProperty("patient_booking_url");
        // 图文消息图片URL
        String picUrlBooking = systemConf.getProperty("patient_booking_pic_url");
        // URL设置服务器URL、AppId
        urlBooking = urlBooking.replace("{server}", wechat_base_url)
                .replace("{appId}", appId);
        //图片地址
        picUrlBooking = picUrlBooking.replace("{server}", serverUrl);
        articleBooking.put("Url", urlBooking);
        articleBooking.put("Title", "预约挂号功能使用说明");
        articleBooking.put("Description", "功能使用说明");
        articleBooking.put("PicUrl", picUrlBooking);
        articles.add(articleBooking);
//        Map<String, String> articleBooking = new HashMap<>();
//        // 图文URL
//        String urlBooking = systemConf.getProperty("patient_booking_url");
//        // 图文消息图片URL
//        String picUrlBooking = systemConf.getProperty("patient_booking_pic_url");
//        // URL设置服务器URL、AppId
//        urlBooking = urlBooking.replace("{server}", wechat_base_url)
//                .replace("{appId}", appId);
//        //图片地址
//        picUrlBooking = picUrlBooking.replace("{server}", serverUrl);
//
//        articleBooking.put("Url", urlBooking);
//        articleBooking.put("Title", "预约挂号功能使用说明");
//        articleBooking.put("Description", "功能使用说明");
//        articleBooking.put("PicUrl", picUrlBooking);
//
//        articles.add(articleBooking);
        Map<String, String> articleDevice = new HashMap<>();
        // 图文URL
@ -647,8 +647,8 @@ public class WeiXinEventProcess {
            //设置通用链接
            setUrlItems(articles, systemConf);
            //加入续签图文
            Map videoText = getNews("patient_sign_again_url", "patient_sign_again_pic_url", "家庭医生续签提醒", null);
            articles.add(videoText);
//            Map videoText = getNews("patient_sign_again_url", "patient_sign_again_pic_url", "家庭医生续签提醒", null);
//            articles.add(videoText);
            // 消息XML
            result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"), message.get("ToUserName"), articles);
        } else if (StringUtils.isNotEmpty(eventKey) && (eventKey.startsWith("hs_") ||
@ -681,8 +681,8 @@ public class WeiXinEventProcess {
            //设置通用链接
            setUrlItems(articles, systemConf);
            //加入续签图文
            Map videoText = getNews("patient_sign_again_url", "patient_sign_again_pic_url", "家庭医生续签提醒", null);
            articles.add(videoText);
//            Map videoText = getNews("patient_sign_again_url", "patient_sign_again_pic_url", "家庭医生续签提醒", null);
//            articles.add(videoText);
            // 消息XML
            result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"), message.get("ToUserName"), articles);
        } else if (StringUtils.isNotEmpty(eventKey) && (eventKey.startsWith("tw_") ||
@ -715,8 +715,8 @@ public class WeiXinEventProcess {
            //设置通用链接
            setUrlItems(articles, systemConf);
            //加入续签图文
            Map videoText = getNews("patient_sign_again_url", "patient_sign_again_pic_url", "家庭医生续签提醒", null);
            articles.add(videoText);
//            Map videoText = getNews("patient_sign_again_url", "patient_sign_again_pic_url", "家庭医生续签提醒", null);
//            articles.add(videoText);
            // 消息XML
            result = WeiXinMessageReplyUtils.replyNewsMessage(message.get("FromUserName"), message.get("ToUserName"), articles);
        } else if (StringUtils.isNotEmpty(eventKey) && (("wechat_ehc").equals(eventKey)) ||

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

@ -21,7 +21,7 @@ spring:
     password: Kb6wKDQP1W4
server:
  server_url: http://www.xmtyw.cn/wlyy/
  server_url: http://srijk.yihu.com/wlyy/
#医生助手服务器地址及模板跳转链接(医生未读消息统计页)
doctorAssistant:
  api: http://www.xmtyw.cn/assistant/
@ -42,7 +42,7 @@ wechat:
  appId: wxe627ffaee2d05a40
  appSecret: 7c29f6b28be7e54b742883a47ff39767
  wechat_token: 27eb3bb24f149a7760cf1bb154b08040
  wechat_base_url: http%3a%2f%2fwww.xmtyw.cn%2fwlyy
  wechat_base_url: http%3a%2f%2fsrijk.yihu.com%2fwlyy
  accId: gh_733f975e0bed
  message:
   #咨询回复
@ -61,7 +61,7 @@ yihu:
  yihu_OpenPlatform_secret: 2JGL19AH3JS55MQY6ZOFJE1JZJ1OF23GWV67MCDQV74
fastDFS:
  fastdfs_file_url: http://www.xmtyw.cn/
  fastdfs_file_url: http://srijk.yihu.com/
images:
  path: /var/local/upload/images

+ 2 - 2
patient-co/patient-co-wlyy/src/main/resources/wechat/weixin_menu.txt

@ -11,12 +11,12 @@
		  {
			"type":"view",
			"name":"我的关注",
			"url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fyszd%2fhtml%2ffocused-doctor.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
			"url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fyszx%2fhtml%2ffocused-doctor.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
		  },
		  {
            "type":"view",
            "name":"查找医生",
            "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fyszd%2fhtml%2fselect-consult-doctor.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
            "url":"https://open.weixin.qq.com/connect/oauth2/authorize?appid=appId&redirect_uri=server_url%2fwx%2fhtml%2fyszx%2fhtml%2fselect-consult-doctor.html&response_type=code&scope=snsapi_base&state=STATE#wechat_redirect"
          }
	  ]