package com.mortals.xhx.busiz.web;

import cn.hutool.core.codec.Base64;
import cn.hutool.core.util.StrUtil;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.mortals.framework.service.ILogService;
import com.mortals.framework.service.impl.FileLogServiceImpl;
import com.mortals.xhx.busiz.req.TestReq;
import com.mortals.xhx.busiz.rsp.ApiResp;
import com.mortals.xhx.busiz.rsp.DeviceResp;
import com.mortals.xhx.common.code.ApiRespCodeEnum;
import com.mortals.xhx.common.utils.ImgUtils;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import java.io.File;

/**
 * 设备
 *
 * @author: zxfei
 * @date: 2021/8/24 20:28
 */
@RestController
@Slf4j
@RequestMapping("/test")
public class TestSendMsgController {
    @Autowired
    protected ILogService logService = FileLogServiceImpl.getInstance();

    /**
     * 发送日志消息
     *
     * @param req
     * @return
     */
    @PostMapping("log")
    public String register(@RequestBody TestReq req) {
        log.info("【测试消息】【请求体】-->  " + JSONObject.toJSONString(req));
        ApiResp<DeviceResp> rsp = new ApiResp<>();
        rsp.setCode(ApiRespCodeEnum.SUCCESS.getValue());


        log.info("响应【设备注册】【响应体】-->  " + JSONObject.toJSONString(rsp));
        return JSON.toJSONString(rsp);
    }


    public static void main(String[] args) {

        String resp = HttpUtil.get("http://59.225.206.13:8331/oauth-pro/admin-pro/sys/randomImage/1675827431800?_t=1675827431");
        JSONObject jsonObject = JSON.parseObject(resp);

        //  log.info("resp:{}",resp);
        log.info("result:{}", jsonObject.get("result"));
        String OriginalImg = "F:\\pics\\2.jpg";
        String ocrResult = "F:\\pics\\2-1.jpg";
        Base64.decodeToFile(StrUtil.replace(jsonObject.get("result").toString(),"data:image/jpg;base64,",""), new File(OriginalImg));
        ImgUtils.removeBackground(OriginalImg, ocrResult);

       // log.info(code);
/*

        //原始验证码地址

        //识别样本输出地址
        String ocrResult = "F:\\pics\\2.jpg";

        //测试登录
        //获取并识别验证码
        ImgUtils.removeBackground(OriginalImg, ocrResult);
*/


    }


}
