package com.zskk.service; import org.apache.commons.io.IOUtils; import org.apache.http.client.methods.CloseableHttpResponse; import org.apache.http.client.methods.HttpGet; import org.apache.http.impl.client.CloseableHttpClient; import org.apache.http.impl.client.HttpClients; import org.apache.http.impl.conn.PoolingHttpClientConnectionManager; public class WeixinService { static { // PropKit.use("config.txt"); // ServiceFactory.init(); // DruidPlugin plugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim()); // ActiveRecordPlugin arp = new ActiveRecordPlugin(plugin); // _MappingKit.mapping(arp); // plugin.start(); // arp.start(); } private static final PoolingHttpClientConnectionManager POOL_CM = new PoolingHttpClientConnectionManager(); private static final String CAHR_CODE = "UTF-8"; // 获取访问TOKEN private static final String WEIXIN_QRCODE = "http://wechat.pacsonline.cn/wx_patient/api/unifyGetWxQrcode?reportId=%s"; /* * 获取用户信息 */ public void requestWeixinQrcode(String reportid) { String url = String.format(WEIXIN_QRCODE, reportid); String content = doGet(url); } private String doGet(String url) { StringBuilder apiLog = new StringBuilder(); apiLog.append(url).append("\t").append("params:").append(""); CloseableHttpClient client = HttpClients.custom().setConnectionManager(POOL_CM).build(); String content = null; // 返回内容 try { HttpGet get = new HttpGet(url); CloseableHttpResponse response = null; try { response = client.execute(get); int code = response.getStatusLine().getStatusCode(); if (code == 200) { content = IOUtils.toString(response.getEntity().getContent(), CAHR_CODE); } else { content = "{\"40013\":" + code + "}"; } } finally { if (response != null) { response.close(); } } } catch (Exception e) { // LogUtil.netEaseError(e.getMessage(), e); content = "{\"40013\":1000}"; } // 记录日志 apiLog.append("\t").append("result:").append(content); // LogUtil.netEaseDebug(apiLog.toString()); return content; } }