package com.fastbee.data.controller.printer.yilianyun;

import cn.hutool.json.JSONObject;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

import java.util.HashMap;
import java.util.Map;

@Component
public class YiLianYunPrintService {
    @Autowired
    private YiLianYunAuthorizationService authorizationService;
    private final String endpoint_text = "https://open-api.10ss.net/v2/print/index";
    private final String endpoint_image = "https://open-api.10ss.net/v2/pictureprint/index";


    /**
     * 文本打印
     * @param content 打印内容
     */
    public void textPrint(String content){
        YiLianYunBaseService yiLianYunBaseService = new YiLianYunBaseService();
        //构建请求参数
        // 创建一个 HashMap 来存储属性
        Map<String, Object> attributes = new HashMap<>();
        String accessToken = authorizationService.getAccessToken();
        System.err.println("accessToken:"+accessToken);
        // 添加属性到 HashMap
        Long timestamp = System.currentTimeMillis();
        attributes.put("client_id", YiLianYunUtil.clientId);
        attributes.put("sign", YiLianYunUtil.getSign(timestamp));
        attributes.put("timestamp", timestamp);
        attributes.put("id", "550e8400-e29b-41d4-a716-446655440000");
        attributes.put("access_token", accessToken);
        attributes.put("machine_code", "4004899747");
        attributes.put("origin_id", "123");
        attributes.put("content", content);
        JSONObject resp = yiLianYunBaseService.baseRequest(endpoint_text, attributes);
    }
    /**
     * 图片打印
     */
    public void imagePrint(String pictureUrl){
        YiLianYunBaseService yiLianYunBaseService = new YiLianYunBaseService();
        //构建请求参数
        // 创建一个 HashMap 来存储属性
        Map<String, Object> attributes = new HashMap<>();
        String accessToken = authorizationService.getAccessToken();
        System.err.println("accessToken:"+accessToken);
        // 添加属性到 HashMap
        Long timestamp = System.currentTimeMillis();
        attributes.put("client_id", YiLianYunUtil.clientId);
        attributes.put("sign", YiLianYunUtil.getSign(timestamp));
        attributes.put("timestamp", timestamp);
        attributes.put("id", "550e8400-e29b-41d4-a716-446655440000");
        attributes.put("access_token", accessToken);
        attributes.put("machine_code", "4004899747");
        attributes.put("origin_id", "123");
        attributes.put("picture_url", pictureUrl);
        JSONObject resp = yiLianYunBaseService.baseRequest(endpoint_image, attributes);
    }
}
