Search in sources :

Example 1 with SmsLog

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

the class SmsSendService method sendSmsByEmay.

/**
 * 调用亿美短信接口发送短信
 *
 * @param smsGate
 * @param mobile
 * @param content
 * @param smsType
 * @param projectId
 * @return
 */
public boolean sendSmsByEmay(SmsGate smsGate, String mobile, String content, String smsType, Long projectId, String userSn, String keySn) {
    boolean ret = false;
    // SysUser sysUser = sqlSession.selectOne(
    // "com.itrus.portal.db.SysUserMapper.selectByPrimaryKey",
    // sysUserId);
    // if (null == sysUser) {
    // logger.error("发送失败 ,id为【" + sysUserId + "】的用户不存在");
    // return false;
    // }
    SmsLog smsLog = new SmsLog();
    smsLog.setSmsType(smsType);
    smsLog.setmPhoneNum(mobile);
    smsLog.setCreateTime(new Date());
    smsLog.setProjectId(projectId);
    // smsLog.setSysUser(sysUserId);
    // 添加用户日志
    UserLog userLog = new UserLog();
    userLog.setHostId("未知");
    String smsTypeStr = smsType;
    if ("SHJJ".equals(smsType)) {
        smsTypeStr = "审核拒绝";
    }
    userLog.setType(smsTypeStr);
    userLog.setSn(userSn);
    userLog.setProject(projectId);
    String info = "";
    int sendValue = -1;
    try {
        logger.debug(mobile + " " + content);
        // 调用亿美短信接口发送短信
        java.net.URL endpointURL = new java.net.URL(smsGate.getEmayAddress());
        javax.xml.rpc.Service service = null;
        SDKServiceBindingStub client = new SDKServiceBindingStub(endpointURL, service);
        if (0 != regValue) {
        } else {
            sendValue = client.sendSMS(smsGate.getEmaySerialnum(), smsGate.getEmayPass(), "", new String[] { mobile }, content, "", "utf-8", 5, 0);
            smsLog.setGateType(smsGate.getGateType());
            if (0 == sendValue) {
                logger.debug("发送成功");
                smsLog.setSendStatus(SMS_STATUS_SUCCESS);
                ret = true;
                info = "手机号:" + mobile + ",发送成功\n订单号:" + keySn;
            } else {
                info = "手机号:" + mobile + ",发送失败.返回码:" + sendValue + "\n订单号:" + keySn;
                smsLog.setSendStatus(SMS_STATUS_FAIL);
                smsLog.setCommentInfo("返回信息:" + sendValue);
                logger.error("发送失败 " + sendValue);
            }
        }
    } catch (IOException e) {
        info = "手机号:" + mobile + ",发送失败.返回码:" + sendValue + "\n订单号:" + keySn;
        smsLog.setSendStatus(SMS_STATUS_FAIL);
        smsLog.setCommentInfo("出现未知异常,请查看日志");
        logger.error("发送失败 " + e.toString());
    }
    if (!"sendSms4three".equals(smsType)) {
        sqlSession.insert("com.itrus.portal.db.SmsLogMapper.insert", smsLog);
        userLog.setInfo(info);
        LogUtil.userlog(sqlSession, userLog);
    }
    return ret;
}
Also used : UserLog(com.itrus.portal.db.UserLog) IOException(java.io.IOException) Date(java.util.Date) SDKServiceBindingStub(cn.b2m.eucp.sdkhttp.SDKServiceBindingStub) SmsLog(com.itrus.portal.db.SmsLog)

Example 2 with SmsLog

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

the class SmsSendService method sendSms.

/**
 * 给单个手机发送短信(旧的发送短信接口)
 *
 * @param mobile
 * @param content
 * @param smsType
 * @param projectId
 * @param sysUserId
 * @return
 */
public boolean sendSms(SmsGate smsGate, String mobile, String content, String smsType, Long projectId, Long sysUserId, String keySn) {
    String bodyAsString;
    boolean ret = false;
    // SysUser sysUser = sqlSession.selectOne(
    // "com.itrus.portal.db.SysUserMapper.selectByPrimaryKey",
    // sysUserId);
    // if (null == sysUser) {
    // logger.error("发送失败 ,id为【" + sysUserId + "】的用户不存在");
    // return false;
    // }
    SmsLog smsLog = new SmsLog();
    smsLog.setSmsType(smsType);
    smsLog.setmPhoneNum(mobile);
    smsLog.setCreateTime(new Date());
    smsLog.setProjectId(projectId);
    // smsLog.setSysUser(sysUserId);
    // 添加用户日志
    UserLog userLog = new UserLog();
    userLog.setHostId("未知");
    userLog.setType(smsType);
    userLog.setProject(projectId);
    String info = "";
    try {
        logger.debug(mobile + " " + content);
        String md5Plaintext = mobile.substring(0, 8) + mobile.substring(mobile.length() - 10) + smsGate.getMd5Key();
        String md5Ciphertext = smsMD5Keyword(md5Plaintext);
        String sendContent = URLEncoder.encode(content, "GBK");
        StringBuilder url = new StringBuilder(smsGate.getGateAddress() + SMS_SENT_URL);
        url.append("?Username=").append(smsGate.getAccountName()).append("&Password=").append(smsGate.getAccountPass()).append("&Mobile=").append(mobile).append("&Content=").append(sendContent).append("&Keyword=").append(md5Ciphertext);
        smsLog.setGateType(smsGate.getGateType());
        HttpResponse response = client.execute(new HttpGet(url.toString()));
        bodyAsString = EntityUtils.toString(response.getEntity());
        if ("0".equals(bodyAsString)) {
            logger.debug("发送成功");
            smsLog.setSendStatus(SMS_STATUS_SUCCESS);
            ret = true;
            info = "手机号:" + mobile + ",发送成功";
        } else {
            smsLog.setSendStatus(SMS_STATUS_FAIL);
            smsLog.setCommentInfo("返回信息:" + bodyAsString);
            logger.error("发送失败 " + bodyAsString);
            info = "手机号:" + mobile + ",发送失败";
        }
    } catch (IOException e) {
        smsLog.setSendStatus(SMS_STATUS_FAIL);
        smsLog.setCommentInfo("出现未知异常,请查看日志");
        logger.error("发送失败 " + e.toString());
        info = "手机号:" + mobile + ",发送失败";
    }
    sqlSession.insert("com.itrus.portal.db.SmsLogMapper.insert", smsLog);
    userLog.setInfo(info);
    LogUtil.userlog(sqlSession, userLog);
    return ret;
}
Also used : HttpGet(org.apache.http.client.methods.HttpGet) HttpResponse(org.apache.http.HttpResponse) UserLog(com.itrus.portal.db.UserLog) IOException(java.io.IOException) SmsLog(com.itrus.portal.db.SmsLog) Date(java.util.Date)

Example 3 with SmsLog

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

the class SmsSendService method wlsendSms.

/**
 * 给单个手机发送短信(未来无线发送短信接口)
 *
 * @param mobile
 * @param content
 * @param smsType
 * @param projectId
 * @param sysUserId
 * @return
 */
public boolean wlsendSms(SmsGate smsGate, String mobile, String content, String smsType, Long projectId, Long sysUserId, String keySn) {
    String bodyAsString;
    boolean ret = false;
    SmsLog smsLog = new SmsLog();
    smsLog.setSmsType(smsType);
    smsLog.setmPhoneNum(mobile);
    smsLog.setCreateTime(new Date());
    smsLog.setProjectId(projectId);
    // smsLog.setSysUser(sysUserId);
    // 添加用户日志
    UserLog userLog = new UserLog();
    userLog.setHostId("未知");
    userLog.setType(smsType);
    userLog.setProject(projectId);
    String info = "";
    try {
        logger.debug(mobile + " " + content);
        smsLog.setGateType(smsGate.getGateType());
        String str = smsClientService.sendSms(mobile, content, smsGate.getGateAddress(), smsGate.getAccountPass(), smsGate.getAccountName(), smsGate.getMd5Key());
        String[] s = str.split(":");
        bodyAsString = s[3].substring(0, s[3].length() - 2);
        if ("0".equals(bodyAsString)) {
            logger.debug("发送成功");
            smsLog.setSendStatus(SMS_STATUS_SUCCESS);
            ret = true;
            info = "手机号:" + mobile + ",发送成功";
        } else {
            smsLog.setSendStatus(SMS_STATUS_FAIL);
            smsLog.setCommentInfo("返回信息:" + bodyAsString);
            logger.error("发送失败 " + bodyAsString);
            info = "手机号:" + mobile + ",发送失败";
        }
    } catch (IOException e) {
        smsLog.setSendStatus(SMS_STATUS_FAIL);
        smsLog.setCommentInfo("出现未知异常,请查看日志");
        logger.error("发送失败 " + e.toString());
        info = "手机号:" + mobile + ",发送失败";
    }
    sqlSession.insert("com.itrus.portal.db.SmsLogMapper.insert", smsLog);
    userLog.setInfo(info);
    LogUtil.userlog(sqlSession, userLog);
    return ret;
}
Also used : UserLog(com.itrus.portal.db.UserLog) IOException(java.io.IOException) SmsLog(com.itrus.portal.db.SmsLog) Date(java.util.Date)

Aggregations

SmsLog (com.itrus.portal.db.SmsLog)3 UserLog (com.itrus.portal.db.UserLog)3 IOException (java.io.IOException)3 Date (java.util.Date)3 SDKServiceBindingStub (cn.b2m.eucp.sdkhttp.SDKServiceBindingStub)1 HttpResponse (org.apache.http.HttpResponse)1 HttpGet (org.apache.http.client.methods.HttpGet)1