发送短信验证码

​​​​​​【短信验证码-快速报备签名】三网短信接口-短信-短信验证码-短信服务-三网短信接口-短信-三网短信【最新版】_商业智能_电商_金融-云市场-阿里云阿里云云市场提供 专注企业短信服务10年运营与技术积累,稳定、安全、快速。服务,建站服务,api服务,助力企业、客户更好的解决问题,帮助企业进行数字化建设。由北京深智恒际科技有限公司为您提供服务https://market.aliyun.com/products/57124001/cmapi00037170.html?spm=5176.2020520132.101.2.330c7218KMwlX4#sku=yuncode3117000001阿里云云市场提供 专注企业短信服务10年运营与技术积累,稳定、安全、快速。服务,建站服务,api服务,助力企业、客户更好的解决问题,帮助企业进行数字化建设。由北京深智恒际科技有限公司为您提供服务icon-default.png?t=N7T8https://market.aliyun.com/products/57124001/cmapi00037170.html?spm=5176.2020520132.101.2.330c7218KMwlX4#sku=yuncode3117000001

   String url = "https://dfsns.market.alicloudapi.com/data/send_sms";
         String appcode = "363efa0e07bb4c368b05f500db153ec5";
         int code = RandomUtil.randomInt(1000,10000);

         String result = HttpRequest.post(url)
                 .header("Authorization", "APPCODE "+appcode)
                 .body("content=code:"+code+"&template_id=TPL_0000&phone_number="+tel)
                 .execute().body();

         JSONObject object = JSONUtil.parseObj(result);
         if(!object.get("status").equals("OK")){
             log.error("发送验证码错误:{}",object.get("reason"));
             throw new BizException(404,"发送验证码错误");
         }

 

  • 3
    点赞
  • 9
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
发送短信验证码可以使用阿里云的短信服务,以下是使用Spring Boot集成阿里云短信服务发送短信验证码的简单步骤: 1. 在阿里云控制台开通短信服务并获取AccessKey和AccessSecret。 2. 引入阿里云短信服务SDK依赖,例如: ``` <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.5.3</version> </dependency> <dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-dysmsapi</artifactId> <version>1.0.0</version> </dependency> ``` 3. 编写发送短信验证码的代码,例如: ``` @RestController public class SmsController { @Autowired private AliyunSmsConfig aliyunSmsConfig; // 阿里云短信服务配置 @PostMapping("/sms/send") public String sendSms(@RequestParam String mobile) throws ClientException { // 生成6位随机验证码 String code = String.valueOf((int)((Math.random()*9+1)*100000)); // 发送短信验证码 DefaultProfile profile = DefaultProfile.getProfile("default", aliyunSmsConfig.getAccessKey(), aliyunSmsConfig.getAccessSecret()); IAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); request.setMethod(MethodType.POST); request.setDomain("dysmsapi.aliyuncs.com"); request.setVersion("2017-05-25"); request.setAction("SendSms"); request.putQueryParameter("PhoneNumbers", mobile); request.putQueryParameter("SignName", aliyunSmsConfig.getSignName()); request.putQueryParameter("TemplateCode", aliyunSmsConfig.getTemplateCode()); request.putQueryParameter("TemplateParam", "{\"code\":\"" + code + "\"}"); CommonResponse response = client.getCommonResponse(request); // 输出发送结果 System.out.println(response.getData()); return code; } } ``` 其中,`AliyunSmsConfig`是阿里云短信服务的配置类,需要配置AccessKey、AccessSecret、短信签名和短信模板编号等信息。 4. 在前端页面中添加发送短信验证码的按钮,并调用发送短信验证码的接口。 以上就是使用Spring Boot集成阿里云短信服务发送短信验证码的简单步骤,希望对你有所帮助。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值