1.进入控制台后,把鼠标放在头像上然后点击access key管理 2.新建用户组 3.添加用户
4.给用户组添加权限 5.将用户添加到用户组
6.进入短信服务界面 7.添加签名 8.添加模板 ps:添加签名和模板时的理由要求正当合理,然后等待它审核通过
1.新建一个springboot项目,并添加依赖
<dependency> <groupId>com.aliyun</groupId> <artifactId>aliyun-java-sdk-core</artifactId> <version>4.0.6</version> </dependency> <dependency> <groupId>com.alibaba</groupId> <artifactId>fastjson</artifactId> <version>1.2.70</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-redis</artifactId> </dependency>
复制阿里云上的代码
public static void main(String[] args) { DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "xxxx@xxxxx.onaliyun.com", "阿里云登录密码"); 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", "手机号"); request.putQueryParameter("SignName", "短信签名"); request.putQueryParameter("TemplateCode", "短信模板 SMS_208915239"); HashMap<String, Object> map = new HashMap<>(); map.put("code","验证码"); request.putQueryParameter("TemplateParam", JSONObject.toJSONString(map)); try { CommonResponse response = client.getCommonResponse(request); System.out.println(response.getData()); } catch (ServerException e) { e.printStackTrace(); } catch (ClientException e) { e.printStackTrace(); } }
参数的使用