af38455692b67a25d021c2ff9312cf08bf8980eb.svn-base 3.1 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990
  1. package com.yihu.platform.api;
  2. import com.yihu.platform.apiservice.IHealthService;
  3. import com.yihu.platform.utils.ApiUtil;
  4. import com.yihu.platform.utils.StringUtil;
  5. import com.yihu.wsgw.api.InterfaceMessage;
  6. import net.sf.json.JSONException;
  7. import net.sf.json.JSONObject;
  8. /**
  9. * 用户接口
  10. *
  11. * @author wengsb----yihu.com
  12. * 2017年8月17日下午3:00:15
  13. */
  14. public class UserApi {
  15. /**
  16. * 通过用户id获取用户信息
  17. *
  18. * @param msg
  19. * @return
  20. */
  21. public String queryUserInfoByID(InterfaceMessage msg) {
  22. try {
  23. JSONObject json = JSONObject.fromObject(msg.getParam());
  24. String userId = StringUtil.isEmpty(json.get("userId")) ? null : json.getString("userId");
  25. if (StringUtil.isEmpty(userId)) {
  26. return ApiUtil.getRespJSON(-10000, "userId不能为空").toString();
  27. }
  28. IHealthService api = new IHealthService();
  29. String resp = api.queryPatient(userId);
  30. JSONObject re = JSONObject.fromObject(resp);
  31. if (re.getInt("status") != 10000) {
  32. return ApiUtil.getRespJSON(-10000, "查询用户信息失败:" + re).toString();
  33. }
  34. JSONObject userInfo = re.getJSONObject("result");
  35. JSONObject result = new JSONObject();
  36. if(userInfo.size()>0){
  37. result.put("UserName", userInfo.get("name"));
  38. result.put("PhotoUri", userInfo.get("photo"));
  39. result.put("CName", userInfo.get("name"));
  40. result.put("Sex", userInfo.get("sex"));
  41. result.put("BirthDate", userInfo.get("birthday"));
  42. result.put("IdNumber", userInfo.get("idcard"));
  43. result.put("MainPhone", userInfo.get("mobile"));
  44. result.put("Phone", userInfo.get("phone"));
  45. result.put("ProvinceID", userInfo.get("province"));
  46. result.put("ProvinceName", userInfo.get("provinceName"));
  47. result.put("CityID", userInfo.get("city"));
  48. result.put("CityName", userInfo.get("cityName"));
  49. result.put("AreaID", userInfo.get("town"));
  50. result.put("AreaName", userInfo.get("townName"));
  51. result.put("UserID", userId);
  52. }
  53. JSONObject obj = ApiUtil.getRespJSON(10000, "成功");
  54. obj.put("Result", result);
  55. return obj.toString();
  56. } catch (JSONException e) {
  57. return ApiUtil.getRespJSON(-10000, "非标准json:[" + msg.getParam() + "]").toString();
  58. } catch (Exception e) {
  59. e.printStackTrace();
  60. return ApiUtil.getRespJSON(-14444, "加载异常!" + StringUtil.getException(e)).toString();
  61. }
  62. }
  63. /**
  64. * 通过用户id获取用户信息
  65. *
  66. * @param msg
  67. * @return
  68. */
  69. public String getAccLoginInfo(InterfaceMessage msg) {
  70. return this.queryUserInfoByID(msg);
  71. }
  72. /**
  73. * 通过用户id获取用户信息
  74. *
  75. * @param msg
  76. * @return
  77. */
  78. public String queryLoginInfoByUserID(InterfaceMessage msg) {
  79. return this.queryUserInfoByID(msg);
  80. }
  81. }