网站发送短信的工具类,验证码、通知消息等
来源:互联网 发布:c语言中使用thumb指令 编辑:程序博客网 时间:2024/04/28 13:07
import java.net.URLEncoder;
import java.util.Random;
import com.bcloud.msg.http.HttpSender;//还需要一个http.jar包
public class SmsUtil{
private static final String URL_SendSM = "http://ip/msg/HttpSendSM"; //应用地址+单独发送方法private static final String URL_BatchSendS = "http://ip/msg/HttpBatchSendS"; //应用地址+单独群发方法private static final String ACCOUNT = "******";//账号private static final String PSWD = "*******";//密码private static final String SIGNATURE = "【我的技术总结】";private static final String CONTENT_END = "退订回N";private boolean needstatus = true;//是否需要状态报告,需要true,不需要falseprivate String Phone,Content;private String Product = "";//产品IDprivate String Extno = "012";//扩展码private int Type = 1;//1,代表给一个手机号发短信,2,代表给多个人发短信public SmsUtil(String phone,int type){ super(); this.Phone = phone; this.Type = type;}public void setProduct(String product){ this.Product = product;}public void setExtno(String extno){ this.Extno = extno;}public String getProduct(){ return this.Product;}public String getExtno(){ return this.Extno;}public void setContent(String content){ this.Content = content;}public String getContent(){ return SIGNATURE+this.Content+CONTENT_END;}public void setNeedstatus(boolean flag){ this.needstatus = flag;}public Boolean getNeedstatus(){ return this.needstatus;}public String Send(){ String returnFlag = ""; if(Type == 1){ returnFlag +=Sendsms(); }else { returnFlag +=batchSendsms(); } return returnFlag;}//只给一个手机号码发送短信public String Sendsms(){ String returnString = ""; try { returnString = HttpSender.send(URL_SendSM, ACCOUNT, PSWD, Phone, SIGNATURE+Content+CONTENT_END, needstatus, Product, Extno);
// System.out.println(returnString);
return returnString;
//TODO 处理返回值,参见HTTP协议文档
} catch (Exception e) {
//TODO 处理异常
return returnString;
}
}//给多个号码发送短信,用“,”隔开public String batchSendsms(){ String returnString = ""; try { returnString = HttpSender.batchSend(URL_BatchSendS, ACCOUNT, PSWD, Phone, SIGNATURE+Content+CONTENT_END, needstatus, Product, Extno);
// System.out.println(returnString);
return returnString;
//TODO 处理返回值,参见HTTP协议文档
} catch (Exception e) {
//TODO 处理异常
return returnString;
}
}
//得到随机数
public String getRandNum(int charCount) {
String charValue = ""; for (int i = 0; i < charCount; i++) { char c = (char) (randomInt(0, 10) + '0'); charValue += String.valueOf(c); } return charValue;}public int randomInt(int from, int to) { Random r = new Random(); return from + r.nextInt(to - from);}
}
0 0
- 网站发送短信的工具类,验证码、通知消息等
- 验证码短信接口可以广泛应用在网站会员手机验证、APP应用手机验证、订单通知、物流提醒等触发类短信应用。
- 工具系类 1.1 生成并发送 短信验证码
- 阿里云短信验证码发送工具类
- 网站注册登录等短信验证码
- 网站注册登录等短信验证码
- 使用网易云通信发送验证码,通知类型短信
- 短信验证码通知
- 发送短信验证码
- 发送短信验证码
- 发送短信验证码
- 短信验证码发送
- 发送短信验证码
- 发送短信验证码
- Java使用阿里大于发送短信通知和短信验证码
- Java使用阿里大于发送短信通知和短信验证码
- 网易云信-网易验证码短信,网易通知类短信的使用
- 发送短信验证码按钮的实现
- WEB服务器:Apache、Tomcat、JBoss、WebLogic、Websphere、IIS的区别与关系
- jni semantic error
- Delphi对Excel的所有操作(二)
- QlikView 学习资料
- 小议HTML与XML的区别
- 网站发送短信的工具类,验证码、通知消息等
- python包的各种安装问题汇总
- ios学习路线—Objective-C(Protocol)
- Delphi对Excel的所有操作(一)
- session
- eclipse中文变乱码原因及解决办法
- swift单例的创建与使用
- linux kernel的中断子系统之(九):tasklet
- Android 下陀螺仪、加速度和磁场传感器数据定义