zoukankan      html  css  js  c++  java
  • 发送短信(1)

    //发送短信
        @Override
        public int sendSms(String mobile){
    
            int smsCode=0, ret=0;
            String temp;
            boolean result=false;
            Map<String, String> paramMap = new HashMap<>();
    
            //发送短信内容
            smsCode = 1000 + (int)(Math.random()*8999);
            temp = "验证码:"+smsCode+"。请不要把验证码泄露给其他人。如非本人操作,可不用理会";
            paramMap.put("msg", temp);
            paramMap.put("mobile", mobile);
    
            //获取短信配置
            List<AppSmsSet> appSmsSetList = getAppSmsSetAvail();
            if(appSmsSetList==null){
                return -1;
            }
    
            //发送短信
            for (int i=0; i<appSmsSetList.size(); i++){
                AppSmsSet appSmsSet = appSmsSetList.get(i);
                paramMap.put("url", appSmsSet.getUrl());
                paramMap.put("password", appSmsSet.getPassword());
                //
                if(appSmsSet.getSmsservicename().equals("九天企信")){
                    paramMap.put("cpid", appSmsSet.getCpid());
                    paramMap.put("channel", appSmsSet.getChannelid());
                    result = SmsUtil.sendSmsJTQX(paramMap);
                }else if (appSmsSet.getSmsservicename().equals("云通讯")){
                    paramMap.put("act", appSmsSet.getName());
                    result = SmsUtil.sendSmsYTX(paramMap);
                }else {
                    //未知接口
                    continue;
                }
                //
                if(result){
                    break;
                }
            }
            if(!result){
                return -1;
            }
    
            //保存记录
            AppMobileSmscode appMobileSmscode = getAppMobileSmscode(mobile);
            if(appMobileSmscode==null){
                appMobileSmscode = new AppMobileSmscode();
                appMobileSmscode.setMobile(mobile);
                appMobileSmscode.setSmsCode(smsCode);
                appMobileSmscode.setCreateTime(new Date());
                appMobileSmscode.setUpdateTime(new Date());
                ret = appMobileSmscodeMapper.insert(appMobileSmscode);
            }else {
                appMobileSmscode.setSmsCode(smsCode);
                appMobileSmscode.setUpdateTime(new Date());
                ret = appMobileSmscodeMapper.updateByPrimaryKey(appMobileSmscode);
            }
            if(ret<=0){
                return -1; //保存失败
            }
    
            return smsCode;
        }
    

      

  • 相关阅读:
    JavaScript操作符instanceof揭秘
    Linux打开txt文件乱码的解决方法
    Working copy locked run svn cleanup not work
    poj 2299 UltraQuickSort 归并排序求解逆序对
    poj 2312 Battle City 优先队列+bfs 或 记忆化广搜
    poj2352 stars 树状数组
    poj 2286 The Rotation Game 迭代加深
    hdu 1800 Flying to the Mars
    poj 3038 Children of the Candy Corn bfs dfs
    hdu 1983 Kaitou Kid The Phantom Thief (2) DFS + BFS
  • 原文地址:https://www.cnblogs.com/ipetergo/p/6744975.html
Copyright © 2011-2022 走看看