java小王博客

记录菜B的一点一滴,欢迎各位好汉前来叨扰!


>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>博主qq:1756691861

阿里云验证码接口

2020-6-8 卑微小王

 

<dependency>  <groupId>com.aliyun</groupId>  <artifactId>aliyun-java-sdk-core</artifactId>  <version>4.0.6</version> </dependency>

 
 
 
 
 
package com.ruoyi.project.tool.massages; import com.alibaba.fastjson.JSONObject; import com.aliyuncs.CommonRequest; import com.aliyuncs.CommonResponse; import com.aliyuncs.DefaultAcsClient; import com.aliyuncs.IAcsClient; import com.aliyuncs.exceptions.ClientException; import com.aliyuncs.exceptions.ServerException; import com.aliyuncs.http.MethodType; import com.aliyuncs.profile.DefaultProfile; import com.alibaba.fastjson.JSONObject; import com.ruoyi.framework.redis.RedisClientServer; import java.util.List; import java.util.Map; /**  * @title  * @auther WangWenJie  * @date 2020/6/7 20:33  **/ public class duanxin { /**  * 短信发送  * @param PhoneNumbers 用户手机号  * @param TemplateParam 验证码  * @return  */  
 public  void fasong(String PhoneNumbers, String TemplateParam){ 
String accessKeyId=""; 
String accessSecret="";
 DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", accessKeyId, accessSecret); IAcsClient client = new DefaultAcsClient(profile); CommonRequest request = new CommonRequest(); request.setSysMethod(MethodType.POST); request.setSysDomain("dysmsapi.aliyuncs.com"); request.setSysVersion("2017-05-25"); request.setSysAction("SendSms"); request.putQueryParameter("RegionId", "cn-hangzhou"); request.putQueryParameter("PhoneNumbers", PhoneNumbers); request.putQueryParameter("SignName", "签名"); request.putQueryParameter("TemplateCode", "模板号"); request.putQueryParameter("TemplateParam", "{\"code\":"+TemplateParam+"}"); try { CommonResponse response = client.getCommonResponse(request); JSONObject pa=JSONObject.parseObject(response.getData()); //判断是或否发送成功  if(pa.getString("Code") !=null && pa.getString("Code").equals("OK")){ //成功后设置redis过期时间60 RedisClientServer.set(PhoneNumbers,TemplateParam,60);
            } System.out.println(response.getData());
        } catch (ServerException e) {
            e.printStackTrace();
        } catch (ClientException e) {
            e.printStackTrace();
        } catch (Exception e) {
            e.printStackTrace();
        }
    }
}

发表评论: