8584ee09fcf8d86697138c91df27e4d0fcdf2686.svn-base 2.9 KB

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