mirror of
https://github.com/certd/certd.git
synced 2026-05-15 04:27:31 +08:00
perf: 修复西数解析记录添加失败的bug,支持部署证书到西数虚拟主机
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
import { HttpRequestConfig } from '@certd/basic';
|
||||
import { IsAccess, AccessInput, BaseAccess } from '@certd/pipeline';
|
||||
|
||||
import qs from 'qs';
|
||||
/**
|
||||
* 这个注解将注册一个授权配置
|
||||
* 在certd的后台管理系统中,用户可以选择添加此类型的授权
|
||||
@@ -55,7 +56,7 @@ export class WestAccess extends BaseAccess {
|
||||
component: {
|
||||
placeholder: '账户级别的key,对整个账户都有管理权限',
|
||||
},
|
||||
helper: '账户级别的key,对整个账户都有管理权限\n前往https://www.west.cn/manager/API/APIconfig.asp,手动设置“api连接密码”',
|
||||
helper: '账户级别的key,对整个账户都有管理权限\n前往[API接口配置](https://www.west.cn/manager/API/APIconfig.asp),手动设置“api连接密码”',
|
||||
encrypt: true,
|
||||
required: false,
|
||||
mergeScript: `
|
||||
@@ -88,6 +89,100 @@ export class WestAccess extends BaseAccess {
|
||||
`,
|
||||
})
|
||||
apidomainkey = '';
|
||||
|
||||
|
||||
@AccessInput({
|
||||
title: "测试",
|
||||
component: {
|
||||
name: "api-test",
|
||||
action: "TestRequest"
|
||||
},
|
||||
helper: "点击测试接口是否正常"
|
||||
})
|
||||
testRequest = true;
|
||||
|
||||
async onTestRequest() {
|
||||
await this.getDomainList();
|
||||
return "ok";
|
||||
}
|
||||
|
||||
|
||||
async getDomainList() {
|
||||
const res = await this.doRequest({
|
||||
url: '/v2/domain',
|
||||
method: 'GET',
|
||||
data:{
|
||||
act:'getdomains',
|
||||
limit:1,
|
||||
page:1
|
||||
}
|
||||
});
|
||||
return res;
|
||||
}
|
||||
|
||||
|
||||
|
||||
public async doRequest(req: HttpRequestConfig) {
|
||||
let { url, method, data } = req;
|
||||
if (data == null) {
|
||||
data = {};
|
||||
}
|
||||
if (!method) {
|
||||
method = 'POST';
|
||||
}
|
||||
|
||||
if (this.scope === 'account') {
|
||||
/**
|
||||
* token text 身份验证字符串,取值为:md5(username+api_password+timestamp),其中:
|
||||
username:您在我司注册的用户名。
|
||||
api_password:您设置的API密码。您可登录官网管理中心,在“代理商管理”-<API接口配置>""页面查看您的api密码。
|
||||
timestamp:当前时间的毫秒时间戳。
|
||||
将字符串username与字符串api_password连接,再与timestamp连接,然后将生成的字符串进行md5求值,md5算法要求为:
|
||||
32位16进制字符串,小写格式。
|
||||
身份验证串有效期10分钟。
|
||||
|
||||
比如,您的用户名为:zhangsan,您的API密码为:5dh232kfg!* ,当前毫秒时间戳为:1554691950854,则:
|
||||
token=md5(zhangsan + 5dh232kfg!* + 1554691950854)=cfcd208495d565ef66e7dff9f98764da
|
||||
*/
|
||||
// data.apikey = this.ctx.utils.hash.md5(this.apikey);
|
||||
data.username = this.username;
|
||||
const timestamp = new Date().getTime();
|
||||
const token = this.ctx.utils.hash.md5(`${this.username}${this.apikey}${timestamp}`).toLowerCase();
|
||||
data.token = token;
|
||||
data.time = timestamp;
|
||||
} else {
|
||||
data.apidomainkey = this.apidomainkey;
|
||||
}
|
||||
|
||||
|
||||
const headers = {}
|
||||
const body: any = {}
|
||||
if (method.toUpperCase() === 'POST') {
|
||||
headers['Content-Type'] = 'application/x-www-form-urlencoded';
|
||||
body.data = data
|
||||
} else if (method.toUpperCase() === 'GET') {
|
||||
let queryString = '';
|
||||
if (method.toUpperCase() === 'GET') {
|
||||
queryString = qs.stringify(data);
|
||||
}
|
||||
url = `${url}?${queryString}`
|
||||
}
|
||||
|
||||
|
||||
const res = await this.ctx.http.request<any, any>({
|
||||
baseURL: 'https://api.west.cn/api',
|
||||
url,
|
||||
method,
|
||||
...body,
|
||||
headers,
|
||||
});
|
||||
this.ctx.logger.info(`request ${url} ${method} res:${JSON.stringify(res)}`);
|
||||
if (res.msg !== 'success' && res.result!= 200) {
|
||||
throw new Error(`${JSON.stringify(res.msg)}`);
|
||||
}
|
||||
return res;
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
new WestAccess();
|
||||
|
||||
Reference in New Issue
Block a user