短信发送接口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框架中,本身提供了对邮件.短信的基础支持,那么只需要根据自己的情况实现对应的接 ...
随机推荐
- C++ 中的关于输出的设置于
▲setw(n)用法: 通俗地讲就是预设宽度 如 cout<<setw(5)<<255<<endl; 结果是: (空格)(空格)255 ▲setfill(char ...
- 还是 js 替代 vw vh 了
有个需求是要层叠两张图,就像你现在看到的:整个浏览器和html页面,内层图片要水平居中,等比例与源UI图适配不同设备 本来很简单的使用 vw vh了( 核心代码 top: 13 ...
- maven3常用命令、java项目搭建、web项目搭建
------------------------------maven3常用命令--------------------------- 1.常用命令 1)创建一个Project mvn archety ...
- HttpRequest中常见的四种ContentType
https://www.cnblogs.com/xiaozong/p/5732332.html
- HDU1166 敌兵布阵_线段树
敌兵布阵 Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/32768 K (Java/Others)Total Submis ...
- Bitwise Equations
Problem Description You are given two positive integers X and K. Return the K-th smallest positive i ...
- 003PHP文件处理——目录操作:rename scandir
<?php //目录操作:rename scandir /** * 修改目录名字: * rename('旧名字','新名字') 改变文件夹或者文件的名称 */ //var_dump(rename ...
- vue 子组件把数据传递给父组件
<div id="app"> <child v-on:drop='parent'></child> //这里v-on:drop="pa ...
- 为什么不建议将 font-size 设置为 12px 以下?如果一定要设置为 12px 以下要怎么做?
问题:为什么不建议将 font-size 设置为 12px 以下?如果一定要设置为 12px 以下要怎么做? 先看看把 font-size 设置为 12px 以下时的效果:(浏览器为 Chrome 5 ...
- python将字符转换为字典
参考文章Python 如何将字符串转为字典 注意: 使用json的时候一定要注意是loads而不是load 即:user_dict = json.loads(user_info) 注意: 用eval( ...