导航菜单

页面标题

页面副标题

新暖心缘 v8.1.1 - LinkingDeviceManager.java 源代码

正在查看: 新暖心缘 v8.1.1 应用的 LinkingDeviceManager.java JAVA 源代码文件

本页面展示 JAVA 反编译生成的源代码文件,支持语法高亮显示。 仅供安全研究与技术分析使用,严禁用于任何非法用途。请遵守相关法律法规。


package com.qiniu.linking;

import com.qiniu.common.Constants;
import com.qiniu.common.QiniuException;
import com.qiniu.http.Client;
import com.qiniu.http.Response;
import com.qiniu.linking.model.Device;
import com.qiniu.linking.model.DeviceHistoryListing;
import com.qiniu.linking.model.DeviceKey;
import com.qiniu.linking.model.DeviceListing;
import com.qiniu.linking.model.PatchOperation;
import com.qiniu.util.Auth;
import com.qiniu.util.Json;
import com.qiniu.util.StringMap;
import com.qiniu.util.UrlSafeBase64;
import com.tencent.qcloud.tim.uikit.utils.TUIKitConstants;

public class LinkingDeviceManager {
    private final Auth auth;
    private final Client client;
    private final String host;

    private class DeviceKeyRet {
        DeviceKey[] keys;

        private DeviceKeyRet() {
        }
    }

    public LinkingDeviceManager(Auth auth) {
        this(auth, "http://linking.qiniuapi.com");
    }

    private Response get(String str) throws QiniuException {
        Response response = this.client.get(str, this.auth.authorizationV2(str, "GET", null, null));
        if (response.isOK()) {
            return response;
        }
        throw new QiniuException(response);
    }

    private Response post(String str, StringMap stringMap) throws QiniuException {
        String str2;
        byte[] bArr = null;
        if (stringMap == null) {
            str2 = null;
        } else {
            bArr = Json.encode(stringMap).getBytes(Constants.UTF_8);
            str2 = "application/json";
        }
        Response post = this.client.post(str, bArr, this.auth.authorizationV2(str, "POST", bArr, str2), "application/json");
        if (post.isOK()) {
            return post;
        }
        throw new QiniuException(post);
    }

    public DeviceKey[] addDeviceKey(String str, String str2) throws QiniuException {
        Response post = post(String.format("%s/v1/apps/%s/devices/%s/keys", this.host, str, UrlSafeBase64.encodeToString(str2)), null);
        DeviceKeyRet deviceKeyRet = (DeviceKeyRet) post.jsonToObject(DeviceKeyRet.class);
        post.close();
        if (deviceKeyRet != null) {
            return deviceKeyRet.keys;
        }
        return null;
    }

    public DeviceKey[] cloneDeviceKey(String str, String str2, String str3, boolean z7, boolean z8, String str4) throws QiniuException {
        UrlSafeBase64.encodeToString(str2);
        Response post = post(String.format("%s/v1/apps/%s/devices/%s/keys/clone", this.host, str, UrlSafeBase64.encodeToString(str3)), new StringMap().put("fromDevice", str2).put("cleanSelfKeys", Boolean.valueOf(z7)).put("deleteDevice", Boolean.valueOf(z8)).put("deviceAccessKey", str4));
        DeviceKeyRet deviceKeyRet = (DeviceKeyRet) post.jsonToObject(DeviceKeyRet.class);
        post.close();
        if (deviceKeyRet != null) {
            return deviceKeyRet.keys;
        }
        return null;
    }

    public void createDevice(String str, String str2) throws QiniuException {
        post(String.format("%s/v1/apps/%s/devices", this.host, str), new StringMap().put("device", str2)).close();
    }

    public void deleteDevice(String str, String str2) throws QiniuException {
        String format = String.format("%s/v1/apps/%s/devices/%s", this.host, str, UrlSafeBase64.encodeToString(str2));
        Response delete = this.client.delete(format, this.auth.authorizationV2(format, "DELETE", null, null));
        if (!delete.isOK()) {
            throw new QiniuException(delete);
        }
        delete.close();
    }

    public void deleteDeviceKey(String str, String str2, String str3) throws QiniuException {
        String format = String.format("%s/v1/apps/%s/devices/%s/keys/%s", this.host, str, UrlSafeBase64.encodeToString(str2), str3);
        Response delete = this.client.delete(format, this.auth.authorizationV2(format, "DELETE", null, null));
        if (!delete.isOK()) {
            throw new QiniuException(delete);
        }
        delete.close();
    }

    public Device getDevice(String str, String str2) throws QiniuException {
        Response response = get(String.format("%s/v1/apps/%s/devices/%s", this.host, str, UrlSafeBase64.encodeToString(str2)));
        Device device = (Device) response.jsonToObject(Device.class);
        response.close();
        return device;
    }

    public Device getDeviceByAccessKey(String str) throws QiniuException {
        Response response = get(String.format("%s/v1/keys/%s", this.host, str));
        Device device = (Device) response.jsonToObject(Device.class);
        response.close();
        return device;
    }

    public DeviceListing listDevice(String str, String str2, String str3, int i8, boolean z7) throws QiniuException {
        StringMap putWhen = new StringMap().putNotEmpty("marker", str3).putNotEmpty("prefix", str2).putWhen(TUIKitConstants.Selection.LIMIT, Integer.valueOf(i8), i8 > 0).putWhen("online", Boolean.valueOf(z7), z7);
        String formString = putWhen.formString();
        if (putWhen.size() > 0) {
            formString = "?" + formString;
        }
        Response response = get(String.format("%s/v1/apps/%s/devices%s", this.host, str, formString));
        DeviceListing deviceListing = (DeviceListing) response.jsonToObject(DeviceListing.class);
        response.close();
        return deviceListing;
    }

    public DeviceHistoryListing listDeviceHistory(String str, String str2, long j8, long j9, String str3, int i8) throws QiniuException {
        Response response = get(String.format("%s/v1/apps/%s/devices/%s/historyactivity?%s", this.host, str, UrlSafeBase64.encodeToString(str2), new StringMap().putNotEmpty("marker", str3).put("start", Long.valueOf(j8)).put("end", Long.valueOf(j9)).putWhen(TUIKitConstants.Selection.LIMIT, Integer.valueOf(i8), i8 > 0).formString()));
        DeviceHistoryListing deviceHistoryListing = (DeviceHistoryListing) response.jsonToObject(DeviceHistoryListing.class);
        response.close();
        return deviceHistoryListing;
    }

    public DeviceKey[] queryDeviceKey(String str, String str2) throws QiniuException {
        Response response = get(String.format("%s/v1/apps/%s/devices/%s/keys", this.host, str, UrlSafeBase64.encodeToString(str2)));
        DeviceKeyRet deviceKeyRet = (DeviceKeyRet) response.jsonToObject(DeviceKeyRet.class);
        response.close();
        if (deviceKeyRet != null) {
            return deviceKeyRet.keys;
        }
        return null;
    }

    public Device updateDevice(String str, String str2, PatchOperation[] patchOperationArr) throws QiniuException {
        String encodeToString = UrlSafeBase64.encodeToString(str2);
        StringMap put = new StringMap().put("operations", patchOperationArr);
        String format = String.format("%s/v1/apps/%s/devices/%s", this.host, str, encodeToString);
        byte[] bytes = Json.encode(put).getBytes(Constants.UTF_8);
        Response patch = this.client.patch(format, bytes, this.auth.authorizationV2(format, "PATCH", bytes, "application/json"), "application/json");
        if (!patch.isOK()) {
            throw new QiniuException(patch);
        }
        Device device = (Device) patch.jsonToObject(Device.class);
        patch.close();
        return device;
    }

    public void updateDeviceKeyState(String str, String str2, String str3, int i8) throws QiniuException {
        post(String.format("%s/v1/apps/%s/devices/%s/keys/%s/state", this.host, str, UrlSafeBase64.encodeToString(str2), str3), new StringMap().put("state", Integer.valueOf(i8))).close();
    }

    public LinkingDeviceManager(Auth auth, String str) {
        this(auth, str, new Client());
    }

    public LinkingDeviceManager(Auth auth, String str, Client client) {
        this.auth = auth;
        this.host = str;
        this.client = client;
    }

    public void createDevice(String str, Device device) throws QiniuException {
        StringMap stringMap = new StringMap();
        stringMap.put("device", device.getDeviceName());
        stringMap.put("segmentExpireDays", Integer.valueOf(device.getSegmentExpireDays()));
        stringMap.put("device", device.getDeviceName());
        stringMap.put("segmentExpireDays", Integer.valueOf(device.getSegmentExpireDays()));
        stringMap.put("uploadMode", Integer.valueOf(device.getUploadMode()));
        stringMap.put("meta", device.getMeta());
        stringMap.put("sdcardRotatePolicy", Integer.valueOf(device.getSdcardRotatePolicy()));
        stringMap.put("sdcardRotateValue", Integer.valueOf(device.getSdcardRotateValue()));
        stringMap.put("type", Integer.valueOf(device.getType()));
        stringMap.put("maxChannel", Integer.valueOf(device.getMaxChannel()));
        stringMap.put("channels", device.getChannels());
        post(String.format("%s/v1/apps/%s/devices", this.host, str), stringMap).close();
    }
}