一、实现了模拟利用阿里云发送短信的功能
1.新建了一个SmsSendDemo的工程
2.在pom文件中导入相关jar包
3.拷贝阿里云发送短信的API
public class SendDemo {
public static void main(String[] args) {
//后两个参数是访问阿里云的密钥
DefaultProfile profile = DefaultProfile.getProfile("cn-hangzhou", "************", "*****************");
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("RegionId", "cn-hangzhou");
//手机号
request.putQueryParameter("PhoneNumbers", "*********");
//签名名称
request.putQueryParameter("SignName", "*******");
//短信模板CODE信息
request.putQueryParameter("TemplateCode", "*******");
//验证码内容
request.putQueryParameter("TemplateParam", "{\"code\":\"666888\"}");
try {
CommonResponse response = client.getCommonResponse(request);
System.out.println(response.getData());
} catch (ServerException e) {
e.printStackTrace();
} catch (ClientException e) {
e.printStackTrace();
}
}
}
4.运行main方法即可向目标手机号发送短信
二、实现了通过HttpClient获取到所有的品牌
HttpClient就是模拟支持 HTTP 协议的客户端向别的服务器发送请求并且可以获得页面信息的一个框架
实现思路:利用HttpClient向pyg_manager_web模块中的http://localhost:9101/brand/findAll.do发送请求,从而可以获取到页面响应的json类型的品牌信息
步骤:
1.在SmsSendDemo模块的pom文件中导入和HttpClient相关的坐标
2.引入封装好的操作HttpClient的工具类HttpClientUtil
3.写一个测试方法
public static void main(String[] args) throws IOException, ParseException {
//解决方法二:就在在访问获取所有品牌前登陆,通过安全验证
HttpClientUtil httpClientUtil1 = new HttpClientUtil("http://localhost:9101/login");
Map map=new HashMap();
map.put("username","admin");
map.put("password","123456");
//设置post提交方式传递的信息
httpClientUtil1.setParameter(map);
//post提交
httpClientUtil1.post();
String content1 = httpClientUtil1.getContent();
System.o