WeixinService.java 2.1 KB

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