//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//
package com.jeequan.jeepay.thirdparty.device.printer.ylyPrinter.sdk;

import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;
import com.jeequan.jeepay.core.exception.BizException;
import com.jeequan.jeepay.core.model.device.YlyParams;
import lombok.extern.slf4j.Slf4j;

import java.net.URLEncoder;
import java.util.HashMap;
import java.util.Map;
import java.util.UUID;

@Slf4j
public class RequestMethod {
    private static String example = "{\"error\":\"20\",\"error_description\":\"success\",\"body\":\"未完成初始化\"}";
    public String clientId;
    public String clientSecret;

    public String getClientId() {
        return clientId;
    }

    public void setClientId(String clientId) {
        this.clientId = clientId;
    }

    public String getClientSecret() {
        return clientSecret;
    }

    public void setClientSecret(String clientSecret) {
        this.clientSecret = clientSecret;
    }

    private static final RequestMethod singleton = new RequestMethod();

    public RequestMethod() {
    }

    public static RequestMethod getInstance() {
        return singleton;
    }

    public void init(String client_id, String client_secret) {
        clientId = client_id;
        clientSecret = client_secret;
    }

    private boolean CCIsNull(String client_id, String client_secret) {
        return clientId != null && clientSecret != null && !clientId.equals("") && !clientSecret.equals("");
    }

    public String getCodeOpen(String redirect_uri) {
        return clientId != null && !clientId.equals("") ? UtilUrl.openType + "?response_type=code&client_id=" + clientId + "&redirect_uri=" + redirect_uri + "&state=1" : example;
    }

    public String getOpenAccessToken(String code) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("client_id", clientId);
            paramMap.put("grant_type", "authorization_code");
            paramMap.put("sign", sign);
            paramMap.put("code", code);
            paramMap.put("scope", "all");
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            return HttpRequest.sendPost(UtilUrl.freeType, paramMap);
        } else {
            return example;
        }
    }

    public String getAccessToken() throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("client_id", clientId);
            paramMap.put("grant_type", "client_credentials");
            paramMap.put("sign", sign);
            paramMap.put("scope", "all");
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            return HttpRequest.sendPost(UtilUrl.freeType, paramMap);
        } else {
            return example;
        }
    }

    public String getRefreshAccessToken(String refresh_token) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("refresh_token", refresh_token);
            paramMap.put("grant_type", "refresh_token");
            paramMap.put("scope", "all");
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.freeType, paramMap);
        } else {
            return example;
        }
    }

    public String addPrinter(String machine_code, String msign, String access_token) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("machine_code", machine_code);
            paramMap.put("msign", msign);
            paramMap.put("access_token", access_token);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.addPrinter, paramMap);
        } else {
            return example;
        }
    }

    public String addPrinter(String machine_code, String msign, String access_token, String phone, String print_name) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("machine_code", machine_code);
            paramMap.put("msign", msign);
            paramMap.put("access_token", access_token);
            paramMap.put("phone", phone);
            paramMap.put("print_name", print_name);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.addPrinter, paramMap);
        } else {
            return example;
        }
    }

    public String scanCodeModel(String machine_code, String msign) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("machine_code", machine_code);
            paramMap.put("msign", msign);
            paramMap.put("scope", "all");
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.scanCodeModel, paramMap);
        } else {
            return example;
        }
    }

    public String scanCodeModel_msign(String machine_code, String msign) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("machine_code", machine_code);
            paramMap.put("msign", msign);
            paramMap.put("scope", "all");
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.scanCodeModel, paramMap);
        } else {
            return example;
        }
    }

    public String printIndex(String access_token, String machine_code, String content, String origin_id) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("content", content);
            paramMap.put("origin_id", origin_id);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("idempotence", "0");
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printIndex, paramMap);
        } else {
            return example;
        }
    }

    public String picturePrintIndex(String access_token, String machine_code, String picture_url, String origin_id) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("picture_url", URLEncoder.encode(picture_url, "UTF-8"));
            paramMap.put("origin_id", origin_id);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.picturePrintIndex, paramMap);
        } else {
            return example;
        }
    }

    public String expressPrintIndex(String access_token, String machine_code, String content, String origin_id) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("content", content);
            paramMap.put("origin_id", origin_id);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.expressPrintIndex, paramMap);
        } else {
            return example;
        }
    }

    public String printerSetVoice(String access_token, String machine_code, String content, String is_file, String aid, String origin_id) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("content", content);
            paramMap.put("is_file", is_file);
            paramMap.put("aid", aid);
            paramMap.put("origin_id", origin_id);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printerSetVoice, paramMap);
        } else {
            return example;
        }
    }

    public String printerDeleteVoice(String access_token, String machine_code, String aid, String origin_id) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("aid", aid);
            paramMap.put("origin_id", origin_id);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printerDeleteVoice, paramMap);
        } else {
            return example;
        }
    }

    public String printerDeletePrinter(String access_token, String machine_code) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printerDeletePrinter, paramMap);
        } else {
            return example;
        }
    }

    public String printMenuAddPrintMenu(String access_token, String machine_code, String content) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("content", content);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printMenuAddPrintMenu, paramMap);
        } else {
            return example;
        }
    }

    public String printShutdownRestart(String access_token, String machine_code, String response_type) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("response_type", response_type);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printShutdownRestart, paramMap);
        } else {
            return example;
        }
    }

    public String printSetSound(String access_token, String machine_code, String response_type, String voice) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("response_type", response_type);
            paramMap.put("voice", voice);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printSetSound, paramMap);
        } else {
            return example;
        }
    }

    public String printPrintInfo(String access_token, String machine_code) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printPrintInfo, paramMap);
        } else {
            return example;
        }
    }

    public String printGetVersion(String access_token, String machine_code) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printGetVersion, paramMap);
        } else {
            return example;
        }
    }

    public String printCancelAll(String access_token, String machine_code) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printCancelAll, paramMap);
        } else {
            return example;
        }
    }

    public String printCancelOne(String access_token, String machine_code, String order_id) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("order_id", order_id);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printCancelOne, paramMap);
        } else {
            return example;
        }
    }

    public String printSetIcon(String access_token, String machine_code, String img_url) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("img_url", img_url);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printSetIcon, paramMap);
        } else {
            return example;
        }
    }

    public String printDeleteIcon(String access_token, String machine_code) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printDeleteIcon, paramMap);
        } else {
            return example;
        }
    }

    public String printBtnPrint(String access_token, String machine_code, String response_type) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("response_type", response_type);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printBtnPrint, paramMap);
        } else {
            return example;
        }
    }

    public String printGetOrder(String access_token, String machine_code, String response_type) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("response_type", response_type);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printGetOrder, paramMap);
        } else {
            return example;
        }
    }

    public String oauthSetPushUrl(String access_token, String machine_code, String cmd, String url, String status) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("cmd", cmd);
            paramMap.put("url", url);
            paramMap.put("status", status);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.oauthSetPushUrl, paramMap);
        } else {
            return example;
        }
    }

    public String printerGetOrderStatus(String access_token, String machine_code, String order_id) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("order_id", order_id);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printerGetOrderStatus, paramMap);
        } else {
            return example;
        }
    }

    public String printerGetOrderPagingList(String access_token, String machine_code, String page_index, String page_size) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("page_index", page_index);
            paramMap.put("page_size", page_size);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printerGetOrderPagingList, paramMap);
        } else {
            return example;
        }
    }

    public String printerGetPrintStatus(String access_token, String machine_code) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printerGetPrintStatus, paramMap);
        } else {
            return example;
        }
    }

    public String printerSetKeywords(String access_token, String machine_code, String keys, String type, String content) throws Exception {
        if (CCIsNull(clientId, clientSecret)) {
            String timestamp = Utils.getTimestamp();
            String signMD5 = clientId + timestamp + clientSecret;
            String sign = Utils.getMD5Str(signMD5);
            Map<String, String> paramMap = new HashMap();
            paramMap.put("access_token", access_token);
            paramMap.put("machine_code", machine_code);
            paramMap.put("client_id", clientId);
            paramMap.put("timestamp", timestamp);
            paramMap.put("id", UUID.randomUUID().toString());
            paramMap.put("keys", keys);
            paramMap.put("type", type);
            paramMap.put("content", content);
            paramMap.put("sign", sign);
            return HttpRequest.sendPost(UtilUrl.printerSetKeywords, paramMap);
        } else {
            return example;
        }
    }

    /** 设备解绑 **/
    public String printerDeletePrinter(YlyParams.ProviderParams providerParams, YlyParams.DeviceParams printConfig) {
        try {
            Map<String, Object> paramMap = new HashMap();
            return createPost(UtilUrl.printerDeletePrinter, paramMap, providerParams, printConfig);
        }catch (BizException e) {
            throw new BizException(e.getMessage());
        }
    }

    /** LOGO删除 **/
    public String printDeleteIcon(YlyParams.ProviderParams providerParams, YlyParams.DeviceParams printConfig) {
        try {
            Map<String, Object> paramMap = new HashMap();
            return createPost(UtilUrl.printDeleteIcon, paramMap, providerParams, printConfig);
        }catch (BizException e) {
            throw new BizException(e.getMessage());
        }
    }

    /** 设备绑定 **/
    public String addPrinter(YlyParams.ProviderParams providerParams, YlyParams.DeviceParams printConfig) {
        try {
            Map<String, Object> paramMap = new HashMap();
            paramMap.put("msign", printConfig.getDeviceKey());
            return createPost(UtilUrl.addPrinter, paramMap, providerParams, printConfig);
        }catch (BizException e) {
            throw new BizException(e.getMessage());
        }
    }

    /** 设置打印logo **/
    public String printSetIcon(YlyParams.ProviderParams providerParams, YlyParams.DeviceParams printConfig) {
        try {
            Map<String, Object> paramMap = new HashMap();
            paramMap.put("img_url", providerParams.getPrintSetIcon());
            return createPost(UtilUrl.printSetIcon, paramMap, providerParams, printConfig);
        }catch (BizException e) {
            throw new BizException(e.getMessage());
        }
    }

    /** 设备状态查询 **/
    public String printerGetPrintStatus(YlyParams.ProviderParams providerParams, YlyParams.DeviceParams printConfig) {
        try {
            Map<String, Object> paramMap = new HashMap();
            return createPost(UtilUrl.printerGetPrintStatus, paramMap, providerParams, printConfig);
        }catch (BizException e) {
            throw new BizException(e.getMessage());
        }
    }

    /** 配置关键词 **/
    public String printerSetKeywords(YlyParams.ProviderParams providerParams, YlyParams.DeviceParams printConfig, String keys, String type, String content) {
        try {
            Map<String, Object> paramMap = new HashMap();
            paramMap.put("keys", keys);
            paramMap.put("type", type);
            paramMap.put("content", content);
            return createPost(UtilUrl.printerSetKeywords, paramMap, providerParams, printConfig);
        }catch (BizException e) {
            throw new BizException(e.getMessage());
        }
    }

    /** 文本打印 **/
    public String printIndex(YlyParams.ProviderParams providerParams, YlyParams.DeviceParams printConfig, String content, String origin_id) {
        try {
            Map<String, Object> paramMap = new HashMap();
            paramMap.put("content", content);
            paramMap.put("origin_id", origin_id);
            paramMap.put("idempotence", "0");
            return createPost(UtilUrl.printIndex, paramMap, providerParams, printConfig);
        }catch (BizException e) {
            throw new BizException(e.getMessage());
        }
    }

    /** 取消打印（全量） **/
    public String printCancelAll(YlyParams.ProviderParams providerParams, YlyParams.DeviceParams printConfig) {
        try {
            Map<String, Object> paramMap = new HashMap();
            return createPost(UtilUrl.printCancelAll, paramMap, providerParams, printConfig);
        }catch (BizException e) {
            throw new BizException(e.getMessage());
        }
    }

    /** 发送请求 **/
    public String createPost(String reqUrl, Map<String, Object> params, YlyParams.ProviderParams providerParams, YlyParams.DeviceParams printConfig) {
        String timestamp = Utils.getTimestamp();
        String signMD5 = providerParams.getClientId() + timestamp + providerParams.getClientSecret();
        String sign = Utils.getMD5Str(signMD5);

        params.put("machine_code", printConfig.getDeviceNo());
        params.put("access_token", providerParams.getAccessToken());
        params.put("client_id", providerParams.getClientId());
        params.put("timestamp", timestamp);
        params.put("id", UUID.randomUUID().toString());
        params.put("sign", sign);

        log.info("【易联云打印】-->>> 请求地址：{}， 请求参数：{}", reqUrl, params);
        String result = HttpUtil.createPost(reqUrl).body(JSONObject.toJSONString(params)).execute().body();
        log.info("【易联云打印】-->>> 响应结果：{}", result);
        return result;
    }
}
