浏览代码

feat:后端项目,调整调用接口的客户端通过固定的url和动态的path进行接口调用

yang yi 10 月之前
父节点
当前提交
fe83149599

+ 3 - 2
open-api-client/src/main/java/space/anyi/client/ClientApplication.java

@@ -20,7 +20,8 @@ public class ClientApplication {
     public static final String ACCESS_KEY = "accessKey";
     public static final String SECRET_KEY = "secretKey";
     public static void main(String[] args) {
-        OpenAPIClient client = new OpenAPIClient(ACCESS_KEY, SECRET_KEY,"http://localhost:10002/open-api/user/body");
-        client.handler("yangyi");
+        OpenAPIClient client = new OpenAPIClient(ACCESS_KEY, SECRET_KEY,"http://localhost:10002");
+        String path = "/open-api/user/body";
+        client.handler(path,"yangyi");
     }
 }

+ 2 - 2
open-api-client/src/main/java/space/anyi/client/OpenAPIClient.java

@@ -31,11 +31,11 @@ public class OpenAPIClient {
         this.secretKey = secretKey;
         this.url = url;
     }
-    public String handler(String data){
+    public String handler(String path,String data){
         User user = new User(data);
         String json = JSONUtil.toJsonStr(user);
         String timestamp = System.currentTimeMillis() + "";
-        HttpResponse httpResponse = HttpRequest.post(url)
+        HttpResponse httpResponse = HttpRequest.post(url+path)
                 .header("accessKey",accessKey)//accessKey
                 .header("timestamp", timestamp)//时间戳
                 .header("sign",getSign(secretKey,timestamp))//摘要签名