短信发送接口demo
public class SendValidCode {
// 短信发送的接口网关
private static String sendUrl = "****************************";
/**
* @Title: sendMessage
* @Description: 验证码短信发送
* @param userName:发送的用户名
* @param userPass:密码
* @param iphoneNum:电话号码
* @param signature:签名
* @return
*
* @return: String返回发送的结果
*/
public static String sendMessage(String userName, String userPass, String iphoneNum, String signature,
String validcode, String channel) {
// 发送结果
String msgContent = "验证码:" + validcode + ",请在60秒内完成验证。如非本人操作,请忽略。";// 发送消息的内容
String encrypStrPara1 = "userPass=" + userPass + "&DesNo=" + iphoneNum + "&Msg=" + msgContent + "【" + signature +"】&Channel=" + channel;
String encryptStr = DESEncrypt(encrypStrPara1, userPass);
List<NameValuePair> nvps = new ArrayList<NameValuePair>();
nvps.add(new BasicNameValuePair("userCode", userName));
nvps.add(new BasicNameValuePair("submitInfo", encryptStr));
String post = httpPost(sendUrl, nvps); // post请求
//String getparam = "userCode=" + userName +"&submitInfo=" + encryptStr;
//String result = httpGet(sendUrl, getparam); // get请求
// 返回结果
return post;
}
private static String DESEncrypt(String encryptStr, String key) {
String result = "";
try {
String encryptKey = SHA1(key).substring(0, 8).toUpperCase();
DESKeySpec desKeySpec = new DESKeySpec(encryptKey.getBytes());
SecretKeyFactory keyFactory = SecretKeyFactory.getInstance("DES");
SecretKey securekey = keyFactory.generateSecret(desKeySpec);
Cipher cipher = Cipher.getInstance("DES/CBC/PKCS5Padding");
IvParameterSpec ivp = new IvParameterSpec(encryptKey.getBytes());
cipher.init(Cipher.ENCRYPT_MODE, securekey, ivp);
byte[] encryptResult = cipher.doFinal(encryptStr.getBytes("GB2312"));
result = BinaryToHexString(encryptResult);
} catch (Exception e) {
System.out.println(e.getStackTrace());
System.out.println(e.getMessage());
}
return result;
}
private static String SHA1(String key) {
StringBuffer sb = new StringBuffer();
try {
MessageDigest md = MessageDigest.getInstance("SHA-1");
md.update(key.getBytes("GB2312"));
byte[] resultsha = md.digest();
for (byte b : resultsha) {
int i = b & 0xff;
if (i < 0xf) {
sb.append(0);
}
sb.append(Integer.toHexString(i));
}
} catch (Exception e) {
}
return sb.toString();
}
private static String BinaryToHexString(byte[] bytes) {
String hexStr = "0123456789ABCDEF";
String result = "";
String hex = "";
for (int i = 0; i < bytes.length; i++) {
// 字节高4位
hex = String.valueOf(hexStr.charAt((bytes[i] & 0xF0) >> 4));
// 字节低4位
hex += String.valueOf(hexStr.charAt(bytes[i] & 0x0F));
result += hex;
}
return result;
}
private static String httpPost(String url, List<NameValuePair> params) {
String result = "";
try {
HttpClient httpclient = new DefaultHttpClient();
HttpPost httpPost = new HttpPost(url);
httpPost.setEntity(new UrlEncodedFormEntity(params, "UTF-8"));
HttpResponse response = httpclient.execute(httpPost);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instreams = entity.getContent();
result = convertStreamToString(instreams);
}
} catch (Exception e) {
}
return result;
}
private static String httpGet(String url, String params) {
String result = "";
try {
HttpClient client = new DefaultHttpClient();
if (params != "") {
url = url + "?" + params;
}
HttpGet httpget = new HttpGet(url);
HttpResponse response = client.execute(httpget);
HttpEntity entity = response.getEntity();
if (entity != null) {
InputStream instreams = entity.getContent();
result = convertStreamToString(instreams);
}
} catch (Exception e) {
}
return result;
}
private static String convertStreamToString(InputStream is) {
BufferedReader reader = new BufferedReader(new InputStreamReader(is));
StringBuilder sb = new StringBuilder();
String line = null;
try {
while ((line = reader.readLine()) != null) {
sb.append(line + "\n");
}
} catch (IOException e) {
e.printStackTrace();
} finally {
try {
is.close();
} catch (IOException e) {
e.printStackTrace();
}
}
return sb.toString();
}
/*public static void main(String[] args) {
String result = SendValidCode.sendMessage("XMSTCF", "XMST123abc", "185****3547", "万兆天空", "123456","0");
System.out.println(result+">>>>>>>");
}*/
}
短信发送接口demo的更多相关文章
- 给安卓端调用的短信发送接口demo
package com.js.ai.modules.pointwall.action; import java.io.IOException; import java.util.HashMap; im ...
- thinkphp 5.0整合阿里大于验证码短信发送接口,含完整模型验证实例DEMO
为大家分享一个阿里大于短信发送接口: 首先创建一个发送模型(Send.php): <?php namespace app\index\model; use think\Validate; cla ...
- 短信发送接口被恶意访问的网络攻击事件(三)定位恶意IP的日志分析脚本
前言 承接前文<短信发送接口被恶意访问的网络攻击事件(二)肉搏战-阻止恶意请求>,文中有讲到一个定位非法IP的shell脚本,现在就来公布一下吧,并没有什么技术难度,只是当时花了些时间去写 ...
- 短信发送接口被恶意访问的网络攻击事件(四)完结篇--搭建WAF清理战场
前言 短信发送接口被恶意访问的网络攻击事件(一)紧张的遭遇战险胜 短信发送接口被恶意访问的网络攻击事件(二)肉搏战-阻止恶意请求 短信发送接口被恶意访问的网络攻击事件(三)定位恶意IP的日志分析脚本 ...
- python 简单爬虫获取气象数据发送气象定时报-预报预警信息及时推送及阿里云短信群发接口
!/usr/bin/python #encoding=utf-8 #Author:Ruiy #//////////////////////////////////////////////////// ...
- destoon 短信发送函数及短信接口修改
// $DT在common.inc.php中定义, $CACHE = cache_read('module.php'); $DT = $CACHE['dt']; 从缓存里读取网站配置信息. //$d ...
- C# 编写短信发送Window服务
我们做项目过程中,一般都会有发送短信的需求.最常见的就是户注册或者登录时发送短信验证码.不同类型的短信发送,我们都可以放到到一张短信表中,然后通过一个定时的作业去执行短信发送.而定时作业的执行,我们就 ...
- Abp 添加阿里云短信发送
ABP中有短信发送接口ISmsSender public interface ISmsSender { Task<string> SendAsync(string number, stri ...
- ABP框架中短信发送处理,包括阿里云短信和普通短信商的短信发送集成
在一般的系统中,往往也有短信模块的需求,如动态密码的登录,系统密码的找回,以及为了获取用户手机号码的短信确认等等,在ABP框架中,本身提供了对邮件.短信的基础支持,那么只需要根据自己的情况实现对应的接 ...
随机推荐
- Shell脚本之无限循环的两种方法
for #!/bin/bash ;i<;)) do let "j=j+1" echo "-------------j is $j ----------------- ...
- RabbitMQ入门_01_简介与安装
A. 资源与参考文档 官网:https://www.rabbitmq.com/ B. 学习目的 部门目前使用其他部门维护的 WebLogic 的 JMS 消息服务,缺乏足够的技术支持与运维支持.随着基 ...
- Java IO流-字节流
2017-11-05 17:48:17 Java中的IO流按数据类型分类分为两种,一是字节流,二是字符流.字符流的出现是为了简化文本数据的读入和写出操作. 如果操作的文件是文本文件,那么使用字符流会大 ...
- ElasticSearch安装和head插件安装
本文主要介绍elasticsearch5.0安装及head插件安装.确保系统已经安装好jdk1.8以上,操作系统CentOS6以上. 一.elasticsearch安装配置 1.官网下载源码包 下载不 ...
- Tornado的cookie过期问题
首先,web应用程序是使用HTTP协议进行数据传输,因为HTTP协议是无状态的,所以一旦提交数据完成后,客户端和服务器端的连接就会被关闭,再次进行数据的交换就得重新建立新的连接,那么,有个问题就是服务 ...
- @Query 注解实现查询(二十四)
为了节约时间使得各位看官看起来更加简单舒适,这一节把测试方法和测试代码放在一起. 测试方法: // ------------------------------------ 使用 @Query 注解 ...
- 201621123010《Java程序设计》第8周学习总结
1. 本周学习总结 以你喜欢的方式(思维导图或其他)归纳总结集合相关内容. 2. 书面作业 1. ArrayList代码分析 1.1 解释ArrayList的contains源代码 答:如图,可见co ...
- layui table 数据表格 隐藏列
现在国内的模板,也就layui一家独大了,其中的数据表格功能强大,但我不会用python或者django拼接json,输出发送给数据表格,那只好用笨办法,循环遍历吧. 数据表格中保留id列,是为了编辑 ...
- 第3课 进化后的const分析
C语言中的const const修饰的变量是只读的,本质还是变量 const修饰的局部变量在栈上分配空间(改变这个空间的值,这个变量就会改变) const修饰的全局变量在只读存储区分配空间 const ...
- 为什么要使用索引?-Innodb与Myisam引擎的区别与应用场景
Innodb与Myisam引擎的区别与应用场景 http://www.cnblogs.com/changna1314/p/6878900.html https://www.cnblogs.com/ho ...