手机发短信

package com.jeemis.framework.util;

import com.alibaba.fastjson.JSON;
import com.jeemis.framework.core.util.HttpUtil;
import com.jeemis.framework.core.util.JsonUtil;
import com.jeemis.framework.core.util.StringUtil;
import com.jeemis.framework.web.JeemisApplicationContext;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import java.util.HashMap;
import java.util.Map;
import java.util.concurrent.TimeUnit;

/**
 * 短信发送工具类
 * @author liuz
 * @version v1.0
 * <p>
 * Created on 2017年8月11日
 * <p>
 * Revision History: Date Reviser Description ---- -------
 * ----------------------------------------------------
 * <p>
 * Description:
 */
public class SMSUtil {
   
   
   private static final Logger logger = LoggerFactory.getLogger("SMSLOG");
   
   /**
    * 发送短信验证码
    * @param mobile 手机号
    * @param verfiyCode 验证码
    * @param message 消息
    * @return true 发送成功  false 发送失败
    * 
    * 接口描述
      请求方式:post
      描述  发送来过app的短信
       @param mobile 手机号码
       @param message 调用方传过来的消息
       @param verfiyCode 调用方传入的验证码  传入的code需加密加密方式参考/sm/sendAuditSM接口
       @return 返回json数据,
      成功:{"rspCode":1,"rspDesc":"success","result":null}  
      失败:{"rspCode":0,"rspDesc":"fail","result":null}
    */
   @SuppressWarnings("unchecked")
   public static boolean sendVerfiyCodeSms(String mobile, String verfiyCode, String message) {
      try {
         String url = "http://app.travelsky.com/csapp/sm/sendLGSM";//JeemisApplicationContext.getContext("SMSGatewayUrl");
         String key = "140018cs";//JeemisApplicationContext.getContext("SMSKeyCode");
         Map<String, String> params = new HashMap<String, String>();
         params.put("phone", mobile);
         params.put("message", message);
         String code = DESUtils.encryptDES(verfiyCode, key);
         params.put("code", code);
         //System.out.println(code);
         //System.out.println(DESUtils.decryptDES(code, key));
         String _sResponseBody = HttpUtil.sendPostRequest(url, params, null, null);
         Map<String, Object> resultMap = (Map<String, Object>)JsonUtil.parseToObject(_sResponseBody);
         if(resultMap != null && !resultMap.isEmpty()) {
            String status = String.valueOf(resultMap.get("status"));
            if("200".equals(status)){
               String result = String.valueOf(resultMap.get("result"));
               if(StringUtil.isNotBlank(result)) {
                  Map<String,Object> resMap = JSON.parseObject(result, Map.class);
                  if(resMap != null && !resMap.isEmpty() && resMap.get("rspCode") != null) {
                     if((Integer)resMap.get("rspCode") == 1) {
                        logger.error("{},{},{},{},{}",DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"), mobile, message, code, "succ");
                        return true;
                     }
                  }
               }
               
            }
         }
      } catch (Exception e) {
         e.printStackTrace();
      }
      logger.error("{},{},{},{},{}",DateFormatUtils.format(System.currentTimeMillis(), "yyyy-MM-dd HH:mm:ss"), mobile, message, "", "fail");
      
      return false;
   }

   public static void main(String[] args) {
      String verifyCode = VerifyCodeUtils.generateVerifyCode(6, "0123456789");

      //调用短信网关发送短信验证码
      boolean sendResult = SMSUtil.sendVerfiyCodeSms("15804019477", verifyCode, "您正在使用来过APP(登录),验证码("+verifyCode+"),请及时验证。(为了保证帐号安全,请勿向他人泄露。如非本人操作,请忽略。)");
   }
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值