You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
137 lines
4.1 KiB
137 lines
4.1 KiB
// app/service/user.js
|
|
const Service = require("egg").Service;
|
|
const parseString = require("xml2js").parseString;
|
|
const _ = require("lodash");
|
|
class HaikangweishiService extends Service {
|
|
//旋转
|
|
async continuous(params) {
|
|
let paramsTemp = {
|
|
url: `http://192.168.1.64/ISAPI/PTZCtrl/channels/${
|
|
_.get(params, ["channels"], 1) || 1
|
|
}/continuous`,
|
|
method: "PUT",
|
|
data: `<?xml version: "1.0" encoding="UTF-8"?><PTZData><pan>${_.get(
|
|
params,
|
|
["pan"],
|
|
0
|
|
)}</pan><tilt>${_.get(params, ["tilt"], 0)}</tilt></PTZData>`,
|
|
};
|
|
return await this.togetherCurl(paramsTemp);
|
|
}
|
|
//到达预置点
|
|
async goto(params) {
|
|
let paramsTemp = {
|
|
url: `http://192.168.1.64/ISAPI/PTZCtrl/channels/${
|
|
_.get(params, ["channels"], 1) || 1
|
|
}/presets/${_.get(params, ["presets"], 1) || 1}/goto`,
|
|
method: "PUT",
|
|
};
|
|
return await this.togetherCurl(paramsTemp);
|
|
}
|
|
//设置预置点
|
|
async presets(params) {
|
|
let paramsTemp = {
|
|
url: `http://192.168.1.64/ISAPI/PTZCtrl/channels/${
|
|
_.get(params, ["channels"], 1) || 1
|
|
}/presets/${_.get(params, ["presets"], 1) || 1}`,
|
|
method: "PUT",
|
|
data: `<?xml version: "1.0" encoding="UTF-8"?><PTZPreset xmlns="http://www.isapi.org/ver20/XMLSchema" version="2.0"><id>${
|
|
_.get(params, ["presets"], 1) || 1
|
|
}</id><presetName>${
|
|
_.get(
|
|
params,
|
|
["presetsName"],
|
|
"预置点 " + _.get(params, ["presets"], 1)
|
|
) || "预置点 1"
|
|
}</presetName></PTZPreset>`,
|
|
};
|
|
return await this.togetherCurl(paramsTemp);
|
|
}
|
|
//删除预置点
|
|
async delPresets(params) {
|
|
let paramsTemp = {
|
|
url: `http://192.168.1.64/ISAPI/PTZCtrl/channels/${
|
|
_.get(params, ["channels"], 1) || 1
|
|
}/presets/${_.get(params, ["presets"], 1) || 1}`,
|
|
method: "DELETE",
|
|
};
|
|
return await this.togetherCurl(paramsTemp);
|
|
}
|
|
//调焦
|
|
async zoom(params) {
|
|
let paramsTemp = {
|
|
url: `http://192.168.1.64/ISAPI/PTZCtrl/channels/${
|
|
_.get(params, ["channels"], 1) || 1
|
|
}/continuous`,
|
|
method: "PUT",
|
|
data: `<?xml version: "1.0" encoding="UTF-8"?><PTZData><zoom>${
|
|
_.get(params, ["zoom"], 0) || 0
|
|
}</zoom></PTZData>`,
|
|
};
|
|
return await this.togetherCurl(paramsTemp);
|
|
}
|
|
//聚焦
|
|
async focus(params) {
|
|
let paramsTemp = {
|
|
url: `http://192.168.1.64/ISAPI/System/Video/inputs/channels/${
|
|
_.get(params, ["channels"], 1) || 1
|
|
}/focus`,
|
|
method: "PUT",
|
|
data: `<?xml version: "1.0" encoding="UTF-8"?><FocusData><focus>${
|
|
_.get(params, ["focus"], 0) || 0
|
|
}</focus></FocusData>`,
|
|
};
|
|
return await this.togetherCurl(paramsTemp);
|
|
}
|
|
//曝光度
|
|
async iris(params) {
|
|
let paramsTemp = {
|
|
url: `http://192.168.1.64/ISAPI/System/Video/inputs/channels/${
|
|
_.get(params, ["channels"], 1) || 1
|
|
}/iris`,
|
|
method: "PUT",
|
|
data: `<?xml version: "1.0" encoding="UTF-8"?><IrisData><iris>${
|
|
_.get(params, ["iris"], 0) || 0
|
|
}</iris></IrisData>`,
|
|
};
|
|
return await this.togetherCurl(paramsTemp);
|
|
}
|
|
//统一请求
|
|
async togetherCurl(params) {
|
|
let { ctx } = this;
|
|
try {
|
|
const loginResult1 = await ctx.curl(params.url, {
|
|
method: params.method,
|
|
data: params.data,
|
|
headers: {
|
|
Cookie: this.config.cookie,
|
|
},
|
|
});
|
|
this.config.duplicateReq++;
|
|
let resData1 = {};
|
|
let resDataStr = "";
|
|
parseString(loginResult1.data.toString(), function (err, result) {
|
|
resData1 = result;
|
|
resDataStr = JSON.stringify(result);
|
|
});
|
|
if (resDataStr.indexOf("Unauthorized") === -1) {
|
|
this.config.duplicateReq = 0;
|
|
return {
|
|
haserror: false,
|
|
data: resData1,
|
|
};
|
|
} else {
|
|
await ctx.service.home.index();
|
|
if (this.config.duplicateReq < 10) {
|
|
return await this.togetherCurl(params);
|
|
} else {
|
|
return { haserror: true, msg: "请求次数过多,请稍后重试" };
|
|
}
|
|
}
|
|
} catch (error) {
|
|
return { haserror: true, msg: error };
|
|
}
|
|
}
|
|
}
|
|
|
|
module.exports = HaikangweishiService;
|
|
|