java at发短信_发送短信(1)
//發(fā)送短信
@Override
public int sendSms(String mobile){
int smsCode=0, ret=0;
String temp;
boolean result=false;
Map paramMap = new HashMap<>();
//發(fā)送短信內(nèi)容
smsCode = 1000 + (int)(Math.random()*8999);
temp = "驗(yàn)證碼:"+smsCode+"。請(qǐng)不要把驗(yàn)證碼泄露給其他人。如非本人操作,可不用理會(huì)";
paramMap.put("msg", temp);
paramMap.put("mobile", mobile);
//獲取短信配置
List appSmsSetList = getAppSmsSetAvail();
if(appSmsSetList==null){
return -1;
}
//發(fā)送短信
for (int i=0; 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;
}
總結(jié)
以上是生活随笔為你收集整理的java at发短信_发送短信(1)的全部?jī)?nèi)容,希望文章能夠幫你解決所遇到的問題。
- 上一篇: mysql insert 几分钟_我们可
- 下一篇: java属性监听_Java event事