package com.baichuanxin.openrestapi.service.impl;

import cn.hutool.http.HttpResponse;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSON;
import com.baichuanxin.openrestapi.service.ECService;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Service;

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

@Slf4j
@Service
public class ECServiceImpl implements ECService {


    private String getTokenRequest() {
        String accessToken = "false";
        String getTokenUrl = "http://65.26.106.115:8003/license-api-release/oauth/token";
        Map<String, Object> formDataMap = new HashMap<>();
        formDataMap.put("client_id", "linewell-oauth");
        formDataMap.put("client_secret", "linewell-mobile");
        formDataMap.put("grant_type", "password");
        formDataMap.put("scope", "readwrite");
        formDataMap.put("username", "dzzz_bajgxxxt");
        formDataMap.put("password", "Bajgxxxt_6777");
        HttpResponse execute = HttpUtil.createPost(getTokenUrl).header("Content-Type", "application/x-www-form-urlencoded")
                .form(formDataMap).execute();
        String responseBody = execute.body();
        int status = execute.getStatus();
        if (status == 200) {
            Map<String, String> resMap = JSON.parseObject(execute.body(), Map.class);
            accessToken = resMap.get("access_token");
            log.info("获取电子证照token响应体:{}", responseBody);
        }
        return accessToken;
    }
}
