Search in sources :

Example 1 with AppConfigExample

use of com.itrus.portal.db.AppConfigExample in project portal by ixinportal.

the class SMSServiceAsync method sendDR.

public Object sendDR(Map param, Integer flag) {
    if (QueueThread.ASYNC_ON == flag) {
        QueueThread.buildTask(sqlSession, this, param);
        return null;
    }
    String authHmac = (String) param.get("authHmac");
    String appid = (String) param.get("appid");
    String mphone = (String) param.get("mphone");
    String content = (String) param.get("content");
    HttpServletRequest request = (HttpServletRequest) param.get("request");
    Map<String, Object> result = new HashMap<String, Object>(2);
    // 验证参数是否完整
    if (StringUtils.isBlank(authHmac) || StringUtils.isBlank(appid) || StringUtils.isBlank(mphone) || StringUtils.isBlank(content)) {
        result.put("retCode", 0);
        result.put("retMsg", "提交的参数信息不完整");
        return result;
    }
    if (content.length() >= 70) {
        result.put("retCode", -1);
        result.put("retMsg", "短信内容过长");
        return result;
    }
    AppConfigExample ace = new AppConfigExample();
    AppConfigExample.Criteria acc = ace.createCriteria();
    acc.andAppIdEqualTo(appid);
    AppConfig ac = sqlSession.selectOne("com.itrus.portal.db.AppConfigMapper.selectByExample", ace);
    if (null == ac) {
        result.put("retCode", -3);
        result.put("retMsg", "没有此应用");
        return result;
    }
    Smsserver smsserver = sqlSession.selectOne("com.itrus.portal.db.SmsserverMapper.selectByPrimaryKey", ac.getSmsId());
    if (!content.startsWith(smsserver.getSmsSignature())) {
        // 判断短信签名
        result.put("retCode", -2);
        result.put("retMsg", "短信签名错误");
        return result;
    }
    if (ac.getAppStatus() == 1 || !ac.getAppip().contains(request.getRemoteAddr())) {
        LogUtil.syslog(sqlSession, "短信服务", appid + "没有此服务权限,访问ip:" + request.getRemoteAddr());
        result.put("retCode", -4);
        result.put("retMsg", "没有此服务权限");
        return result;
    }
    MessageLog ml;
    String send = "-8";
    // 验证hmac有效性
    try {
        String macVal = Base64.encode(HMACSHA1.getHmacSHA1(appid + content + mphone, ac.getSecretKey()), false);
        if (!authHmac.equals(macVal)) {
            result.put("retCode", -5);
            result.put("retMsg", "服务密钥错误");
            return result;
        }
        ml = new MessageLog();
        ml.setAppId(ac.getId());
        ml.setCellPhone(mphone);
        ml.setContent(content);
        ml.setSendTime(new Date());
        ml.setGate(smsserver.getSmsport());
        // 0亿美 1未来无线
        smsService = SpringContextHolder.getBean("smsClientService" + smsserver.getSmsport());
        // send = smsService.sendSms(smsserver,mphone,content);
        if ("0".equals(send)) {
            ml.setStatus(1);
            // ml.setErrorInfo();
            sqlSession.insert("com.itrus.portal.db.MessageLogMapper.insert", ml);
            result.put("retCode", 1000);
            return result;
        }
    } catch (NoSuchAlgorithmException e) {
        result.put("retCode", -6);
        result.put("retMsg", "Hmac验证错误");
        e.printStackTrace();
        return result;
    } catch (UnsupportedEncodingException e) {
        result.put("retCode", -6);
        result.put("retMsg", "Hmac验证错误");
        e.printStackTrace();
        return result;
    } catch (Exception e) {
        result.put("retCode", -7);
        result.put("retMsg", e.toString());
        e.printStackTrace();
        return result;
    }
    if (null != ml) {
        ml.setStatus(0);
        ml.setErrorInfo("短信接口发送错误,返回" + send);
        sqlSession.insert("com.itrus.portal.db.MessageLogMapper.insert", ml);
    }
    result.put("retCode", send);
    result.put("retMsg", "短信接口发送错误");
    return result;
}
Also used : AppConfig(com.itrus.portal.db.AppConfig) Smsserver(com.itrus.portal.db.Smsserver) HashMap(java.util.HashMap) UnsupportedEncodingException(java.io.UnsupportedEncodingException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Date(java.util.Date) InvocationTargetException(java.lang.reflect.InvocationTargetException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) UnsupportedEncodingException(java.io.UnsupportedEncodingException) HttpServletRequest(javax.servlet.http.HttpServletRequest) AppConfigExample(com.itrus.portal.db.AppConfigExample) MessageLog(com.itrus.portal.db.MessageLog) JSONObject(com.alibaba.fastjson.JSONObject)

Aggregations

JSONObject (com.alibaba.fastjson.JSONObject)1 AppConfig (com.itrus.portal.db.AppConfig)1 AppConfigExample (com.itrus.portal.db.AppConfigExample)1 MessageLog (com.itrus.portal.db.MessageLog)1 Smsserver (com.itrus.portal.db.Smsserver)1 UnsupportedEncodingException (java.io.UnsupportedEncodingException)1 InvocationTargetException (java.lang.reflect.InvocationTargetException)1 NoSuchAlgorithmException (java.security.NoSuchAlgorithmException)1 Date (java.util.Date)1 HashMap (java.util.HashMap)1 HttpServletRequest (javax.servlet.http.HttpServletRequest)1