package com.jisco.ymtappoint.service.impl;

import com.alibaba.fastjson.JSONObject;
import org.springframework.http.HttpEntity;
import org.springframework.http.MediaType;
import org.springframework.http.ResponseEntity;
import org.springframework.util.LinkedMultiValueMap;
import org.springframework.util.MultiValueMap;
import org.springframework.web.client.RestTemplate;

public class GetYMTAppoint {

//    获取token接口
    String url="http://10.1.213.213:8765/oauth/token?client_id=c1&client_secret=secret&grant_type=password&username=jk-jl&password=Jl123456";

    public  String getAppointToken(){
        RestTemplate client = new RestTemplate();
//        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();

        ResponseEntity<String> entity = client.postForEntity(url, null, String.class);
        JSONObject jsonObject = JSONObject.parseObject(entity.getBody());
        return jsonObject.get("access_token").toString();
    }

    public String getAppointData(String lcdate){

        RestTemplate client = new RestTemplate();
        String ymtToken = "Bearer "+this.getAppointToken();
//        获取预约信息接口  现为测试机，后需改为一码通生产机
        String url = "http://10.1.213.213:8778/appoint/getAppointToJL?lcdate="+lcdate;
        MultiValueMap<String, String> headers = new LinkedMultiValueMap<>();
        headers.add("Content-Type", MediaType.APPLICATION_JSON_VALUE);
        headers.add("Authorization", ymtToken);
        HttpEntity<String> request = new HttpEntity<>(headers);

        ResponseEntity<String> entity = client.postForEntity(url, request, String.class);
        JSONObject jsonObject = JSONObject.parseObject(entity.getBody());
        return jsonObject.get("data").toString();
    }


}
