Jelajahi Sumber

短信接口改造

chenweida 7 tahun lalu
induk
melakukan
f0a458a9a3

+ 3 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/prenatalInspector/PrenatalInspectorPreCardService.java

@ -990,10 +990,10 @@ public class PrenatalInspectorPreCardService extends BaseService {
                }
            }
            if (!flag && StringUtils.isNotEmpty(mobile)) {
//                发送短信消息
                org.json.JSONObject resultJson = smsService.sendMsg(mobile, name + ":,您好!您的家庭医生" + doctor.getName() + "提醒你,您和您的宝宝需要进行产检啦~" +
//
                String responseMessage = smsService.sendMsg(mobile, name + ":,您好!您的家庭医生" + doctor.getName() + "提醒你,您和您的宝宝需要进行产检啦~" +
                        " 您可微信搜索公众号:厦门i健康,关注公众号预约产检时间/查看孕检计划及历史检查记录,更可及时获取产检提醒哟~");
                if (resultJson != null && resultJson.getInt("result") == 0) {
                if (!org.springframework.util.StringUtils.isEmpty(responseMessage)&& (net.sf.json.JSONObject.fromObject(responseMessage).getInt("Code")==10000))   {
                    flag = true;
                }
            }

+ 7 - 8
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/app/sign/PatientRemindService.java

@ -20,6 +20,7 @@ import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.wechat.util.WeiXinAccessTokenUtils;
import com.yihu.wlyy.wechat.util.WeiXinOpenIdUtils;
import org.apache.commons.lang3.StringUtils;
import org.apache.xpath.operations.Bool;
import org.json.JSONArray;
import org.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
@ -218,14 +219,12 @@ public class PatientRemindService extends BaseService {
            if (StringUtils.isNotEmpty(p.getMobile())) {
                isMobileExist = true;
                JSONObject result = smsService.sendMsg(p.getMobile(), doc.getName() + "医生提醒您:为完成家庭医生签约," +
                String responseMessage = smsService.sendMsg(p.getMobile(), doc.getName() + "医生提醒您:为完成家庭医生签约," +
                        "尽早为您提供家庭医生服务,请尽快到" + hos.getName() + "(地址:" + hos.getAddress() + ")缴费");
                if (result != null && result.getInt("result") == 0) {
                if (!org.springframework.util.StringUtils.isEmpty(responseMessage)&& (net.sf.json.JSONObject.fromObject(responseMessage).getInt("Code")==10000))   {
                    mFlag = true;
                }
                if (result != null) {
                    mDesc = result.getString("description");
                }
            }
            WechatTemplateConfig templateConfig = templateConfigDao.findByScene("template_expenses_remind","jftx");
@ -517,14 +516,14 @@ public class PatientRemindService extends BaseService {
        String msg = "尊敬的" + p.get("name").toString() + "," + doctor.getName() + "医生提醒您:" +
                "为更好地为您提供健康服务,请您关注并登录\"厦门i健康\"微信公众号,与医生进行互动。";
        JSONObject smsResult = smsService.sendMsg(p.get("mobile").toString(), msg);
        String responseMessage = smsService.sendMsg(p.get("mobile").toString(), msg);
        if (smsResult != null && smsResult.getInt("result") == 0) {
        if (!org.springframework.util.StringUtils.isEmpty(responseMessage)&& (net.sf.json.JSONObject.fromObject(responseMessage).getInt("Code")==10000))   {
            result.put("status", 200);
            result.put("msg", "提醒成功");
        } else {
            result.put("status", -1);
            result.put("msg", "对不起,短信提醒失败,失败原因:" + smsResult.getString("description"));
            result.put("msg", "对不起,短信提醒失败");
        }
        return result;

+ 31 - 30
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/common/SMSService.java

@ -12,6 +12,8 @@ import com.yihu.wlyy.service.BaseService;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import com.yihu.wlyy.util.SystemConf;
import com.yihu.wlyy.web.third.jkzl.ZBSmsService;
import net.sf.json.JSON;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.json.JSONObject;
@ -48,27 +50,30 @@ public class SMSService extends BaseService {
    private StringRedisTemplate redisTemplate;
    @Value("${pushMes.redis_prescription_title}")
    private String redisQueue;
    @Autowired
    private ZBSmsService zbSmsService;
    /**
     * 内网通过redis的队列发送
     *
     * @param mobile
     * @param ip
     * @param type
     * @return
     */
    public String sendToNeiWang(String mobile, String ip, int type){
    public String sendToNeiWang(String mobile, String ip, int type) {
        com.alibaba.fastjson.JSONObject json = new com.alibaba.fastjson.JSONObject();
        json.put("mobile",mobile);
        json.put("ip",ip);
        json.put("type",type);
        json.put("time",DateUtil.getStringDate());
        json.put("mobile", mobile);
        json.put("ip", ip);
        json.put("type", type);
        json.put("time", DateUtil.getStringDate());
        com.alibaba.fastjson.JSONObject mes = new com.alibaba.fastjson.JSONObject();
        mes.put("title", "sendSms");
        mes.put("value", json.toString());
        redisTemplate.opsForList().leftPush(redisQueue, mes.toString());
        return  "ok";
        return "ok";
    }
    /**
@ -188,20 +193,18 @@ public class SMSService extends BaseService {
        sms.setIp(ip);
        sms.setType(type);
        sms.setStatus(1);
        // 调用总部发送信息的接口
        String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(sms.getContent(), mobile), "GBK");
        JSONObject json = toJson(result);
        if (json == null) {
            // 发送失败
            throw new Exception("短信发送失败!");
        } else if (json.getInt("result") != 0) {
            return json.getString("description");
        } else {
            //发送成功,保存到数据库
        // 调用发送信息的接口
        String responseMessage = zbSmsService.sendMessage(mobile, sms.getContent());
        if (!StringUtils.isEmpty(responseMessage)&& (net.sf.json.JSONObject.fromObject(responseMessage).getInt("Code")==10000)) {
            // 发送成功
            smsDao.save(sms);
        } else {
            throw new Exception("短信发送失败!");
        }
        return "ok";
    }
    /**
     * 外部短信调用 发送短信验证码接口
     *
@ -233,20 +236,19 @@ public class SMSService extends BaseService {
        sms.setIp(ip);
        sms.setType(type);
        sms.setStatus(1);
        // 调用总部发送信息的接口
        String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(sms.getContent(), mobile), "GBK");
        JSONObject json = toJson(result);
        if (json == null) {
            // 发送失败
            throw new Exception("短信发送失败!");
        } else if (json.getInt("result") != 0) {
            return json.getString("description");
        } else {
            //发送成功,保存到数据库
        // 调用发送信息的接口
        // 调用发送信息的接口
        // 调用发送信息的接口
        String responseMessage = zbSmsService.sendMessage(mobile, sms.getContent());
        if (!StringUtils.isEmpty(responseMessage)&& (net.sf.json.JSONObject.fromObject(responseMessage).getInt("Code")==10000)) {
            // 发送成功
            smsDao.save(sms);
        } else {
            throw new Exception("短信发送失败!");
        }
        return "ok";
    }
    /**
     * 发送短信
     *
@ -254,11 +256,10 @@ public class SMSService extends BaseService {
     * @param content
     * @return
     */
    public  JSONObject sendMsg(String mobile, String content) {
    public String sendMsg(String mobile, String content) {
        // 调用总部发送信息的接口
        String result = HttpClientUtil.post(SystemConf.getInstance().getSmsUrl(), buildSmsParams(content, mobile), "GBK");
        JSONObject json = toJson(result);
        return json;
        // 调用发送信息的接口
      return  zbSmsService.sendMessage(mobile, content);
    }
    /**

+ 3 - 3
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/service/message/SendMessageService.java

@ -101,9 +101,9 @@ public class SendMessageService extends BaseService {
        String response = null;
        try {
            //发送短信消息,调用总部发送信息的接口
            JSONObject resultJson = smsService.sendMsg(mobile, msg);
            if (resultJson != null && resultJson.getInt("result") != 0) {
                response = "短信提醒失败!(原因:" + resultJson.getString("description") + ")";
            String responseMessage = smsService.sendMsg(mobile, msg);
            if (org.springframework.util.StringUtils.isEmpty(responseMessage)|| !(net.sf.json.JSONObject.fromObject(responseMessage).getInt("Code")==10000))   {
                response = "短信提醒失败!(原因:" + net.sf.json.JSONObject.fromObject(responseMessage).getString("Code") + ")";
            }
            response = "短信发送成功!";
        } catch (Exception e) {

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/task/RemindExpensesTask.java

@ -116,7 +116,7 @@ public class RemindExpensesTask implements Runnable {
            }
        }
        JSONObject result = smsService.sendMsg(sb.toString(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
        String result = smsService.sendMsg(sb.toString(), doctor.getName() + "医生提醒您:为完成家庭医生签约," +
                "尽早为您提供家庭医生服务,您可登录微信账号,进入签约管理,选择待缴费的签约记录进行缴费操作,如需线下缴费,请尽快到" + hospital.getName() + "(地址:" + hospital.getAddress() + ")缴费");
    }
}

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/task/RemindFocusWechatTask.java

@ -47,7 +47,7 @@ public class RemindFocusWechatTask implements Runnable {
                }
                String msg = "尊敬的" + p.get("name").toString() + "," + doctor.getName() + "医生提醒您:" +
                        "为更好地为您提供健康服务,请您关注并登录\"厦门i健康\"微信公众号,与医生进行互动。";
                JSONObject smsResult = SMSService.sendMsg(p.get("mobile").toString(), msg);
                String smsResult = SMSService.sendMsg(p.get("mobile").toString(), msg);
            } catch (Exception e) {
                e.printStackTrace();
            }

+ 1 - 1
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/gateway/controller/doctor/GcMessageController.java

@ -184,7 +184,7 @@ public class GcMessageController {
            String[] codeArr = mobiles.split(",");
            for (String mobile : codeArr) {
                try {
                    JSONObject result = smsService.sendMsg(mobile, content);
                    String result = smsService.sendMsg(mobile, content);
                    logger.info("send mobile message param : " + mobile + " ====> " + content);
                    logger.info("send mobile message return : " + result);
                    success++;

+ 71 - 0
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/jkzl/ZBSmsService.java

@ -0,0 +1,71 @@
package com.yihu.wlyy.web.third.jkzl;
import com.yihu.wlyy.util.DateUtil;
import com.yihu.wlyy.util.HttpClientUtil;
import net.sf.json.JSONObject;
import org.apache.http.NameValuePair;
import org.apache.http.message.BasicNameValuePair;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Service;
import java.util.ArrayList;
import java.util.Date;
import java.util.List;
/**
 * 福州总部的短信接口
 */
@Service
public class ZBSmsService {
    private Logger logger= LoggerFactory.getLogger(ZBSmsService.class);
    @Value("#{message.zongbu.client_id}")
    private String clientId;
    @Value("#{message.zongbu.resturl}")
    private String resturl;
    @Value("#{message.zongbu.api.sms.api}")
    private String smsAPI;
    @Value("#{message.zongbu.api.sms.handlerId}")
    private String smsHandlerId;
    @Autowired
    private HttpClientUtil httpClientUtil;
    /**
     * 发送短信
     * @return
     */
    public String sendMessage(String mobile,String content) {
        try{
            List<NameValuePair> params = new ArrayList<>();
            //拼凑参数
            JSONObject authInfo=new JSONObject();
            authInfo.put("ClientId",clientId);
            params.add(new BasicNameValuePair("AuthInfo",authInfo.toString()));
            params.add(new BasicNameValuePair("SequenceNo", DateUtil.dateToStr(new Date(),DateUtil.YYYYMMddHHmmssSSS)));
            params.add(new BasicNameValuePair("Api", smsAPI));
            JSONObject param=new JSONObject();
            param.put("mobile",mobile);
            param.put("content",content);
            param.put("handlerId",smsHandlerId);
            params.add(new BasicNameValuePair("Param", param.toString()));
            params.add(new BasicNameValuePair("ParamType", "0"));
            params.add(new BasicNameValuePair("OutType", "0"));
            String response = httpClientUtil.post(resturl, params, "UTF-8");
            Integer code= JSONObject.fromObject(response).getInt("Code");
            if(code!=10000){
                logger.error(response);
            }
            return response;
        }catch (Exception e){
            logger.error(e.getMessage());
        }
        return null;
    }
}

+ 18 - 16
patient-co/patient-co-wlyy/src/main/java/com/yihu/wlyy/web/third/zysoft/BookingController.java

@ -525,19 +525,19 @@ public class BookingController extends WeixinBaseController {
    public String testSMS(@ApiParam(name = "msg") @RequestParam(value = "msg", required = true) String msg)
    {
        String re = "";
        try {
            //发送短信消息,调用总部发送信息的接口
            JSONObject resultJson = smsService.sendMsg("13559207522", msg);
            if (resultJson != null && resultJson.getInt("result") != 0) {
                re = "短信提醒失败!(原因:" + resultJson.getString("description") + ")";
            }
            re = "短信发送成功!";
        }
        catch (Exception ex)
        {
            ex.printStackTrace();
            re = ex.getMessage();
        }
//        try {
//            //发送短信消息,调用总部发送信息的接口
//            JSONObject resultJson = smsService.sendMsg("13559207522", msg);
//            if (resultJson != null && resultJson.getInt("result") != 0) {
//                re = "短信提醒失败!(原因:" + resultJson.getString("description") + ")";
//            }
//            re = "短信发送成功!";
//        }
//        catch (Exception ex)
//        {
//            ex.printStackTrace();
//            re = ex.getMessage();
//        }
        return re;
    }
@ -592,9 +592,11 @@ public class BookingController extends WeixinBaseController {
                            .replace("br","\n");
                    //发送短信消息,调用总部发送信息的接口
                    JSONObject resultJson = smsService.sendMsg(patientPhone,remark);
                    if (resultJson != null && resultJson.getInt("result") != 0) {
                        des = "短信提醒失败!(原因:"+resultJson.getString("description")+")";
                    String resultJson = smsService.sendMsg(patientPhone,remark);
                    if (org.springframework.util.StringUtils.isEmpty(resultJson)||(net.sf.json.JSONObject.fromObject(resultJson).getInt("Code")==10000))   {
                        des = "短信提醒失败!)";
                    }
                    //保存短信记录
                    SMS sms = new SMS();

+ 10 - 0
patient-co/patient-co-wlyy/src/main/resources/application.yml

@ -94,3 +94,13 @@ interceptor:
putMesType:
  #推送到redis消息类型
  wechat: wechat
##福州健康之路总部的接口
message:
  zongbu:
    client_id:
    resturl: http://service.yihu.com:8080/WSGW/rest
    api:
      sms: ##短信接口
        api: MsgGW.Sms.send
        handlerId: 50778