import { AccessInput, BaseAccess, IsAccess, PageSearch } from '@certd/pipeline'; /** 管理页面地址:https://www.dns.com.cn/login/toLogin.do 是否有API接口,接口地址:https://api.bizcn.com/rrpservices */ @IsAccess({ name: 'xinnetconnect', title: '新网互联授权', icon: 'svg:icon-xinnet', desc: '仅支持代理账号,ip需要加入白名单', }) export class XinnetConnectAccess extends BaseAccess { /** * 授权属性配置 */ @AccessInput({ title: '用户名', component: { placeholder: '代理用户名,如:agent001', help: '新网互联的代理用户名', }, required: true, encrypt: false, }) username = ''; @AccessInput({ title: '密码', component: { name: "a-input-password", vModel: "value", placeholder: '密码', }, required: true, encrypt: true, }) password = ''; @AccessInput({ title: "测试", component: { name: "api-test", action: "onTestRequest", }, helper: "点击测试接口看是否正常", }) testRequest = true; async onTestRequest() { await this.getDomainList({ pageNo: 1, pageSize: 10, }); return "ok"; } async getDomainList(req: PageSearch): Promise { let bodyXml =` ${req.pageSize} ${req.pageNo} ` if(req.searchKey){ bodyXml += `${req.searchKey}` } const res = await this.doRequest({ url: "/domainService", bodyXml: bodyXml, service: "getDomainList", }) return res } async addDnsRecord(req: {domain:string,hostRecord:string, value:string, type:string}): Promise { const { domain,hostRecord, value, type } = req; const bodyXml =` ${domain} ${type} ${hostRecord} ${value} 10 ` const res = await this.doRequest({ url: "/addDnsRecordService", bodyXml: bodyXml, service: "addDnsRecord", }) return res } async delDnsRecord(req: {domain:string,hostRecord:string, type:string,value:string}): Promise { const { domain,hostRecord, type,value } = req; const bodyXml =` ${domain} ${type} ${hostRecord} ${value} 10 ` const res = await this.doRequest({ url: "/delDnsRecordService", bodyXml: bodyXml, service: "delDnsRecord", }) return res } buildUserXml(){ return ` ${this.username} ${this.password} ` } async doRequest(req: {bodyXml:string,service:string,url:string}) { const xml2js = await import('xml2js'); const soapRequest = ` ${this.buildUserXml()} ${req.bodyXml} `; const response = await this.ctx.http.request({ url: req.url, baseURL: "https://api.bizcn.com/rrpservices", data: soapRequest, headers: { 'Content-Type': 'text/xml; charset=utf-8', 'SOAPAction': '' // 根据WSDL,soapAction为空 }, method: "POST", returnOriginRes: true, }) // 解析SOAP响应 const parser = new xml2js.Parser({ explicitArray: false }); const result = await parser.parseStringPromise(response.data); // 提取返回结果 const soapBody = result['soap:Envelope']['soap:Body']; const keys = Object.keys(soapBody); if (keys.length === 0) { throw new Error('SOAP响应体为空'); } const addDnsRecordResponse = soapBody[keys[0]]; this.ctx.logger.info(addDnsRecordResponse) const resultData = addDnsRecordResponse.response.result; const res = { code: resultData.$.code, msg: resultData.msg } this.ctx.logger.info('操作结果:', res); if (res.code != "200") { throw new Error(res.msg + " code:" + res.code); } return resultData; } } new XinnetConnectAccess();