|
@@ -0,0 +1,97 @@
|
|
|
+package com.zhentao;
|
|
|
+
|
|
|
+import com.zhentao.service.TestService;
|
|
|
+import com.zhentao.service.impl.TestServiceImpl;
|
|
|
+import com.zhentao.util.HttpUtils;
|
|
|
+import org.springframework.boot.SpringApplication;
|
|
|
+import org.springframework.boot.autoconfigure.SpringBootApplication;
|
|
|
+
|
|
|
+import java.text.ParseException;
|
|
|
+import java.text.SimpleDateFormat;
|
|
|
+import java.util.Date;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.Map;
|
|
|
+
|
|
|
+@SpringBootApplication
|
|
|
+public class Day01Application {
|
|
|
+ static TestService signService = new TestServiceImpl();
|
|
|
+ public static void main(String[] args) {
|
|
|
+ SpringApplication.run(Day01Application.class, args);
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ // 接口一的请求参数 post请求
|
|
|
+ Map<String, Object> requestParams1 = new HashMap<>();
|
|
|
+ requestParams1.put("appId", "123");
|
|
|
+ requestParams1.put("goodsId", "456");
|
|
|
+ requestParams1.put("reqTime", 1111L);
|
|
|
+ requestParams1.put("amount", 1);
|
|
|
+ requestParams1.put("price", 10.00);
|
|
|
+ requestParams1.put("mobile", "13800138000");
|
|
|
+ requestParams1.put("reqId", "789");
|
|
|
+
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Date nowDate = sdf.parse("2020-02-03");
|
|
|
+ requestParams1.put("nowDate", nowDate);
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成签名
|
|
|
+ String sign1 = signService.generateSign(requestParams1);
|
|
|
+ requestParams1.put("sign", sign1);
|
|
|
+
|
|
|
+ // 调用接口一
|
|
|
+ String url1 = "http://localhost:8080/test/postApi";
|
|
|
+ String reqId = "789";
|
|
|
+ HttpUtils.callInterface(url1, requestParams1, reqId);
|
|
|
+ System.err.println("post请求");
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+//get请求
|
|
|
+ // 接口二的请求参数
|
|
|
+ Map<String, Object> requestParams2 = new HashMap<>();
|
|
|
+ requestParams2.put("appId", "123");
|
|
|
+ requestParams2.put("goodsId", "456");
|
|
|
+ requestParams2.put("reqTime", 1111L);
|
|
|
+ requestParams2.put("amount", 1);
|
|
|
+ requestParams2.put("price", 10.00);
|
|
|
+ requestParams2.put("mobile", "13800138000");
|
|
|
+ requestParams2.put("reqId", "789");
|
|
|
+
|
|
|
+ try {
|
|
|
+ SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd");
|
|
|
+ Date nowDate = sdf.parse("2020-02-03");
|
|
|
+ // 由于实体类中 nowDate 为 String 类型,这里将 Date 转为 String
|
|
|
+ requestParams2.put("nowDate", sdf.format(nowDate));
|
|
|
+ } catch (ParseException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+
|
|
|
+ // 生成签名
|
|
|
+ String sign2 = signService.generateSign(requestParams2);
|
|
|
+ requestParams2.put("sign", sign2);
|
|
|
+
|
|
|
+ // 调用接口二
|
|
|
+ String url2 = "http://localhost:8080/test/getApi";
|
|
|
+ String reqId2 = "789";
|
|
|
+ HttpUtils.callGetInterface(url2, requestParams2, reqId2);
|
|
|
+ System.err.println("get请求");
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+}
|