zengh
2022-05-16 63ad2c3598400370dd7da5534659fd7e768a0a4a
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
function HkDevice(appKey, appSecret) {
  this.appKey = appKey; //在萤石云获取
  this.appSecret = appSecret; //在萤石云获取
  this.accessToken = null;
  this.livelist = null;
  this.devicelist = null;
  this.cameralist = null;
  this.post = function(url, data, success) {
    jQuery.ajax({
      sender: this,
      type: "POST",
      url: url,
      data: data,
      dataType: "json",
      success: function(data) {
        success(this.sender, data);
      }
    });
  };
 
  /**
   * 根据appKey和secret获取accessToken
   * @param {function} ret 异步回调请求结果
   */
  this.getAccessToken = function(ret) {
    this.post(
      "https://open.ys7.com/api/lapp/token/get",
      { appKey: this.appKey, appSecret: this.appSecret },
      function(sender, data) {
        if (data.code == "200") {
          sender.accessToken = data.data.accessToken;
        }
        ret(data);
      }
    );
  };
 
  /**
   * 获取用户下直播视频列表
   * @param {function} ret 异步回调请求结果
   */
  this.getLiveVideoList = function(ret) {
    this.post(
      "https://open.ys7.com/api/lapp/live/video/list",
      { accessToken: this.accessToken, pageStart: "0", pageSize: "50" },
      function(sender, data) {
        if (data.code == "200") {
          sender.livelist = data.data;
        }
        ret(data);
      }
    );
  };
 
  /**
   * 获取设备列表
   * @param {function} ret 异步回调请求结果
   */
  this.getDeviceList = function(ret) {
    this.post(
      "https://open.ys7.com/api/lapp/device/list",
      { accessToken: this.accessToken, pageStart: "0", pageSize: "50" },
      function(sender, data) {
        if (data.code == "200") {
          sender.devicelist = data.data;
        }
        ret(data);
      }
    );
  };
 
  /**
   * 获取摄像头列表
   * @param {function} ret 异步回调请求结果
   */
  this.getCamerasList = function(ret) {
    var mPageStart = "0";
    var mPageStartIndex = 0;
    var mCamerasList = {
      code: "200",
      data: []
    };
    var cl_this = this;
 
    function mGetCamerasList() {
      cl_this.post(
        "https://open.ys7.com/api/lapp/camera/list",
        {
          accessToken: cl_this.accessToken,
          pageStart: mPageStart,
          pageSize: "50"
        },
        function(sender, data) {
          if (data.code == "200") {
            mCamerasList.data = mCamerasList.data.concat(data.data);
            mPageStartIndex++;
            if (data.page.total > mPageStartIndex * 50) {
              mPageStart = mPageStartIndex + "";
              mGetCamerasList();
            } else {
              sender.cameralist = mCamerasList.data;
              ret(mCamerasList);
            }
          }
        }
      );
    }
 
    mGetCamerasList();
  };
 
  /**
   * 开始云台控制
   * @param {Object} option
   * {deviceSerial:设备序列号,
   * channelNo:通道号,
   * direction:镜像方向:操作命令:0-上,1-下,2-左,3-右,4-左上,5-左下,6-右上,7-右下,8-放大,9-缩小,10-近焦距,11-远焦距。   ,
   * speed:云台速度:0-慢,1-适中,2-快}
   * @param {function} ret 异步回调请求结果
   */
  this.setPtzTurn = function(option, ret) {
    if (
      !(
        option.deviceSerial &&
        option.channelNo &&
        option.direction != undefined &&
        option.speed
      )
    ) {
      ret();
      return;
    }
    this.post(
      "https://open.ys7.com/api/lapp/device/ptz/start",
      {
        accessToken: this.accessToken,
        deviceSerial: option.deviceSerial,
        channelNo: option.channelNo,
        direction: option.direction,
        speed: option.speed
      },
      function(sender, data) {
        if (data.code == "200") {
        }
        ret(data);
      }
    );
  };
 
  /**
   * 停止云台控制
   * @param {Object} option
   * {deviceSerial:设备序列号,
   * channelNo:通道号}
   * @param {function} ret 异步回调请求结果
   */
  this.setPtzStop = function(option, ret) {
    if (!(option.deviceSerial && option.channelNo)) {
      ret();
      return;
    }
    this.post(
      "https://open.ys7.com/api/lapp/device/ptz/stop",
      {
        accessToken: this.accessToken,
        deviceSerial: option.deviceSerial,
        channelNo: option.channelNo
      },
      function(sender, data) {
        if (data.code == "200") {
        }
        ret(data);
      }
    );
  };
  /**
   * 镜像翻转
   * @param {Object} option
   * {deviceSerial:设备序列号,
   * channelNo:通道号,
   * command:镜像方向:0-上下, 1-左右, 2-中心}
   * @param {function} ret 异步回调请求结果
   */
  this.setPtzMirror = function(option, ret) {
    if (!(option.deviceSerial && option.channelNo && option.command)) {
      ret();
      return;
    }
    this.post(
      "https://open.ys7.com/api/lapp/device/ptz/stop",
      {
        accessToken: this.accessToken,
        deviceSerial: option.deviceSerial,
        channelNo: option.channelNo,
        command: option.command
      },
      function(sender, data) {
        if (data.code == "200") {
        }
        ret(data);
      }
    );
  };
 
  /**
   * 根据时间获取历史影像
   * @param {Object} option
   * {deviceSerial:设备序列号,
   * channelNo:通道号,
   * startTime:起始时间,时间格式为:1378345128000。非必选,默认为当天0点
   * endTime:结束时间,时间格式为:1378345128000。非必选,默认为当前时间
   * recType:回放源,0-系统自动选择,1-云存储,2-本地录像。非必选,默认为0
   * @param {function} ret 异步回调请求结果
   */
  this.getPlaybackRecord = function(option, ret) {
    if (!option.deviceSerial) {
      ret();
      return;
    }
    this.post(
      "https://open.ys7.com/api/lapp/video/by/time",
      {
        accessToken: this.accessToken,
        deviceSerial: option.deviceSerial,
        channelNo: option.channelNo,
        //"startTime":option.startTime,
        //"endTime":option.endTime,
        recType: 0
      },
      function(sender, data) {
        if (data.code == "200") {
        }
        ret(data);
      }
    );
  };
}