Java开发SDK详解->客户端测试

本文详细介绍如何在SpringBoot项目中引入并测试SDK。首先,将SDK复制到项目的lib目录,并在pom.xml中配置依赖。然后,通过创建测试类,调用SDK提供的方法,验证其功能的正确性。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

一、前言

  • 前面已经开发好了服务端(服务端开发),并且已经打包好了SDK(SDK开发),现在我们在客户端引用SDK进行测试吧。

二、详情

2.1首先在项目中引入SDK

创建一个SpringBoot项目,包sdk复制到项目的lib目录下。
在这里插入图片描述

2.2 pom中引入jar包
<dependency>
    <groupId>com.lh.hope</groupId>
    <artifactId>hope-sdk</artifactId>
    <version>1.1</version>
    <scope>system</scope>
    <systemPath>${project.basedir}/lib/hope-sdk.jar</systemPath>
</dependency>
2.3 测试
package com.lh.basecryptology.sdk;

import com.alibaba.fastjson.JSON;
import com.lh.hope.client.SysUserClient;
import com.lh.hope.domain.SysUser;
import com.lh.hope.domain.SysUserDTO;
import com.lh.hope.domain.common.ApiRequest;
import com.lh.hope.domain.common.BaseResponse;
import com.lh.hope.domain.common.PageModel;

public class App {

    /**
     * 公钥
     */
    private static final String PUBLIC_KEY_STRING = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQCllRJyNyA5/kOKpF+VV322IN7fownz5GMltjnWLHJPE+xdusVYHz/3C0ck27sv7mHP0TrJ7PLxUHyeUJ9PGOZ2fyrBRikKNE4ce1ihNgQxorIJ68G+70eHyOr65mQxRYa4lUOHMMPHgicN/2vGCjwL/ET8eQU0yIRAoOnO8avAuQIDAQAB";
    
    public static void main(String[] args) {
        SysUserDTO dto = new SysUserDTO();
        dto.setStatus(0);
        ApiRequest<SysUserDTO> request = ApiRequest.<SysUserDTO>builder()
                .appId("000001")
                .url("http://localhost:8081/api/user/queryUserList")
                .publicKey(PUBLIC_KEY_STRING)
                .data(dto)
                .build();
        BaseResponse<PageModel<SysUser>> pageModelBaseResponse = SysUserClient.queryUserList(request);
        System.out.println(JSON.toJSONString(pageModelBaseResponse));
    }

}

接口已经调通结果已经打印在控制台
在这里插入图片描述

三、最后

附上自己参看的一些博客连接

<groupId>jakarta.servlet</groupId> <artifactId>jakarta.servlet-api</artifactId> <version>5.0.0</version> <!-- 使用最新的 Jakarta Servlet API 版本 --> <scope>provided</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-security</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-thymeleaf</artifactId> </dependency> <dependency> <groupId>org.projectlombok</groupId> <artifactId>lombok</artifactId> <version>1.18.26</version> </dependency> <!-- https://mvnrepository.com/artifact/com.tencentcloudapi/tencentcloud-sdk-java --> <dependency> <groupId>com.tencentcloudapi</groupId> <artifactId>tencentcloud-sdk-java</artifactId> <version>3.1.1245</version> </dependency> <!-- 验证码 --> <dependency> <groupId>pro.fessional</groupId> <artifactId>kaptcha</artifactId> <version>2.3.3</version> </dependency> <!-- Token生成与解析--> <dependency> <groupId>io.jsonwebtoken</groupId> <artifactId>jjwt</artifactId> <version>${jwt.version}</version> </dependency> <!-- 接口管理--> <!-- https://doc.xiaominfo.com/docs/quick-start --> <dependency> <groupId>com.github.xiaoymin</groupId> <artifactId>knife4j-openapi2-spring-boot-starter</artifactId> <version>4.3.0</version> </dependency> <!-- https://mvnrepository.com/artifact/com.alibaba/fastjson --> <!--dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>2.0.10</version> </dependency--> <dependency> <groupId>com.alibaba.fastjson2</groupId> <artifactId>fastjson2</artifactId> <version>2.0.57</version> </dependency> <!-- https://mvnrepository.com/artifact/org.apache.httpcomponents.client5/httpclient5 --> <dependency> <groupId>org.apache.httpcomponents.client5</groupId> <artifactId>httpclient5</artifactId> <version>5.2.1</version> </dependency> <!-- https://mvnrepository.com/artifact/com.huawei.apigateway/java-sdk-core --> <dependency> <groupId>com.huawei.apigateway</groupId> <artifactId>java-sdk-core</artifactId> <version>3.0.10</version> </dependency> <!--sdk参考文档--> <!--https://support.huaweicloud.com/devg-apisign/api-sign-sdk-java.html--> <!-- https://mvnrepository.com/artifact/org.apache.commons/commons-lang3 --> <dependency> <groupId>org.apache.commons</groupId> <artifactId>commons-lang3</artifactId> <version>3.14.0</version> </dependency> <!-- https://mvnrepository.com/artifact/cn.hutool/hutool-all --> <dependency> <groupId>cn.hutool</groupId> <artifactId>hutool-all</artifactId> <version>5.8.24</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-data-jpa</artifactId> </dependency> <dependency> <groupId>mysql</groupId> <artifactId>mysql-connector-java</artifactId> <version>8.0.17</version> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.mybatis.spring.boot</groupId> <artifactId>mybatis-spring-boot-starter-test</artifactId> <version>3.0.3</version> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.security</groupId> <artifactId>spring-security-test</artifactId> <scope>test</scope> </dependency> <dependency> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-starter-web</artifactId> </dependency> <dependency> <groupId>junit</groupId> <artifactId>junit</artifactId> <version>3.8.1</version> <scope>test</scope> </dependency> <dependency> <groupId>com.squareup.okhttp3</groupId> <artifactId>okhttp</artifactId> <version>4.12.0</version> </dependency> <dependency> <groupId>org.json</groupId> <artifactId>json</artifactId> <version>20210307</version> </dependency> <!-- <dependency> <groupId>com.azure</groupId> <artifactId>azure-ai-openai</artifactId> <version>1.0.0-beta.6</version> </dependency> <dependency> <groupId>com.logaritex.ai</groupId> <artifactId>assistant-api</artifactId> <version>0.3.0</version> </dependency>--> </dependencies> <repositories> <repository> <id>HuaweiCloudSDK</id> <url>https://mirrors.huaweicloud.com/repository/maven/huaweicloudsdk/</url> <releases> <enabled>true</enabled> </releases> <snapshots> <enabled>false</enabled> </snapshots> </repository> <repository> <!-- id必须唯一 --> <id>aliyun-repository</id> <!-- 见名知意即可 --> <name>aliyun repository</name> <!-- 仓库的url地址 --> <url>http://maven.aliyun.com/nexus/content/groups/public/</url> </repository> </repositories> <build> <plugins> <plugin> <groupId>org.springframework.boot</groupId> <artifactId>spring-boot-maven-plugin</artifactId> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-surefire-plugin</artifactId> <configuration> <skipTests>true</skipTests> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-compiler-plugin</artifactId> <configuration> <source>${java.version}</source> <target>${java.version}</target> </configuration> </plugin> <plugin> <groupId>org.apache.maven.plugins</groupId> <artifactId>maven-jar-plugin</artifactId> <version>2.6</version> </plugin>解释一下这些依赖的作用
最新发布
07-24
评论 3
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值