123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990 |
- package com.yihu.platform.api;
- import com.yihu.platform.apiservice.IHealthService;
- import com.yihu.platform.utils.ApiUtil;
- import com.yihu.platform.utils.StringUtil;
- import com.yihu.wsgw.api.InterfaceMessage;
- import net.sf.json.JSONException;
- import net.sf.json.JSONObject;
- /**
- * Created by jcl on 2017/9/12.
- */
- public class MessageApi {
- /**
- * 微信推送
- * @param msg
- * @return
- */
- public String push(InterfaceMessage msg) {
- try {
- JSONObject json = JSONObject.fromObject(msg.getParam());
- String userId = StringUtil.isEmpty(json.get("userId")) ? null : json.getString("userId");
- String handlerId = StringUtil.isEmpty(json.get("handlerId")) ? null : json.getString("handlerId");
- String content = StringUtil.isEmpty(json.get("content")) ? null : json.getString("content");
- String detailUrl = StringUtil.isEmpty(json.get("detailUrl")) ? null : json.getString("detailUrl");
- String doctorUserId = StringUtil.isEmpty(json.get("doctorUserId")) ? null : json.getString("doctorUserId");
- if (StringUtil.isEmpty(userId)) {
- return ApiUtil.getRespJSON(-10000, "userId不能为空").toString();
- }
- if (StringUtil.isEmpty(handlerId)) {
- return ApiUtil.getRespJSON(-10000, "handlerId不能为空").toString();
- }
- if (StringUtil.isEmpty(content)) {
- return ApiUtil.getRespJSON(-10000, "content不能为空").toString();
- }
- if (StringUtil.isEmpty(doctorUserId)) {
- return ApiUtil.getRespJSON(-10000, "doctorUserId不能为空").toString();
- }
- IHealthService api = new IHealthService();
- String resp = api.push(userId,handlerId,content,detailUrl,doctorUserId);
- JSONObject re = JSONObject.fromObject(resp);
- if (re.getInt("status") != 10000) {
- return ApiUtil.getRespJSON(-10000, "微信推送失败:" + re).toString();
- }
- JSONObject obj = ApiUtil.getRespJSON(10000, "成功");
- return obj.toString();
- } catch (JSONException e) {
- return ApiUtil.getRespJSON(-10000, "非标准json:[" + msg.getParam() + "]").toString();
- } catch (Exception e) {
- e.printStackTrace();
- return ApiUtil.getRespJSON(-14444, "加载异常!" + StringUtil.getException(e)).toString();
- }
- }
- /**
- * 短信发送
- * @param msg
- * @return
- */
- public String send(InterfaceMessage msg) {
- try {
- JSONObject json = JSONObject.fromObject(msg.getParam());
- String mobile = StringUtil.isEmpty(json.get("mobile")) ? null : json.getString("mobile");
- String content = StringUtil.isEmpty(json.get("content")) ? null : json.getString("content");
- String doctorUserId = StringUtil.isEmpty(json.get("doctorUserId")) ? null : json.getString("doctorUserId");
- if (StringUtil.isEmpty(mobile)) {
- return ApiUtil.getRespJSON(-10000, "mobile不能为空").toString();
- }
- if (StringUtil.isEmpty(content)) {
- return ApiUtil.getRespJSON(-10000, "content不能为空").toString();
- }
- if (StringUtil.isEmpty(doctorUserId)) {
- return ApiUtil.getRespJSON(-10000, "doctorUserId不能为空").toString();
- }
- IHealthService api = new IHealthService();
- String resp = api.send(mobile,content,doctorUserId);
- JSONObject re = JSONObject.fromObject(resp);
- if (re.getInt("status") != 10000) {
- return ApiUtil.getRespJSON(-10000, "短信失败:" + re).toString();
- }
- JSONObject obj = ApiUtil.getRespJSON(10000, "成功");
- return obj.toString();
- } catch (JSONException e) {
- return ApiUtil.getRespJSON(-10000, "非标准json:[" + msg.getParam() + "]").toString();
- } catch (Exception e) {
- e.printStackTrace();
- return ApiUtil.getRespJSON(-14444, "加载异常!" + StringUtil.getException(e)).toString();
- }
- }
- }
|