鄙人用的是Java,其他语言也可以用如:c语言、c++、python、java、php等,具体如下
互亿无线
网址:https://www.ihuyi.com
新用户会送几条免费短信,具体几条我也忘记了。
注意:注册号码后会有平台工作人员打电话给你询问你注册这个号干嘛的,其实就是拉你做客户,不用紧张。
----登录进去后在首页可以看到自己的电话号码,和短信余额,然后点击验证码通知短信
下载好的文档是个压缩包,解压就可以了,是这样的:
选择你需要的语言就行啦
我们找到java所在的文件夹
点到这个位置
lib下的是jar包依赖
src下的是实现主要代码
本人是pom文件注入依赖的
<!-- 短信验证jar包 --> <dependency> <groupId>commons-codec</groupId> <artifactId>commons-codec</artifactId> <version>1.9</version> </dependency> <dependency> <groupId>commons-httpclient</groupId> <artifactId>commons-httpclient</artifactId> <version>3.0-rc4</version> </dependency> <dependency> <groupId>commons-logging</groupId> <artifactId>commons-logging</artifactId> <version>1.0.4</version> </dependency> <dependency> <groupId>dom4j</groupId> <artifactId>dom4j</artifactId> <version>1.6.1</version> </dependency>
导入jar包后就把src下的代码放入项目中
工具类:
//接口类型:互亿无线触发短信接口,支持发送验证码短信、订单通知短信等。 // 账户注册:请通过该地址开通账户http://sms.ihuyi.com/register.html // 注意事项: //(1)调试期间,请用默认的模板进行测试,默认模板详见接口文档; //(2)请使用APIID(查看APIID请登录用户中心->验证码短信->产品总览->APIID)及 APIkey来调用接口; //(3)该代码仅供接入互亿无线短信接口参考使用,客户可根据实际需要自行编写; package com.zking.ssm.test.util; import java.security.MessageDigest; public class StringUtil { public static String str; public static final String EMPTY_STRING = ""; private final static String[] hexDigits = { "0", "1", "2", "3", "4", "5", "6", "7", "8", "9", "A", "B", "C", "D", "E", "F" }; private static String byteToHexString(byte b) { int n = b; if (n < 0) n = 256 + n; int d1 = n / 16; int d2 = n % 16; return hexDigits[d1] + hexDigits[d2]; } /** * 转换字节数组为16进制字串 * @param b 字节数组 * @return 16进制字串 */ public static String byteArrayToHexString(byte[] b) { StringBuffer resultSb = new StringBuffer(); for (int i = 0; i < b.length; i++) { resultSb.append(byteToHexString(b[i])); } return resultSb.toString(); } public static String MD5Encode(String origin) { String resultString = null; try { resultString = new String(origin); MessageDigest md = MessageDigest.getInstance("MD5"); resultString = byteArrayToHexString(md.digest(resultString .getBytes())); } catch (Exception ex) { } return resultString; } }
实现功能的类有两个只是编码方式不一样是sendsms和sendsmsutf-8,
这里要用到你账户的APIID和APIKEY还有手机号了
account:对应的是APIID
password:对应的是APIKEY
mobile:手机号
package com.zking.ssm.test;//接口类型:互亿无线触发短信接口,支持发送验证码短信、订单通知短信等。 // 账户注册:请通过该地址开通账户http://sms.ihuyi.com/register.html // 注意事项: //(1)调试期间,请用默认的模板进行测试,默认模板详见接口文档; //(2)请使用APIID(查看APIID请登录用户中心->验证码短信->产品总览->APIID)及 APIkey来调用接口; //(3)该代码仅供接入互亿无线短信接口参考使用,客户可根据实际需要自行编写; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import com.zking.ssm.test.util.StringUtil; public class sendsms { private static String Url = "http://106.ihuyi.cn/webservice/sms.php?method=Submit"; public static void main(String [] args) { 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 = {//提交短信 new NameValuePair("account", "C84099173"), //查看用户名是登录用户中心->验证码短信->产品总览->APIID new NameValuePair("password", "4d6bce3d366d986fa59560484906dd94"), //查看密码请登录用户中心->验证码短信->产品总览->APIKEY //new NameValuePair("password", util.StringUtil.MD5Encode("密码")), new NameValuePair("mobile", "191******72"), 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("短信提交成功"); } } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
sendsmsutf8:
//接口类型:互亿无线触发短信接口,支持发送验证码短信、订单通知短信等。 // 账户注册:请通过该地址开通账户http://sms.ihuyi.com/register.html // 注意事项: //(1)调试期间,请用默认的模板进行测试,默认模板详见接口文档; //(2)请使用APIID(查看APIID请登录用户中心->验证码短信->产品总览->APIID)及 APIkey来调用接口; //(3)该代码仅供接入互亿无线短信接口参考使用,客户可根据实际需要自行编写; package com.zking.ssm.test; import java.io.IOException; import org.apache.commons.httpclient.HttpClient; import org.apache.commons.httpclient.HttpException; import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; import org.dom4j.Document; import org.dom4j.DocumentException; import org.dom4j.DocumentHelper; import org.dom4j.Element; import com.zking.ssm.test.util.StringUtil; public class sendsmsutf8 { private static String Url = "http://106.ihuyi.cn/webservice/sms.php?method=Submit"; public static void main(String [] args) { HttpClient client = new HttpClient(); PostMethod method = new PostMethod(Url); client.getParams().setContentCharset("UTF-8"); method.setRequestHeader("ContentType","application/x-www-form-urlencoded;charset=UTF-8"); int mobile_code = (int)((Math.random()*9+1)*100000); String content = new String("您的验证码是:" + mobile_code + "。请不要把验证码泄露给其他人。"); NameValuePair[] data = {//提交短信 new NameValuePair("account", "C84099173"), //查看用户名是登录用户中心->验证码短信->产品总览->APIID new NameValuePair("password", "4d6bce3d366d986fa59560484906dd94"), //查看密码请登录用户中心->验证码短信->产品总览->APIKEY //new NameValuePair("password", util.StringUtil.MD5Encode("密码")), new NameValuePair("mobile", "191******72"), 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("短信提交成功"); } } catch (HttpException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (IOException e) { // TODO Auto-generated catch block e.printStackTrace(); } catch (DocumentException e) { // TODO Auto-generated catch block e.printStackTrace(); } } }
配置好后,运行就能收到短信啦
我收到的短信截图:
over,如有问题,可以在评论区留言哦。