a2ee68317d628456f25d58d1584a18bfdbb28d1d.svn-base 2.9 KB

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