22a99b08aa0d81ff2c1021059830c9f6b17a344e.svn-base 4.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124
  1. package com.yihu.platform.apiservice;
  2. import com.coreframework.ioc.Ioc;
  3. import com.coreframework.util.AppConfig;
  4. import com.yihu.platform.service.IUserMappingService;
  5. import com.yihu.platform.utils.HttpUtil;
  6. import com.yihu.platform.utils.StringUtil;
  7. import net.sf.json.JSONObject;
  8. import java.util.HashMap;
  9. import java.util.Map;
  10. /**
  11. * 厦门i健康api
  12. */
  13. public class IHealthService {
  14. private static final String URL = AppConfig.getValue("HealthServiceURL");
  15. private static final IUserMappingService userMappingService = Ioc.get(IUserMappingService.class);
  16. private String token;
  17. public IHealthService() throws Exception {
  18. super();
  19. token = getToken();
  20. }
  21. /**
  22. * 获取token
  23. *
  24. * @return
  25. * @throws Exception
  26. */
  27. public String getToken() throws Exception {
  28. HttpUtil httpUtil = new HttpUtil(URL + "gc/accesstoken");
  29. Map map = new HashMap();
  30. map.put("appid", AppConfig.getValue("Token.appid"));
  31. map.put("appSecret", AppConfig.getValue("Token.appSecret"));
  32. String resp = httpUtil.post(map);
  33. if (StringUtil.isNotEmpty(resp) && resp.indexOf("status") >= 0) {
  34. JSONObject json = JSONObject.fromObject(resp);
  35. if (json.getInt("status") != 10000) throw new Exception("获取token失败:" + json);
  36. return json.getJSONObject("result").getString("accesstoken");
  37. } else {
  38. throw new Exception("获取token失败:" + resp);
  39. }
  40. }
  41. public String queryPatient(String userId) throws Exception {
  42. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/patient/user/patient");
  43. httpUtil.setHeader("userAgent", userMappingService.getUserAgent(userId));
  44. Map map = new HashMap();
  45. map.put("code", userId);
  46. map.put("accesstoken", token);
  47. String resp = httpUtil.get(map);
  48. return resp;
  49. }
  50. public String queryHospital(String hospitalId, String provinceId, String cityId, Integer page, Integer pageSize) throws Exception {
  51. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/hospital/");
  52. Map map = new HashMap();
  53. map.put("accesstoken", token);
  54. map.put("hospitalId", hospitalId);
  55. map.put("provinceId", provinceId);
  56. map.put("cityId", cityId);
  57. map.put("page", page);
  58. map.put("pageSize", pageSize);
  59. String resp = httpUtil.get(map);
  60. return resp;
  61. }
  62. public String queryDoctor(String hospitalId, String userId, Integer pageIndex, Integer pageSize) throws Exception {
  63. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/doctor/user/doctors");
  64. httpUtil.setHeader("userAgent", userMappingService.getUserAgent(userId));
  65. Map map = new HashMap();
  66. map.put("accesstoken", token);
  67. map.put("hospitalCode", hospitalId);
  68. map.put("page", pageIndex);
  69. map.put("pageSize", pageSize);
  70. String resp = httpUtil.get(map);
  71. return resp;
  72. }
  73. public String queryDoctorByUserId(String userId) throws Exception {
  74. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/doctor/user/doctor");
  75. Map map = new HashMap();
  76. map.put("accesstoken", token);
  77. map.put("code", userId);
  78. String resp = httpUtil.get(map);
  79. return resp;
  80. }
  81. public String push(String codes, String templateId, String teampolateJson, String url, String doctorUserId) throws Exception {
  82. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/doctor/message/sendWXTemplate");
  83. httpUtil.setHeader("userAgent", userMappingService.getUserAgent(doctorUserId));
  84. Map map = new HashMap();
  85. map.put("accesstoken", token);
  86. map.put("Codes", codes);
  87. map.put("templateId", templateId);
  88. map.put("teampolateJson", teampolateJson);
  89. map.put("url", url);
  90. String resp = httpUtil.post(map);
  91. return resp;
  92. }
  93. public String send(String mobile, String content, String doctorUserId) throws Exception {
  94. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/doctor/message/sendMobileMessage");
  95. httpUtil.setHeader("userAgent", userMappingService.getUserAgent(doctorUserId));
  96. Map map = new HashMap();
  97. map.put("accesstoken", token);
  98. map.put("mobiles", mobile);
  99. map.put("content", content);
  100. String resp = httpUtil.post(map);
  101. return resp;
  102. }
  103. public String getJsapiTicket() throws Exception {
  104. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/wx_jsapi_ticket");
  105. Map map = new HashMap();
  106. map.put("accesstoken", token);
  107. String resp = httpUtil.get(map);
  108. return resp;
  109. }
  110. }