准备:eclipse,浏览器
第一步:打开云之讯官网,先注册,注册后,如下图(可以看到送了些钱):
第二步:认证个人开发者/企业开发(认证后可以创建应用),如下图:
第三步:创建应用,如图:
第四步:开通短信验证功能,如图我开通了:
第五步:创建模板,提交审核(短信-模板库),如图:
第六步:审核通过后,下载sdk,下载后解压,eclipse导入,如图:
第七步(最后一步,恭喜你,你即将成功完成测试,接收到短信):
双击打开sdk中RestTest.java,里面的代码如下:
/**
* @author Tony
* @date 2018-01-10
* @project rest_demo
*/
package com;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import org.apache.commons.lang.StringUtils;
import com.ucpaas.restDemo.client.AbsRestClient;
import com.ucpaas.restDemo.client.JsonReqClient;
public class RestTest {
static AbsRestClient InstantiationRestAPI() {
return new JsonReqClient();
}
public static void testSendSms(String sid, String token, String appid, String templateid, String param, String mobile, String uid){
try {
String result=InstantiationRestAPI().sendSms(sid, token, appid, templateid, param, mobile, uid);
System.out.println("Response content is: " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void testSendSmsBatch(String sid, String token, String appid, String templateid, String param, String mobile, String uid){
try {
String result=InstantiationRestAPI().sendSmsBatch(sid, token, appid, templateid, param, mobile, uid);
System.out.println("Response content is: " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void testAddSmsTemplate(String sid, String token, String appid, String type, String template_name, String autograph, String content){
try {
String result=InstantiationRestAPI().addSmsTemplate(sid, token, appid, type, template_name, autograph, content);
System.out.println("Response content is: " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void testGetSmsTemplate(String sid, String token, String appid, String templateid, String page_num, String page_size){
try {
String result=InstantiationRestAPI().getSmsTemplate(sid, token, appid, templateid, page_num, page_size);
System.out.println("Response content is: " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void testEditSmsTemplate(String sid, String token, String appid, String templateid, String type, String template_name, String autograph, String content){
try {
String result=InstantiationRestAPI().editSmsTemplate(sid, token, appid, templateid, type, template_name, autograph, content);
System.out.println("Response content is: " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
public static void testDeleterSmsTemplate(String sid, String token, String appid, String templateid){
try {
String result=InstantiationRestAPI().deleterSmsTemplate(sid, token, appid, templateid);
System.out.println("Response content is: " + result);
} catch (Exception e) {
e.printStackTrace();
}
}
/**
* 测试说明 启动main方法后,请在控制台输入数字(数字对应 相应的调用方法),回车键结束
* 参数名称含义,请参考rest api 文档
* @throws IOException
* @method main
*/
public static void main(String[] args) throws IOException{
System.out.println("请输入方法对应的数字(例如1),Enter键结束:");
BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
String methodNumber = br.readLine();
if (StringUtils.isBlank(methodNumber)){
System.out.println("请输入正确的数字,不可为空");
return;
}
if (methodNumber.equals("1")) { //指定模板单发
String sid = "";
String token = "";
String appid = "";
String templateid = "";
String param = "";
String mobile = "";
String uid = "";
testSendSms(sid, token, appid, templateid, param, mobile, uid);
} else if (methodNumber.equals("2")) { //指定模板群发
String sid = "";
String token = "";
String appid = "";
String templateid = "";
String param = "";
String mobile = "";
String uid = "";
testSendSmsBatch(sid, token, appid, templateid, param, mobile, uid);
} else if (methodNumber.equals("3")) { //增加模板
String sid = "";
String token = "";
String appid = "";
String type = "";
String template_name = "";
String autograph = "";
String content = "";
testAddSmsTemplate(sid, token, appid, type, template_name, autograph, content);
} else if (methodNumber.equals("4")) { //查询模板
String sid = "";
String token = "";
String appid = "";
String templateid = "";
String page_num = "";
String page_size = "";
testGetSmsTemplate(sid, token, appid, templateid, page_num, page_size);
} else if (methodNumber.equals("5")) { //编辑模板
String sid = "";
String token = "";
String appid = "";
String templateid = "";
String type = "";
String template_name = "";
String autograph = "";
String content = "";
testEditSmsTemplate(sid, token, appid, templateid, type, template_name, autograph, content);
} else if (methodNumber.equals("6")) { //删除模板
String sid = "";
String token = "";
String appid = "";
String templateid = "";
testDeleterSmsTemplate(sid, token, appid, templateid);
}
}
}
其中,在下面这些代码(选自RestTest.java)编辑参数,后提交运行,记得开网络:
if (methodNumber.equals("1")) { //指定模板单发
String sid = "";//这个参数可以在 -短信 中找到(后面附图片)
String token = "";//这个参数可以在 -短信 中找到(后面附图片)
String appid = "";//这个参数可以在 -短信 中找到(后面附图片)
String templateid = "";//模板名称,就是刚刚通过审核的模板名称
String param = "";//特别提醒,这里什么鬼?这里填(看下面附图)
String mobile = "";//手机号码
String uid = "";//测试,不用填
testSendSms(sid, token, appid, templateid, param, mobile, uid);
} else if (methodNumber.equals("2")) { //指定模板群发