https://luosimao.com/docs/api/25
private String testSend(){
// just replace key here
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter(
"api","key-d609b769db914a4d959bae3414ed1f7X"));
WebResource webResource = client.resource(
"http://sms-api.luosimao.com/v1/send.json");
MultivaluedMapImpl formData = new MultivaluedMapImpl();
formData.add("mobile", "13761428267");
formData.add("message", "验证码:286221【铁壳测试】");
ClientResponse response = webResource.type( MediaType.APPLICATION_FORM_URLENCODED ).
post(ClientResponse.class, formData);
String textEntity = response.getEntity(String.class);
int status = response.getStatus();
//System.out.print(textEntity);
//System.out.print(status);
return textEntity;
}
相关jar包下载:
jersey-bundle-1.19.jar
json-org.jar
public static void main(String[] args) {
String s = testSend();
System.out.println(s);
}
public static String testSend(String phone,String yzm){
// just replace key here
Client client = Client.create();
client.addFilter(new HTTPBasicAuthFilter(
"api","key-2172ea9ebbbb2dad933a2705af824e92"));
WebResource webResource = client.resource(
"http://voice-api.luosimao.com/v1/verify.json");
MultivaluedMapImpl formData = new MultivaluedMapImpl();
formData.add("mobile", phone);
formData.add("code", yzm);
ClientResponse response = webResource.type( MediaType.APPLICATION_FORM_URLENCODED ).
post(ClientResponse.class, formData);
String textEntity = response.getEntity(String.class);
int status = response.getStatus();
//System.out.print(textEntity);
//System.out.print(status);
return textEntity;
}
$("#jy").on("click",function () {
$.ajax({
url:"getYzm.do",
data:{"phone":$("#phone").val},
dataType:"json",
type:"post",
success:function (data) {
if(data.error==0) alert("发送成功");
else alert("发送失败,请稍后再试!");
}
})
})
@RequestMapping("getYzm")
@ResponseBody
public String getYzm(HttpSession session, String phone){
Random r=new Random();//实例化一个随机函数
int i = r.nextInt(1000000);
DecimalFormat df=new DecimalFormat("000000");//格式化数字,自动补零
String yzm = df.format(i);
System.out.println(yzm);
session.setAttribute(phone,yzm);
return checkPhone.testSend(phone,yzm);
}
$('#zc').on('click',function(){
$.ajax({
type:"post",
url:"save.do",
async : true,
data:$('#login').serializeArray(),
dataType:"json",
success:function (data) {
if(data){
alert("注册成功!");
}else{
alert("注册失败");
}
}
})
});
@RequestMapping("save")
@ResponseBody
public Boolean saveUser(HttpSession session,User user){
String newYzm = (String)session.getAttribute(user.getUsPhone());
System.out.println(newYzm);
if(newYzm.equals(user.getUsYzm())){
userService.saveUser(user);
return true;
}else{
return false;
}
}