Browse Source

修改bug

chenyongxing 7 years ago
parent
commit
127150cae5

+ 202 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/controller/WeixinBaseController.java

@ -0,0 +1,202 @@
package com.yihu.mm.controller;
import com.yihu.mm.service.AccessTokenService;
import com.yihu.mm.util.CommonUtil;
import com.yihu.mm.util.HttpUtil;
import com.yihu.wlyy.entity.security.AccessToken;
import org.apache.commons.lang3.StringUtils;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import java.io.File;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.net.HttpURLConnection;
import java.net.URL;
import java.util.UUID;
public class WeixinBaseController extends BaseController {
	@Autowired
	private AccessTokenService accessTokenService;
	@Value("${wechat.appId}")
	private String appId;
	@Value("${wechat.appSecret}")
	private String appSecret;
	/**
	 * 获取微信的access_token
	 * 
	 * @return
	 */
	public String getAccessToken() {
		try {
			Iterable<AccessToken> accessTokens = accessTokenService.findAccessToken();
			if (accessTokens != null) {
				for (AccessToken accessToken : accessTokens) {
					if ((System.currentTimeMillis() - accessToken.getAdd_timestamp()) < (accessToken.getExpires_in() * 1000)) {
						return accessToken.getAccess_token();
					} else {
						accessTokenService.delAccessToken(accessToken);
						break;
					}
				}
			}
			String token_url = "https://api.weixin.qq.com/cgi-bin/token";
			String params = "grant_type=client_credential&appid=" + appId + "&secret=" + appSecret;
			String result = new HttpUtil().sendGet(token_url, params);
			JSONObject json = new JSONObject(result);
			if (json.has("access_token")) {
				String token = json.get("access_token").toString();
				String expires_in = json.get("expires_in").toString();
				AccessToken newaccessToken = new AccessToken();
				newaccessToken.setAccess_token(token);
				newaccessToken.setExpires_in(Long.parseLong(expires_in));
				accessTokenService.addAccessToken(newaccessToken);
				return token;
			} else {
				return null;
			}
		} catch (Exception e) {
			error(e);
			return null;
		}
	}
	/**
	 * 获取微信服务器语音
	 * 
	 * @return
	 */
	public String fetchWxVoices() {
		String voiceIds = "";
		try {
			String voices = request.getParameter("voices");
			if (StringUtils.isEmpty(voices)) {
				return voices;
			}
			String[] mediaIds = voices.split(",");
			for (String mediaId : mediaIds) {
				if (StringUtils.isEmpty(mediaId)) {
					continue;
				}
				String temp = saveVoiceToDisk(mediaId);
				if (StringUtils.isNotEmpty(temp)) {
					if (voiceIds.length() == 0) {
						voiceIds = temp;
					} else {
						voiceIds += "," + temp;
					}
				}
			}
		} catch (Exception e) {
			error(e);
		}
		return voiceIds;
	}
	/**
	 * 获取下载语音信息
	 * 
	 * @param mediaId 文件的id
	 * @throws Exception
	 */
	public String saveVoiceToDisk(String mediaId) throws Exception {
		// 文件保存的临时路径
		String tempPath = Class.class.getClass().getResource("/").getPath() + "temp/";
		// 重命名文件
		String fileBase = UUID.randomUUID().toString();
		String newFileName = fileBase+ ".amr";
		String mp3FileName  = fileBase + ".mp3";
		// 保存路径
		File uploadFile = new File(tempPath  + newFileName);
		InputStream inputStream = null;
		FileOutputStream fileOutputStream = null;
		try {
			if (!uploadFile.getParentFile().exists()) {
				uploadFile.getParentFile().mkdirs();
			}
			inputStream = getInputStream(mediaId);
			byte[] data = new byte[1024];
			int len = 0;
			fileOutputStream = new FileOutputStream(uploadFile);
			while ((len = inputStream.read(data)) != -1) {
				fileOutputStream.write(data, 0, len);
			}
			String amrFilePath = tempPath+newFileName;
			String Mp3FilePath = tempPath+mp3FileName;
			new CommonUtil().changeToMp3(amrFilePath,Mp3FilePath);
			// 返回保存路径
			return Mp3FilePath;
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			if (inputStream != null) {
				try {
					inputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			if (fileOutputStream != null) {
				try {
					fileOutputStream.close();
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
		}
		return null;
	}
	/**
	 * 下载多媒体文件(请注意,视频文件不支持下载,调用该接口需http协议)
	 *
	 * @return
	 */
	public InputStream getInputStream(String mediaId) {
		String accessToken = getAccessToken();
		InputStream is = null;
		String url = "http://file.api.weixin.qq.com/cgi-bin/media/get?access_token=" + accessToken + "&media_id=" + mediaId;
		try {
			URL urlGet = new URL(url);
			HttpURLConnection http = (HttpURLConnection) urlGet.openConnection();
			http.setRequestMethod("GET"); // 必须是get方式请求
			http.setRequestProperty("Content-Type", "application/x-www-form-urlencoded");
			http.setDoOutput(true);
			http.setDoInput(true);
			System.setProperty("sun.net.client.defaultConnectTimeout", "30000");// 连接超时30秒
			System.setProperty("sun.net.client.defaultReadTimeout", "30000"); // 读取超时30秒
			http.connect();
			// 获取文件转化为byte流
			is = http.getInputStream();
		} catch (Exception e) {
			e.printStackTrace();
		}
		return is;
	}
	/**
	 * 获取Open
	 * @param code
	 * @return
	 * @throws Exception
     */
	public String getOpenId(String code) throws Exception {
		String token_url = "https://api.weixin.qq.com/sns/oauth2/access_token";
		String params = "appid=" + appId+ "&secret=" + appSecret + "&code=" + code + "&grant_type=authorization_code";
		String result = new HttpUtil().sendGet(token_url, params);
		JSONObject json = new JSONObject(result);
		if (json.has("openid")) {
			return json.get("openid").toString();
		} else {
			return null;
		}
	}
}

+ 30 - 2
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/controller/medicine/PhysicalExaminationController.java

@ -2,7 +2,7 @@ package com.yihu.mm.controller.medicine;
import com.fasterxml.jackson.databind.JavaType;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.yihu.mm.controller.BaseController;
import com.yihu.mm.controller.WeixinBaseController;
import com.yihu.mm.entity.patient.ExamReport;
import com.yihu.mm.entity.patient.PatientExam;
import com.yihu.mm.entity.patient.Report;
@ -29,7 +29,7 @@ import java.util.Map;
@CrossOrigin
@RestController
@RequestMapping(value = "/medicine/physicalExamination")
public class PhysicalExaminationController extends BaseController {
public class PhysicalExaminationController extends WeixinBaseController {
    @Value("${examCode}")
    private String examCode;
@ -181,6 +181,34 @@ public class PhysicalExaminationController extends BaseController {
        return result;
    }
    @ApiOperation(value = "获取微信文件,传到越人接口(四象采集,声音文件需要从微信接口获取)")
    @RequestMapping(value = "/dealVoice", method = RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody
    public String getFileFromWechat( @ApiParam(name = "mediaId", value = "微信媒体id", required = true)@RequestParam(required = true, name = "type") String mediaId,
                                   @ApiParam(name = "type", value = "1.脸型  2.舌像  3.声音", required = true)@RequestParam(required = true, name = "type") String type,
                                   @ApiParam(name = "ct_id", value = "咨询编号", required = true)@RequestParam(required = true, name = "ct_id") String ct_id) throws Exception {
        String voice = saveVoiceToDisk(mediaId);
        String uploadAttachment = physicalExaminationService.uploadAttachment(voice);
        JSONObject uploadResult = new JSONObject(uploadAttachment);
        if(physicalExaminationService.getSuccess(uploadResult)){
            JSONObject recordset = uploadResult.getJSONObject("recordset");
            String at_id =  recordset.get("at_id").toString();
            String at_realname = (String) recordset.get("at_realname");
            String result = physicalExaminationService.dillphoneimgdata(at_id, at_realname, type, ct_id);
            return result;
        }
        return uploadAttachment;
    }
    @ApiOperation(value = "四诊资料采集")
    @RequestMapping(value = "/dillphoneimgdata", method = RequestMethod.POST,produces="application/json;charset=UTF-8")
    @ResponseBody

+ 17 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/repository/wlyy/patient/AccessTokenDao.java

@ -0,0 +1,17 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.mm.repository.wlyy.patient;
import com.yihu.wlyy.entity.security.AccessToken;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.PagingAndSortingRepository;
public interface AccessTokenDao extends PagingAndSortingRepository<AccessToken, Long> {
	
	@Query("select p from AccessToken p order by p.add_timestamp desc")
	Iterable<AccessToken> findAccessToken();
	
}

+ 52 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/service/AccessTokenService.java

@ -0,0 +1,52 @@
/*******************************************************************************
 * Copyright (c) 2005, 2014 springside.github.io
 *
 * Licensed under the Apache License, Version 2.0 (the "License");
 *******************************************************************************/
package com.yihu.mm.service;
import com.yihu.mm.repository.wlyy.patient.AccessTokenDao;
import com.yihu.wlyy.entity.security.AccessToken;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;
import org.springframework.transaction.annotation.Transactional;
import org.springside.modules.utils.Clock;
/**
 * 患者基本信息类.
 * 
 * @author George
 */
@Component
@Transactional(rollbackFor = Exception.class)
public class AccessTokenService {
	@Autowired
	private AccessTokenDao accessTokenDao;
	private Clock clock = Clock.DEFAULT;
	public Iterable<AccessToken> findAccessToken() {
		return accessTokenDao.findAccessToken();
	}
	/**
	 * 添加access_token
	 * @param accessToken
	 */
	public void addAccessToken(AccessToken accessToken) {
		accessToken.setAdd_timestamp(System.currentTimeMillis());
		accessToken.setCzrq(clock.getCurrentDate());
		accessTokenDao.save(accessToken);
	}
	public void delAccessToken(AccessToken accessToken) {
		accessTokenDao.delete(accessToken);
	}
}

+ 1 - 1
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/service/ExamReportService.java

@ -69,7 +69,7 @@ public class ExamReportService {
            //首先通过patientCode和ctId查找是否存在报告
            examReport = findByPatientAndCtId(patientCode, ctId);
            if(examReport==null){
                //为空,调用接口存入数据库,再次获取
                //为空,调用接口存入数据库
                examReport = physicalExaminationService.saveReportDetail(patientCode, ctId);
                return examReport;
            }

+ 15 - 1
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/service/PhysicalExaminationService.java

@ -200,7 +200,7 @@ public class PhysicalExaminationService {
        return examReport;
    }
    //查找试卷
    //上传图片到越人服务器
    public String uploadAttachment(MultipartFile file) {
        MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
        String fileName = file.getOriginalFilename();
@ -225,4 +225,18 @@ public class PhysicalExaminationService {
        return "{\"status\":500,\"msg\":\"上传文件出错\"}";
    }
    public String uploadAttachment(String filePath) {
        MultiValueMap<String, Object> param = new LinkedMultiValueMap<>();
        File dest = new File(filePath);
        RestTemplate rest = new RestTemplate();
        FileSystemResource resource = new FileSystemResource(filePath);
        param.add("file", resource);
        String postStr = rest.postForObject(yuerenApi+"/uploadattachment" , param, String.class);
        if (dest.exists() && dest.isFile()) {
            dest.delete();
        }
        return postStr.replace("exception", "msg");
    }
}

+ 352 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/CommonUtil.java

@ -0,0 +1,352 @@
package com.yihu.mm.util;
import it.sauronsoftware.jave.*;
import org.apache.commons.lang3.StringUtils;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.io.*;
@Component
public class CommonUtil {
    @Value("${fastDFS.fastdfs_file_url}")
    private String fastdfs_file_url;
    @Value("${server.server_url}")
    private String server_url;
    /**
     * 获取图片全路径
     *
     * @return
     */
    public  String getPhoneUrl(String url) {
        if (StringUtils.isEmpty(url)) {
            return "";
        } else {
            if (url.indexOf("http") > -1) {
                return url;
            } else {
                return server_url+ url;
            }
        }
    }
    public  String getIdcardEncode(String idcard) {
        if (idcard != null) {
            if (idcard.length() == 18) {
                return idcard.substring(0, 9) + "*******" + idcard.substring(16, 18);
            } else if (idcard.length() == 15) {
                return idcard.substring(0, 8) + "***" + idcard.substring(11, 15);
            }
        }
        return idcard;
    }
    /**
     * 对象转数组
     *
     * @param obj
     * @return
     */
    public  byte[] toByteArray(Object obj) {
        byte[] bytes = null;
        ByteArrayOutputStream bos = new ByteArrayOutputStream();
        try {
            ObjectOutputStream oos = new ObjectOutputStream(bos);
            oos.writeObject(obj);
            oos.flush();
            bytes = bos.toByteArray();
            oos.close();
            bos.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        }
        return bytes;
    }
    /**
     * 数组转对象
     *
     * @param bytes
     * @return
     */
    public  Object toObject(byte[] bytes) {
        Object obj = null;
        try {
            ByteArrayInputStream bis = new ByteArrayInputStream(bytes);
            ObjectInputStream ois = new ObjectInputStream(bis);
            obj = ois.readObject();
            ois.close();
            bis.close();
        } catch (IOException ex) {
            ex.printStackTrace();
        } catch (ClassNotFoundException ex) {
            ex.printStackTrace();
        }
        return obj;
    }
    /**
     * 拷贝临时语音文件到存储目录
     *
     * @param voices
     * @return
     * @throws IOException
     */
/*
    public String copyTempVoice(String voices) throws  Exception {
        // 文件保存的临时路径
        String serverUrl = fastdfs_file_url;
        FastDFSUtil fastDFSUtil = new FastDFSUtil();
        String fileUrls = "";
        File f = new File(voices);
        if (f.exists()) {
            String fileName = f.getName();
            InputStream in = new FileInputStream(f);
            ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
            in.close();
            if (result != null) {
                fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",") + serverUrl
                        + result.get("groupName").toString().replaceAll("\"", "") + "/"
                        + result.get("remoteFileName").toString().replaceAll("\"", "");
                f.delete();
            }
        }
        return fileUrls;
    }
*/
    /**
     * double转字符串,在转int
     * double*100转int 有bug 34.3会会变成3429
     * @param d
     * @return
     */
    public static Integer doubleToInt(Double d){
        if(d==null){
            return 0;
        }
        String currency = String.valueOf(d);
        int index = currency.indexOf(".");
        int length = currency.length();
        Integer amLong = 0;
        if(index == -1){
            amLong = Integer.valueOf(currency+"00");
        }else if(length - index >= 3){
            amLong = Integer.valueOf((currency.substring(0, index+3)).replace(".", ""));
            if(length-index>3){
                if(Integer.valueOf(currency.substring(index+3,index+4))>=5){
                    amLong++;
                }
            }
        }else if(length - index == 2){
            amLong = Integer.valueOf((currency.substring(0, index+2)).replace(".", "")+0);
        }else{
            amLong = Integer.valueOf((currency.substring(0, index+1)).replace(".", "")+"00");
        }
        return amLong;
    }
    /**
     * 校验健康指标是否正常
     *
     * @param curValue    当前值
     * @param standardMax 最大标准值
     * @param standardMin 最小标准值
     * @return 0正常,1高,-1低
     */
    public  double checkHealthIndex(double curValue, double standardMax, double standardMin) {
        if (curValue <= 0) {
            return 0;
        }
        if (standardMax > 0 && curValue > standardMax) {
            return curValue;
        }
        // 低于标准值,暂不推
        // if (standardMin > 0 && curValue < standardMin) {
        // return -curValue;
        // }
        return 0;
    }
    /**
     * 上传文件到FastDFS
     *
     * @param files 临时文件
     * @return
     * @throws Exception
     */
    /*public  String copyTempImage(String files) throws Exception {
        // 文件保存的临时路径
        String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
        String serverUrl = fastdfs_file_url;
        String[] fileArray = files.split(",");
        FastDFSUtil fastDFSUtil = new FastDFSUtil();
        String fileUrls = "";
        for (String file : fileArray) {
            File f = new File(tempPath + file);
            File fs = new File(tempPath + file + "_small");
            if (f.exists()) {
                String fileName = f.getName();
                InputStream in = new FileInputStream(f);
                ObjectNode result = fastDFSUtil.upload(in, fileName.substring(fileName.lastIndexOf(".") + 1), "");
                in.close();
                if (result != null) {
                    fileUrls += (StringUtils.isEmpty(fileUrls) ? "" : ",") + serverUrl
                            + result.get("groupName").toString().replaceAll("\"", "") + "/"
                            + result.get("remoteFileName").toString().replaceAll("\"", "");
                    f.delete();
                    if (fs.exists()) {
                        fs.delete();
                    }
                }
            }
        }
        return fileUrls;
    }*/
    public  void changeToMp3(String sourcePath, String targetPath) {
        File source = new File(sourcePath);
        File target = new File(targetPath);
        AudioAttributes audio = new AudioAttributes();
        Encoder encoder = new Encoder();
        audio.setCodec("libmp3lame");
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("mp3");
        attrs.setAudioAttributes(audio);
        try {
            encoder.encode(source, target, attrs);
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InputFormatException e) {
            e.printStackTrace();
        } catch (EncoderException e) {
            e.printStackTrace();
        }
    }
    public  long getVideoTimeAndImg(String sourcePath,String targetPath) throws  Exception{
        File source = new File(sourcePath);
        Encoder encoder = new Encoder();
        MultimediaInfo m = encoder.getInfo(source);
        long ms = m.getDuration();
        if(ms<1000)return ms;
        File target = new File(targetPath);//转图片
        VideoAttributes video = new VideoAttributes();
        video.setCodec("png");//转图片
        video.setSize(new VideoSize(600, 500));
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("image2");//转图片
        attrs.setOffset(0.01f);//设置偏移位置,即开始转码位置(3秒)
        attrs.setDuration(0.01f);//设置转码持续时间(1秒)
        attrs.setVideoAttributes(video);
        encoder.encode(source, target, attrs);
        return m.getDuration();
    }
    public  void changeToMp4(String sourcePath, String targetPath) {
        File source = new File(sourcePath);
        File target = new File(targetPath);
        AudioAttributes audio = new AudioAttributes();
        //audio.setCodec("aac");
        audio.setCodec("libvorbis");
       // audio.setBitRate(new Integer(64000));
        //audio.setChannels(new Integer(1));
       // audio.setSamplingRate(new Integer(22050));
        VideoAttributes video = new VideoAttributes();
        //video.setCodec("libxvid");// 转MP4
        video.setCodec("libtheora");//
       // video.setBitRate(new Integer(240000));// 180kb/s比特率
       // video.setFrameRate(new Integer(28));// 1f/s帧频,1是目前测试比较清楚的,越大越模糊
        EncodingAttributes attrs = new EncodingAttributes();
        attrs.setFormat("ogg");// 转MP4
        attrs.setAudioAttributes(audio);
        attrs.setVideoAttributes(video);
        Encoder encoder = new Encoder();
        long beginTime = System.currentTimeMillis();
        try {
            // 获取时长
            MultimediaInfo m = encoder.getInfo(source);
            System.out.println(m.getDuration());
            System.out.println("获取时长花费时间是:" + (System.currentTimeMillis() - beginTime));
            beginTime = System.currentTimeMillis();
            encoder.encode(source, target, attrs);
            System.out.println("视频转码花费时间是:" + (System.currentTimeMillis() - beginTime));
        } catch (IllegalArgumentException e) {
            e.printStackTrace();
        } catch (InputFormatException e) {
            e.printStackTrace();
        } catch (EncoderException e) {
            e.printStackTrace();
        }
    }
    public static void main(String args[]) throws  Exception{
        System.out.print("中文".length());
        System.out.print("中文".substring(0,30));
    }
    public  String getSubString(String content,int min,int max){
        if(StringUtils.isBlank(content)){
            return "";
        }else if(content.length()<=max){
            return content;
        }else{
            return content.substring(min,max);
        }
    }
    /*public  String  saveVoiceToDisk(InputStream inputStream,String newFileName) throws Exception {
        // 文件保存的临时路径
        String tempPath = SystemConf.getInstance().getTempPath() + File.separator;
        // 拼接年月日路径
        String datePath = DateUtil.getStringDate("yyyy") + File.separator + DateUtil.getStringDate("MM") + File.separator + DateUtil.getStringDate("dd") + File.separator;
        // 保存路径
        File uploadFile = new File(tempPath + datePath + newFileName);
        FileOutputStream fileOutputStream = null;
        try {
            if (!uploadFile.getParentFile().exists()) {
                uploadFile.getParentFile().mkdirs();
            }
            byte[] data = new byte[1024];
            int len = 0;
            fileOutputStream = new FileOutputStream(uploadFile);
            while ((len = inputStream.read(data)) != -1) {
                fileOutputStream.write(data, 0, len);
            }
            // 返回保存路径
            return tempPath+datePath + newFileName;
        } catch (IOException e) {
            e.printStackTrace();
        } finally {
            if (inputStream != null) {
                try {
                    inputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            if (fileOutputStream != null) {
                try {
                    fileOutputStream.close();
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
        }
        return null;
    }*/
}

+ 173 - 0
patient-co-customization/patient-co-modern-medicine/src/main/java/com/yihu/mm/util/HttpUtil.java

@ -0,0 +1,173 @@
package com.yihu.mm.util;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.stereotype.Component;
import java.io.*;
import java.net.HttpURLConnection;
import java.net.URL;
import java.net.URLConnection;
/*
 * MD5 算法
 */
@Component
public class HttpUtil {
	private static final Logger logger = LoggerFactory.getLogger(HttpUtil.class);
	/**
	 * 向指定URL发送GET方法的请求
	 *
	 * @param url
	 *            发送请求的URL
	 * @param param
	 *            请求参数,请求参数应该是 name1=value1&name2=value2 的形式。
	 * @return URL 所代表远程资源的响应结果
	 */
	public  String sendGet(String url, String param) {
		String result = "";
		BufferedReader in = null;
		try {
			String urlNameString = url + "?" + param;
			URL realUrl = new URL(urlNameString);
			// 打开和URL之间的连接
			URLConnection connection = realUrl.openConnection();
			// 设置通用的请求属性
			connection.setRequestProperty("accept", "*/*");
			connection.setRequestProperty("connection", "Keep-Alive");
			connection.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			// 建立实际的连接
			connection.connect();
			// 定义 BufferedReader输入流来读取URL的响应
			in = new BufferedReader(new InputStreamReader(connection.getInputStream()));
			String line;
			while ((line = in.readLine()) != null) {
				result += line;
			}
		} catch (Exception e) {
			e.printStackTrace();
		} finally {
			try {
				if (in != null) {
					in.close();
				}
			} catch (Exception e2) {
				e2.printStackTrace();
			}
		}
		return result;
	}
	/**
	 * 向指定 URL 发送POST方法的请求
	 *
	 * @param url
	 *            发送请求的 URL带上参数
	 * @param param
	 *            POST参数。
	 * @return 所代表远程资源的响应结果
	 */
	public  String sendPost(String url, String param) {
		StringBuffer buffer = new StringBuffer();
		PrintWriter out = null;
		BufferedReader in = null;
		HttpURLConnection conn = null;
		try {
			URL realUrl = new URL(url);
			// 打开和URL之间的连接
			conn = (HttpURLConnection) realUrl.openConnection();
			conn.setRequestMethod("POST");
			conn.setConnectTimeout(5000);
			conn.setDoOutput(true);
			conn.setDoInput(true);
			conn.setUseCaches(false);
			conn.setRequestProperty("Content-Type", "application/text");
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream(), "UTF-8");
			osw.write(param.toString());
			osw.flush();
			// 读取返回内容
			BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), "UTF-8"));
			String temp;
			while ((temp = br.readLine()) != null) {
				buffer.append(temp);
				buffer.append("\n");
			}
		} catch (Exception e) {
			logger.error("push message error:", e);
		} finally {
			try {
				if (out != null) {
					out.close();
				}
				if (in != null) {
					in.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
		return buffer.toString();
	}
	/**
	 * 向指定 URL 发送POST方法的请求
	 *
	 * @param url 发送请求的 URL带上参数
	 * @param param POST参数。
	 * @param charset 编码格式
	 * @return 所代表远程资源的响应结果
	 */
	public  String sendPost(String url, String param, String charset) {
		StringBuffer buffer = new StringBuffer();
		PrintWriter out = null;
		BufferedReader in = null;
		HttpURLConnection conn = null;
		try {
			URL realUrl = new URL(url);
			// 打开和URL之间的连接
			conn = (HttpURLConnection) realUrl.openConnection();
			conn.setRequestMethod("POST");
			conn.setDoOutput(true);
			conn.setDoInput(true);
			conn.setUseCaches(false);
			conn.setRequestProperty("Content-Type", "application/text");
			conn.setRequestProperty("accept", "*/*");
			conn.setRequestProperty("connection", "Keep-Alive");
			conn.setRequestProperty("user-agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.1;SV1)");
			OutputStreamWriter osw = new OutputStreamWriter(conn.getOutputStream(), charset);
			osw.write(param.toString());
			osw.flush();
			// 读取返回内容
			BufferedReader br = new BufferedReader(new InputStreamReader(conn.getInputStream(), charset));
			String temp;
			while ((temp = br.readLine()) != null) {
				buffer.append(temp);
				buffer.append("\n");
			}
		} catch (Exception e) {
			logger.error("push message error:", e);
		} finally {
			try {
				if (out != null) {
					out.close();
				}
				if (in != null) {
					in.close();
				}
			} catch (IOException ex) {
				ex.printStackTrace();
			}
		}
		return buffer.toString();
	}
}

+ 19 - 0
patient-co-customization/patient-co-modern-medicine/src/main/resources/application.yml

@ -80,6 +80,17 @@ spring:
        password: 123456
wechat:
  appId: wx1f129f7b51701428
  appSecret: 988f005d8309ed1795939e0f042431fb
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
server:
  server_url: http://ehr.yihu.com/wlyy/
---
##正式的配置
spring:
@ -104,3 +115,11 @@ spring:
server:
  server_url: http://weixin.xmtyw.cn/wlyy-dev/
fastDFS:
  fastdfs_file_url: http://172.19.103.54:80/
wechat:
  appId: wxd03f859efdf0873d
  appSecret: 2935b54b53a957d9516c920a544f2537