b13e7fe5c333c6bd922a8202fbb14100a28feaf1.svn-base 4.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. * Created by jcl on 2017/9/12.
  10. */
  11. public class MessageApi {
  12. /**
  13. * 微信推送
  14. * @param msg
  15. * @return
  16. */
  17. public String push(InterfaceMessage msg) {
  18. try {
  19. JSONObject json = JSONObject.fromObject(msg.getParam());
  20. String userId = StringUtil.isEmpty(json.get("userId")) ? null : json.getString("userId");
  21. String handlerId = StringUtil.isEmpty(json.get("handlerId")) ? null : json.getString("handlerId");
  22. String content = StringUtil.isEmpty(json.get("content")) ? null : json.getString("content");
  23. String detailUrl = StringUtil.isEmpty(json.get("detailUrl")) ? null : json.getString("detailUrl");
  24. String doctorUserId = StringUtil.isEmpty(json.get("doctorUserId")) ? null : json.getString("doctorUserId");
  25. if (StringUtil.isEmpty(userId)) {
  26. return ApiUtil.getRespJSON(-10000, "userId不能为空").toString();
  27. }
  28. if (StringUtil.isEmpty(handlerId)) {
  29. return ApiUtil.getRespJSON(-10000, "handlerId不能为空").toString();
  30. }
  31. if (StringUtil.isEmpty(content)) {
  32. return ApiUtil.getRespJSON(-10000, "content不能为空").toString();
  33. }
  34. if (StringUtil.isEmpty(doctorUserId)) {
  35. return ApiUtil.getRespJSON(-10000, "doctorUserId不能为空").toString();
  36. }
  37. IHealthService api = new IHealthService();
  38. String resp = api.push(userId,handlerId,content,detailUrl,doctorUserId);
  39. JSONObject re = JSONObject.fromObject(resp);
  40. if (re.getInt("status") != 10000) {
  41. return ApiUtil.getRespJSON(-10000, "微信推送失败:" + re).toString();
  42. }
  43. JSONObject obj = ApiUtil.getRespJSON(10000, "成功");
  44. return obj.toString();
  45. } catch (JSONException e) {
  46. return ApiUtil.getRespJSON(-10000, "非标准json:[" + msg.getParam() + "]").toString();
  47. } catch (Exception e) {
  48. e.printStackTrace();
  49. return ApiUtil.getRespJSON(-14444, "加载异常!" + StringUtil.getException(e)).toString();
  50. }
  51. }
  52. /**
  53. * 短信发送
  54. * @param msg
  55. * @return
  56. */
  57. public String send(InterfaceMessage msg) {
  58. try {
  59. JSONObject json = JSONObject.fromObject(msg.getParam());
  60. String mobile = StringUtil.isEmpty(json.get("mobile")) ? null : json.getString("mobile");
  61. String content = StringUtil.isEmpty(json.get("content")) ? null : json.getString("content");
  62. String doctorUserId = StringUtil.isEmpty(json.get("doctorUserId")) ? null : json.getString("doctorUserId");
  63. if (StringUtil.isEmpty(mobile)) {
  64. return ApiUtil.getRespJSON(-10000, "mobile不能为空").toString();
  65. }
  66. if (StringUtil.isEmpty(content)) {
  67. return ApiUtil.getRespJSON(-10000, "content不能为空").toString();
  68. }
  69. if (StringUtil.isEmpty(doctorUserId)) {
  70. return ApiUtil.getRespJSON(-10000, "doctorUserId不能为空").toString();
  71. }
  72. IHealthService api = new IHealthService();
  73. String resp = api.send(mobile,content,doctorUserId);
  74. JSONObject re = JSONObject.fromObject(resp);
  75. if (re.getInt("status") != 10000) {
  76. return ApiUtil.getRespJSON(-10000, "短信失败:" + re).toString();
  77. }
  78. JSONObject obj = ApiUtil.getRespJSON(10000, "成功");
  79. return obj.toString();
  80. } catch (JSONException e) {
  81. return ApiUtil.getRespJSON(-10000, "非标准json:[" + msg.getParam() + "]").toString();
  82. } catch (Exception e) {
  83. e.printStackTrace();
  84. return ApiUtil.getRespJSON(-14444, "加载异常!" + StringUtil.getException(e)).toString();
  85. }
  86. }
  87. }