WeixinService.java 2.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. package com.zskk.service;
  2. import java.io.UnsupportedEncodingException;
  3. import org.apache.commons.io.IOUtils;
  4. import org.apache.http.client.methods.CloseableHttpResponse;
  5. import org.apache.http.client.methods.HttpGet;
  6. import org.apache.http.impl.client.CloseableHttpClient;
  7. import org.apache.http.impl.client.HttpClients;
  8. import org.apache.http.impl.conn.PoolingHttpClientConnectionManager;
  9. public class WeixinService {
  10. static {
  11. // PropKit.use("config.txt");
  12. // ServiceFactory.init();
  13. // DruidPlugin plugin = new DruidPlugin(PropKit.get("jdbcUrl"), PropKit.get("user"), PropKit.get("password").trim());
  14. // ActiveRecordPlugin arp = new ActiveRecordPlugin(plugin);
  15. // _MappingKit.mapping(arp);
  16. // plugin.start();
  17. // arp.start();
  18. }
  19. private static final PoolingHttpClientConnectionManager POOL_CM = new PoolingHttpClientConnectionManager();
  20. private static final String CAHR_CODE = "UTF-8";
  21. // 获取访问TOKEN
  22. private static final String WEIXIN_QRCODE = "http://47.104.6.21:8080/wx_patient/api/unifyGetWxQrcode?reportId=%s";
  23. /*
  24. * 获取用户信息
  25. */
  26. public void requestWeixinQrcode(String reportid) {
  27. String url = String.format(WEIXIN_QRCODE, reportid);
  28. String content = doGet(url);
  29. }
  30. private String doGet(String url) {
  31. StringBuilder apiLog = new StringBuilder();
  32. apiLog.append(url).append("\t").append("params:").append("");
  33. CloseableHttpClient client = HttpClients.custom().setConnectionManager(POOL_CM).build();
  34. String content = null; // 返回内容
  35. try {
  36. HttpGet get = new HttpGet(url);
  37. CloseableHttpResponse response = null;
  38. try {
  39. response = client.execute(get);
  40. int code = response.getStatusLine().getStatusCode();
  41. if (code == 200) {
  42. content = IOUtils.toString(response.getEntity().getContent(), CAHR_CODE);
  43. } else {
  44. content = "{\"40013\":" + code + "}";
  45. }
  46. } finally {
  47. if (response != null) {
  48. response.close();
  49. }
  50. }
  51. } catch (Exception e) {
  52. // LogUtil.netEaseError(e.getMessage(), e);
  53. content = "{\"40013\":1000}";
  54. }
  55. // 记录日志
  56. apiLog.append("\t").append("result:").append(content);
  57. // LogUtil.netEaseDebug(apiLog.toString());
  58. return content;
  59. }
  60. }