java代码实现调用短信接口,发送短信验证。
一、代码示例
package com.aaa.zxf.login;
import org.apache.commons.httpclient.HttpClient;
import org.apache.commons.httpclient.NameValuePair;
import org.apache.commons.httpclient.methods.PostMethod;
import org.dom4j.Document;
import org.dom4j.DocumentHelper;
import org.dom4j.Element; /**
* 一、登录这个网站,注册登录。 http://www.ihuyi.com/product.php 可以免费使用10次。
*
*
*二、找到他的代码示例。在下面会有图片说明
*
*
*三、根据自己的需要,可以对示例代码进行修改。下面的代码是来自于对 https://blog.csdn.net/qq_17025903/article/details/73331091 的编辑。
*
*
*四、jar包管理。
* 1. 点击他的接口下载,里面提供的有jar包。
* 2.maven项目需要直接去搜索
*
* <dependencies>
* <!-- https://mvnrepository.com/artifact/commons-codec/commons-codec -->
* <dependency>
* <groupId>commons-codec</groupId>
* <artifactId>commons-codec</artifactId>
* <version>1.3</version>
* </dependency>
*
*
* <!-- https://mvnrepository.com/artifact/dom4j/dom4j -->
* <dependency>
* <groupId>dom4j</groupId>
* <artifactId>dom4j</artifactId>
* <version>1.6.1</version>
* </dependency>
*
*
*
* <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents/httpclient -->
* <dependency>
* <groupId>org.apache.httpcomponents</groupId>
* <artifactId>httpclient</artifactId>
* <version>4.5.6</version>
* </dependency>
*
* <!-- https://mvnrepository.com/artifact/commons-httpclient/commons-httpclient -->
* <dependency>
* <groupId>commons-httpclient</groupId>
* <artifactId>commons-httpclient</artifactId>
* <version>3.0-rc4</version> 我的这个jar包导不进来,maven项目没有搞定。
* </dependency>
*
*
*/ public class SendsmsDemo { private static String Url = "http://106.ihuyi.cn/webservice/sms.php?method=Submit"; //直接将示例代码中的URL 拿过来用就行。 public static int sendSms(String phone) { HttpClient client = new HttpClient();
PostMethod method = new PostMethod(Url); client.getParams().setContentCharset("GBK");
method.setRequestHeader("ContentType", "application/x-www-form-urlencoded;charset=GBK"); int mobile_code = (int) ((Math.random() * 9 + 1) * 100000); String content = new String("您的验证码是:" + mobile_code + "。请不要把验证码泄露给其他人。"); //提交短信
NameValuePair[] data = { // name 和 password 需要自行修改。
new NameValuePair("account", "C51843367"), //查看用户名 是登录用户中心->验证码短信->产品总览->APIID
new NameValuePair("password", "4839f1a37f6e5240109e6bf1cc8fd647"), //查看密码请登录用户中心->验证码短信->产品总览->APIKEY
new NameValuePair("mobile", phone),
new NameValuePair("content", content),
};
method.setRequestBody(data); try {
client.executeMethod(method); String SubmitResult = method.getResponseBodyAsString(); System.out.println(SubmitResult); Document doc = DocumentHelper.parseText(SubmitResult);
Element root = doc.getRootElement(); String code = root.elementText("code");
String msg = root.elementText("msg");
String smsid = root.elementText("smsid"); System.out.println(code);
System.out.println(msg);
System.out.println(smsid); if ("2".equals(code)) {
System.out.println("短信提交成功"); return mobile_code; //验证码
} else return 0; } catch (Exception e) {
e.printStackTrace();
return 0; } } //测试 手机号
public static void main(String[] args) {
sendSms("15290859821");
} }
二、图片说明




java代码实现调用短信接口,发送短信验证。的更多相关文章
- JAVA 调用第三方短信平台接口发送短信
做了几个调用三方短信平台发送短信的例子,大部分需要 携带参数,向指定URL发送请求 回顾对接第一个平台时痛苦的乱码经历,这里放一份代码,算是个模版,再用到的时候过来copy一下就OK. 在进入主题之前 ...
- android 中调用接口发送短信
android中可以通过两种方式发送短信 第一:调用系统短信接口直接发送短信:主要代码如下: //直接调用短信接口发短信 SmsManager smsManager = SmsManager.getD ...
- Java之HttpClient调用WebService接口发送短信源码实战
摘要 Java之HttpClient调用WebService接口发送短信源码实战 一:接口文档 二:WSDL 三:HttpClient方法 HttpClient方法一 HttpClient方法二 Ht ...
- .NET 微信开放平台接口(接收短信、发送短信)
.NET 微信开放平台接口(接收短信.发送短信) 前两天做个项目用到了微信api功能.项目完成后经过整理封装如下微信操作类. 以下功能的实现需要开发者已有微信的公众平台账号,并且开发模式已开启.接口配 ...
- 注册登录页面修订-Python使用redis-手机验证接口-发送短信验证
登录页面修订 views.Login.vue <template> <div class="login box"> <img src="@/ ...
- 企业短信通 C# HTTP接口 发送短信
/* 功能: 企业短信通 C# HTTP接口 发送短信 修改日期: 2014-09-01 说明: http://api.cnsms.cn/?ac=send&uid=用户账号&pwd=M ...
- 移动MAS短信平台发送短信
MAS短信平台发送短信分为两种方式 参考文档下载 一.sdk调用 using mas.ecloud.sdkclient; using System; namespace 短信发送 { class Pr ...
- 使用短信猫发送短信java代码
短信猫简单配置:https://www.cnblogs.com/Big-Boss/p/9699880.html 发送短信: package utils; import org.smslib.AGate ...
- java中用中国网建提供的SMS短信平台发送短信
接下来的项目需求中提到需要短信发送功能,以前没有做过,因此便在网上搜了一下.大体上说的都是有三种方法,分别是sina提供的webservice接口.短信mao和中国网建提供的SMS短信平台. 这三种方 ...
- 通过移动的Mas接口发送短信
1. 首先,需要移动公司提供的用户名.密码.服务ID.接口Url等信息. 2. 将短信信息整理成XML格式的字符串,再转为byte数组,通过POST的方式,将短信发往Mas接口.需要引用"M ...
随机推荐
- Exploration(hdu5222)
Exploration Accepts: 190 Submissions: 976 Time Limit: 30000/15000 MS (Java/Others) Memory Limit: ...
- Rikka with wood sticks(hdu5203)
Rikka with wood sticks Time Limit: 2000/1000 MS (Java/Others) Memory Limit: 65536/65536 K (Java/O ...
- 1319 - Monkey Tradition
1319 - Monkey Tradition PDF (English) Statistics Forum Time Limit: 2 second(s) Memory Limit: 32 MB ...
- 【机器学*】k*邻算法-03
心得体会: 需要思考如何将现实对象转化为特征向量,设置特征向量时记住鸭子定律1 鸭子定律1 如果走路像鸭子.说话像鸭子.长得像鸭子.啄食也像鸭子,那它肯定就是一只鸭子 事物的外在特征就是事物本质的表现 ...
- Pydantic使用
Pydantic可以在代码运行时提供类型提示, 数据校验失败时提供友好的错误提示, 使用Python的类型注解来进行数据校验和settings管理 一般使用 from datetime import ...
- pandas tutorial 2
@ 目录 Group_By 对数据进行分组 对 group进行迭代 选择一个group get_group() Aggregations 在group的基础上传入函数整合 Transformation ...
- elasticsearch之多索引查询
一.问题源起 在elasticsearch的查询中,我们一般直接通过URL来设置要search的index: 如果我们需要查询的索引比较多并且没有什么规律的话,就会面临一个尴尬的局面,超过URL的长度 ...
- Git 标签使用详解
列出标签 # 默认按字母排序显示 $ git tag # 模糊匹配查找标签 $ git tag -l "v1.8.5*" 创建标签 # 创建附注标签 $ git tag -a v1 ...
- SpringBoot 之 国际化
增加国际化i18n语言配置: # src/main/resources/i18n/login.properties login.btn=登录 # src/main/resources/i18n/log ...
- STM32时钟系统的配置寄存器和源码分析
一.时钟系统 概述 时钟是单片机运行的基础,时钟信号推动单片机内各个部分执行相应的指令,时钟系统就是CPU的脉搏,决定cpu速率. STM32有多个时钟来源的选择,为什么 STM32 要有多个时钟源呢 ...