setDevicePowerState static method

Future<String> setDevicePowerState(
  1. String userId,
  2. String deviceId,
  3. int state
)

远程开关机 userId app用户id deviceId 绑定的设备id state 0-关机;1-开机

Implementation

static Future<String> setDevicePowerState(String userId,String deviceId, int state) async {
  Map<String,String> headers = {
    'tenantId': '10002',
    'token': SpUtil().getString(SpUtil.SP_KEY_ACCESS_TOKEN) ?? '',
    'appSource': 'Maxims',
    'reqSource': '1',
  };
  int timestamp = DateTime.now().millisecondsSinceEpoch;
  String randomStr = CipherUtil.generateRandomString(6);
  Map<String,dynamic> data = {
    'timestamp': timestamp,
    'appKey': BaseHttpConstant.APP_BUSINESS_KEY,
    'nonceStr': randomStr,
    'signVersion': '1',
    'data': {
      'userId': userId,
      'deviceId': deviceId,
      'state': state,
    },
  };
  String sign = CipherUtil.generateSignature2(data, ['data'], BaseHttpConstant.APP_BUSINESS_SECRET);
  data['sign'] = sign;
  Options options = Options(
    headers: headers,
    contentType: Headers.jsonContentType,
  );
  var result = await HttpUtils.post(true, Api.PATH_SET_DEVICE_POWER_STATE,
      data: data,
      options: options);
  return formatResponse(result);
}