2025-12-31 17:01:37 +08:00
|
|
|
|
import { IsAccess, AccessInput, BaseAccess } from "@certd/pipeline";
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
|
* 这个注解将注册一个授权配置
|
|
|
|
|
|
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
|
|
|
|
|
*/
|
|
|
|
|
|
@IsAccess({
|
|
|
|
|
|
name: "yidunrcdn",
|
|
|
|
|
|
title: "易盾rcdn授权",
|
|
|
|
|
|
icon: "material-symbols:shield-outline",
|
|
|
|
|
|
desc: "易盾CDN,每月免费30G,[注册即领](https://rhcdn.yiduncdn.com/register?code=8mn536rrzfbf8)",
|
|
|
|
|
|
})
|
|
|
|
|
|
export class YidunRcdnAccess extends BaseAccess {
|
|
|
|
|
|
@AccessInput({
|
|
|
|
|
|
title: "账户",
|
|
|
|
|
|
component: {
|
|
|
|
|
|
placeholder: "手机号",
|
|
|
|
|
|
},
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
encrypt: true,
|
|
|
|
|
|
})
|
|
|
|
|
|
username = "";
|
|
|
|
|
|
|
|
|
|
|
|
@AccessInput({
|
|
|
|
|
|
title: "密码",
|
|
|
|
|
|
component: {
|
|
|
|
|
|
placeholder: "password",
|
|
|
|
|
|
},
|
|
|
|
|
|
required: true,
|
|
|
|
|
|
encrypt: true,
|
|
|
|
|
|
})
|
|
|
|
|
|
password = "";
|
2026-02-15 22:45:22 +08:00
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@AccessInput({
|
|
|
|
|
|
title: "测试",
|
|
|
|
|
|
component: {
|
|
|
|
|
|
name: "api-test",
|
|
|
|
|
|
action: "onTestRequest",
|
|
|
|
|
|
},
|
|
|
|
|
|
helper: "点击测试接口看是否正常",
|
|
|
|
|
|
})
|
|
|
|
|
|
testRequest = true;
|
|
|
|
|
|
|
|
|
|
|
|
async onTestRequest() {
|
|
|
|
|
|
const token = await this.getLoginToken();
|
|
|
|
|
|
await this.getDomainList(token);
|
|
|
|
|
|
return "ok";
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getDomainList(loginRes: any) {
|
|
|
|
|
|
const url = "https://rhcdn.yiduncdn.com/CdnDomain/queryForDatatables";
|
|
|
|
|
|
const data = {
|
|
|
|
|
|
draw: 1,
|
|
|
|
|
|
start: 0,
|
|
|
|
|
|
length: 1000,
|
|
|
|
|
|
search: {
|
|
|
|
|
|
value: "",
|
|
|
|
|
|
regex: false,
|
|
|
|
|
|
},
|
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
|
|
const res = await this.doRequest(url, loginRes, data);
|
|
|
|
|
|
return res.data?.data;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async doRequest(url: string, loginRes: any, data: any) {
|
|
|
|
|
|
const http = this.ctx.http;
|
|
|
|
|
|
const res: any = await http.request({
|
|
|
|
|
|
url,
|
|
|
|
|
|
method: "POST",
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
Cookie: `JSESSIONID=${loginRes.jsessionId};kuocai_cdn_token=${loginRes.token}`,
|
|
|
|
|
|
},
|
|
|
|
|
|
data,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!res.success) {
|
|
|
|
|
|
throw new Error(res.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
return res;
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
async getLoginToken() {
|
|
|
|
|
|
const access: YidunRcdnAccess = this
|
|
|
|
|
|
const url = "https://rhcdn.yiduncdn.com/login/loginUser";
|
|
|
|
|
|
const data = {
|
|
|
|
|
|
userAccount: access.username,
|
|
|
|
|
|
userPwd: access.password,
|
|
|
|
|
|
remember: true,
|
|
|
|
|
|
};
|
|
|
|
|
|
const http = this.ctx.http;
|
|
|
|
|
|
const res: any = await http.request({
|
|
|
|
|
|
url,
|
|
|
|
|
|
method: "POST",
|
|
|
|
|
|
data,
|
|
|
|
|
|
headers: {
|
|
|
|
|
|
"Content-Type": "application/x-www-form-urlencoded",
|
|
|
|
|
|
},
|
|
|
|
|
|
returnOriginRes: true,
|
|
|
|
|
|
});
|
|
|
|
|
|
if (!res.data?.success) {
|
|
|
|
|
|
throw new Error(res.data?.message);
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
const jsessionId = this.ctx.utils.request.getCookie(res, "JSESSIONID");
|
|
|
|
|
|
const token = res.data?.data;
|
|
|
|
|
|
return {
|
|
|
|
|
|
jsessionId,
|
|
|
|
|
|
token,
|
|
|
|
|
|
};
|
|
|
|
|
|
}
|
2025-12-31 17:01:37 +08:00
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
new YidunRcdnAccess();
|