电商项目日总结(第十四天阿里云短信服务&HttpClient)

一、实现了模拟利用阿里云发送短信的功能

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
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值