package com.yihu.platform.apiservice; import com.coreframework.db.DB; import com.coreframework.db.Sql; import com.coreframework.ioc.Ioc; import com.coreframework.util.AppConfig; import com.yihu.platform.service.IUserMappingService; 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 = AppConfig.getValue("HealthServiceURL"); private static final IUserMappingService userMappingService = Ioc.get(IUserMappingService.class); private String token; public IHealthService() { super(); try { token = getToken(); } catch (Exception e) { e.printStackTrace(); } } /** * 获取token * * @return * @throws Exception */ public String getToken() throws Exception { HttpUtil httpUtil = new HttpUtil(URL + "gc/accesstoken"); Map map = new HashMap(); map.put("appid", AppConfig.getValue("Token.appid")); map.put("appSecret", AppConfig.getValue("Token.appSecret")); 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", userMappingService.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", userMappingService.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; } public String queryDoctorByUserId(String userId) throws Exception{ HttpUtil httpUtil = new HttpUtil(URL + "wlyygc/doctor/user/doctor"); Map map = new HashMap(); map.put("accesstoken", token); map.put("code", userId); String resp = httpUtil.get(map); return resp; } }