1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586 |
- package com.yihu.platform.apiservice;
- import com.coreframework.db.DB;
- import com.coreframework.db.Sql;
- import com.yihu.platform.enums.MyDatabaseEnum;
- import com.yihu.platform.utils.HttpUtil;
- import net.sf.json.JSONObject;
- import java.util.HashMap;
- import java.util.Map;
- /**
- * 厦门i健康api
- */
- public class IHealthService {
- private static final String URL = "http://ehr.yihu.com/wlyy/";
- private String token;
- public IHealthService() {
- super();
- try {
- token = getToken();
- } catch (Exception e) {
- e.printStackTrace();
- }
- }
- /**
- * 获取token
- *
- * @return
- * @throws Exception
- */
- private String getToken() throws Exception {
- HttpUtil httpUtil = new HttpUtil(URL + "gc/accesstoken");
- Map map = new HashMap();
- map.put("appid", "915d0345-5b1d-11e6-8344-fa163e8aee56");
- map.put("appSecret", "915d0345-5b1d-11e6-8344-fa163e8aee52");
- String resp = httpUtil.post(map);
- JSONObject json = JSONObject.fromObject(resp);
- if (json.getInt("status") != 10000) throw new Exception("获取token失败:" + json);
- return json.getJSONObject("result").getString("accesstoken");
- }
- public String queryPatient(String userId) throws Exception {
- HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/patient/user/patient");
- httpUtil.setHeader("userAgent", getUserAgent(userId));
- Map map = new HashMap();
- map.put("code", userId);
- map.put("accesstoken", token);
- String resp = httpUtil.get(map);
- return resp;
- }
- public String queryHospital(String hospitalId, String provinceId, String cityId, Integer page, Integer pageSize) throws Exception {
- HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/hospital");
- Map map = new HashMap();
- map.put("accesstoken", token);
- map.put("hospitalId", hospitalId);
- map.put("provinceId", provinceId);
- map.put("cityId", cityId);
- map.put("page", page);
- map.put("pageSize", pageSize);
- String resp = httpUtil.get(map);
- return resp;
- }
- public String queryDoctor( String hospitalId,String userId, Integer pageIndex, Integer pageSize) throws Exception {
- HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/doctor/user/doctors");
- httpUtil.setHeader("userAgent", getUserAgent(userId));
- Map map = new HashMap();
- map.put("accesstoken", token);
- map.put("hospitalId", hospitalId);
- map.put("page", pageIndex);
- map.put("pageSize", pageSize);
- String resp = httpUtil.get(map);
- return resp;
- }
- private String getUserAgent(String userId) throws Exception {
- Sql sql = new Sql("select user_agent from user_mapping where status =1 and userId = ?");
- sql.addParamValue(userId);
- return DB.me().queryForString(MyDatabaseEnum.BasicServiceDB, sql);
- }
- }
|