云片网发送短信验证码java服务端
我们可以根据我嗯的需要调用实例为我们提供的相应的方法,我也是第一次做,我在项目总的的也就也点点,没什么经验,希望能帮助到你们。
2、还是直接上代码吧
/**
* 云片网短信
* @param phone
* @return
* @throws IOException
* @throws URISyntaxException
*/
@ResponseBody
@RequestMapping(value = "/send.do", produces = "text/html;charset=UTF-8",method={RequestMethod.POST})
public String send(String phone) throws IOException, URISyntaxException {
String apikey = "7******************************c";
String mobile = URLEncoder.encode(phone,"UTF-8");
/**************** 查账户信息调用示例 *****************/
System.out.println(YunPianSmsApi.getUserInfo(apikey));
/**************** 使用智能匹配模版接口发短信(推荐) *****************/
Random r = new Random();
int i = r.nextInt(1000000);
String text = "【XXXX】您的验证码是" + i;
String string = YunPianSmsApi.sendSms(apikey, text, mobile);
System.out.println("发送的验证码为" + i);
System.out.println(YunPianSmsApi.sendSms(apikey, text, mobile));
/**************** 使用指定模板接口发短信(不推荐,建议使用智能匹配模版接口) *****************/
/**************** 使用接口发语音验证码 *****************/
return string;
}