# G-License **Repository Path**: dwdyoung/g-license ## Basic Information - **Project Name**: G-License - **Description**: 用于公信服务器及终端授权接入 - **Primary Language**: Java - **License**: GPL-3.0 - **Default Branch**: master - **Homepage**: None - **GVP Project**: No ## Statistics - **Stars**: 2 - **Forks**: 1 - **Created**: 2023-02-28 - **Last Updated**: 2025-05-24 ## Categories & Tags **Categories**: Uncategorized **Tags**: None ## README # 授权接入 ## 后端接入示例 ### 添加依赖 ``` xml com.gonsin GLicense 1.2 ``` ### 添加注解 特别注意,只能在main方法对应的类上添加该注解,整个可运行的代码**不能有2处**`@EnableGLicense` ``` java /// 其他注解 // 添加如下代码,device表示你的项目类型,每个系统对应一个device,授权文件根据device的不同而互相区分 @EnableGLicense(device = "paperless_v3") public class Application extends SpringBootServletInitializer { public static void main(String[] args) { SpringApplication.run(Application.class); } } ``` ## 前端接入示例 ### 安装依赖 ``` bash npm install @gonsin/glicense ``` ### 添加路由 在需要授权接入的项目的路由中添加: ```js import GLicense from "@gonsin/glicense"; // ... 省略其他代码 const routes = [ { path: "/license", name: "license", component: GLicense, } ] ``` ### 添加拦截器 添加响应拦截配置: 以下为 axios 封装中响应拦截器的例子(需要将 `this.router` 替换成可跳转路由的 router 实例): ```js this.service.interceptors.response.use( (response: AxiosResponse) => { const { data } = response; const { state } = data; if (state == 200) { return data; } else if (state == "-409") { NProgress.done(); // 跳转到授权页面 const { device, uuid } = data.data; if ((this.router ?? "") != "") { this.router?.push({ name: "license", query: { device, uuid, }, }); } return data; } }, async (error: AxiosError) => { MessagePlugin.error(error.message); return Promise.reject(error); }, ); ```

## 效果演示 正常情况,按照如上步骤操作之后,访问未经过授权的服务器,会自动跳转到待授权页面,如下图: ![](images/01.png) 扫码并获取到授权码之后,可以进行 **联网授权** 或 **离线授权**
## 特殊处理 - Docker 由于使用了 `dmidecode` 命令获取主板信息,**在docker容器中无法运行该命令**,需要运行容器时做一些修改。 docker-compose.yml 部分内容 ``` yml volumes: ## 将dmidecode挂载到容器内 - "/usr/sbin/dmidecode:/usr/sbin/dmidecode" - "/dev/mem:/dev/mem" ## 设置容器的权限为root privileged: true ```