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的更多相关文章

  1. 给安卓端调用的短信发送接口demo

    package com.js.ai.modules.pointwall.action; import java.io.IOException; import java.util.HashMap; im ...

  2. thinkphp 5.0整合阿里大于验证码短信发送接口,含完整模型验证实例DEMO

    为大家分享一个阿里大于短信发送接口: 首先创建一个发送模型(Send.php): <?php namespace app\index\model; use think\Validate; cla ...

  3. 短信发送接口被恶意访问的网络攻击事件(三)定位恶意IP的日志分析脚本

    前言 承接前文<短信发送接口被恶意访问的网络攻击事件(二)肉搏战-阻止恶意请求>,文中有讲到一个定位非法IP的shell脚本,现在就来公布一下吧,并没有什么技术难度,只是当时花了些时间去写 ...

  4. 短信发送接口被恶意访问的网络攻击事件(四)完结篇--搭建WAF清理战场

    前言 短信发送接口被恶意访问的网络攻击事件(一)紧张的遭遇战险胜 短信发送接口被恶意访问的网络攻击事件(二)肉搏战-阻止恶意请求 短信发送接口被恶意访问的网络攻击事件(三)定位恶意IP的日志分析脚本 ...

  5. python 简单爬虫获取气象数据发送气象定时报-预报预警信息及时推送及阿里云短信群发接口

    !/usr/bin/python #encoding=utf-8 #Author:Ruiy #//////////////////////////////////////////////////// ...

  6. destoon 短信发送函数及短信接口修改

    // $DT在common.inc.php中定义, $CACHE = cache_read('module.php'); $DT = $CACHE['dt'];  从缓存里读取网站配置信息. //$d ...

  7. C# 编写短信发送Window服务

    我们做项目过程中,一般都会有发送短信的需求.最常见的就是户注册或者登录时发送短信验证码.不同类型的短信发送,我们都可以放到到一张短信表中,然后通过一个定时的作业去执行短信发送.而定时作业的执行,我们就 ...

  8. Abp 添加阿里云短信发送

    ABP中有短信发送接口ISmsSender public interface ISmsSender { Task<string> SendAsync(string number, stri ...

  9. ABP框架中短信发送处理,包括阿里云短信和普通短信商的短信发送集成

    在一般的系统中,往往也有短信模块的需求,如动态密码的登录,系统密码的找回,以及为了获取用户手机号码的短信确认等等,在ABP框架中,本身提供了对邮件.短信的基础支持,那么只需要根据自己的情况实现对应的接 ...

随机推荐

  1. ggplot2作图详解7(完):主题(theme)设置

    凡是和数据无关的图形设置内容理论上都可以归为主题类,但考虑到一些内容(如坐标轴)的特殊性,可以允许例外的情况.主题的设置相当繁琐,很容易就占用了 大量的作图时间,应尽量把这些东西简化,把注意力主要放在 ...

  2. lapply

    正如前面展示的,lapply( )函数接收一个向量和一个函数作为输入参数.它将这个函数应用到向量中的每个元素,再将结果以列表的形式返回.当每次迭代都是相互独立时,这个函数就非常好用.因为在这种情况下, ...

  3. 【 Python】模块学习之Flask模板引擎:jinja2

    原文链接:https://www.cnblogs.com/dachenzi/p/8242713.html 模板的概念 要了解jinja2,那么需要先理解模板的概念.模板在Python的web开发中广泛 ...

  4. vnc viewer 点击system 卡死现象

    转自:http://zhangjunli177.blog.163.com/blog/static/1386073082012103052527557/ VNC viewer desktop dead ...

  5. 数论练习(6)——hdu A/B(逆元gcd)

    A/B Time Limit: 1000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submiss ...

  6. 转载:【Oracle 集群】RAC知识图文详细教程(九)--RAC基本测试与使用

    文章导航 集群概念介绍(一) ORACLE集群概念和原理(二) RAC 工作原理和相关组件(三) 缓存融合技术(四) RAC 特殊问题和实战经验(五) ORACLE 11 G版本2 RAC在LINUX ...

  7. 【LeetCode 225_数据结构_栈_实现】Implement Stack using Queues

    class Stack { public: // Push element x onto stack. void push(int x) { int len = nums.size(); nums.p ...

  8. icon fonts入门

    iconfont网站 http://www.iconfont.cn(推荐) http://fontello.com/ http://fontawesome.io/   https://icomoon. ...

  9. Beta阶段第2周/共2周 Scrum立会报告+燃尽图 10

    作业要求[https://edu.cnblogs.com/campus/nenu/2018fall/homework/2411] 版本控制:https://git.coding.net/liuyy08 ...

  10. ubuntu14.04安装Android Studio出现error while loading shared libraries: libz.so.1的解决方法

    参考博客地址: http://blog.csdn.net/newairzhang/article/details/28656693 安装lib32z1就可以解决,如下: 首先,sudo apt-get ...