39d0102992fcb1f46f1db30f11baa02e26de48f3.svn-base 3.1 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889909192
  1. package com.yihu.platform.apiservice;
  2. import com.coreframework.db.DB;
  3. import com.coreframework.db.Sql;
  4. import com.coreframework.ioc.Ioc;
  5. import com.coreframework.util.AppConfig;
  6. import com.yihu.platform.service.IUserMappingService;
  7. import com.yihu.platform.utils.HttpUtil;
  8. import net.sf.json.JSONObject;
  9. import java.util.HashMap;
  10. import java.util.Map;
  11. /**
  12. * 厦门i健康api
  13. */
  14. public class IHealthService {
  15. private static final String URL = AppConfig.getValue("HealthServiceURL");
  16. private static final IUserMappingService userMappingService = Ioc.get(IUserMappingService.class);
  17. private String token;
  18. public IHealthService() {
  19. super();
  20. try {
  21. token = getToken();
  22. } catch (Exception e) {
  23. e.printStackTrace();
  24. }
  25. }
  26. /**
  27. * 获取token
  28. *
  29. * @return
  30. * @throws Exception
  31. */
  32. public String getToken() throws Exception {
  33. HttpUtil httpUtil = new HttpUtil(URL + "gc/accesstoken");
  34. Map map = new HashMap();
  35. map.put("appid", AppConfig.getValue("Token.appid"));
  36. map.put("appSecret", AppConfig.getValue("Token.appSecret"));
  37. String resp = httpUtil.post(map);
  38. JSONObject json = JSONObject.fromObject(resp);
  39. if (json.getInt("status") != 10000) throw new Exception("获取token失败:" + json);
  40. return json.getJSONObject("result").getString("accesstoken");
  41. }
  42. public String queryPatient(String userId) throws Exception {
  43. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/patient/user/patient");
  44. httpUtil.setHeader("userAgent", userMappingService.getUserAgent(userId));
  45. Map map = new HashMap();
  46. map.put("code", userId);
  47. map.put("accesstoken", token);
  48. String resp = httpUtil.get(map);
  49. return resp;
  50. }
  51. public String queryHospital(String hospitalId, String provinceId, String cityId, Integer page, Integer pageSize) throws Exception {
  52. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/hospital/");
  53. Map map = new HashMap();
  54. map.put("accesstoken", token);
  55. map.put("hospitalId", hospitalId);
  56. map.put("provinceId", provinceId);
  57. map.put("cityId", cityId);
  58. map.put("page", page);
  59. map.put("pageSize", pageSize);
  60. String resp = httpUtil.get(map);
  61. return resp;
  62. }
  63. public String queryDoctor( String hospitalId,String userId, Integer pageIndex, Integer pageSize) throws Exception {
  64. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/doctor/user/doctors");
  65. httpUtil.setHeader("userAgent", userMappingService.getUserAgent(userId));
  66. Map map = new HashMap();
  67. map.put("accesstoken", token);
  68. map.put("hospitalId", hospitalId);
  69. map.put("page", pageIndex);
  70. map.put("pageSize", pageSize);
  71. String resp = httpUtil.get(map);
  72. return resp;
  73. }
  74. public String queryDoctorByUserId(String userId) throws Exception{
  75. HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/doctor/user/doctor");
  76. Map map = new HashMap();
  77. map.put("accesstoken", token);
  78. map.put("code", userId);
  79. String resp = httpUtil.get(map);
  80. return resp;
  81. }
  82. }