package com.muzhi.mt.service.impl;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.request.OapiGettokenRequest;
import com.dingtalk.api.response.OapiGettokenResponse;
import com.muzhi.mt.service.DingAccessTokenService;
import com.taobao.api.ApiException;
import org.springframework.stereotype.Service;


/**
 * @Author ZhangKan
 * @Data 15:39
 */

@Service
public class DingAccessTokenServiceImpl implements DingAccessTokenService{

    //牧之测试架构4
    //APPKEY
    private static String APPKEY1 = "ding2katvzyqvlkunqtb";
    //APPSECRET
    private static String APPSECRET1 = "vSctQrVm5cGos0X6K86NN0A8Vv6-SmN4W_VRXjsqPqZRhZtbG6xfPATOZhPi3VBE";

    public static String accessToken1 = null;


    //茅台架构
    //APPKEY
    private static String APPKEY2 = "dingiisvte8wte8g6svq";
    //APPSECRET
    private static String APPSECRET2 = "STpfocciVDAjEI-i-ibvOd11qM3iIPYA0bplYfqgNWwmMntOxTHJ8dZMCHXVOaEN";

    public static String accessToken2 = null;


    //获取access_token的方法（牧之测试架构4）
    @Override
    public String getMuZhiAccessToken() {
        DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
        OapiGettokenRequest request = new OapiGettokenRequest();
        request.setAppkey(APPKEY1);
        request.setAppsecret(APPSECRET1);
        request.setHttpMethod("GET");
        try {
            OapiGettokenResponse response = client.execute(request);
            accessToken1 = response.getAccessToken();
            System.out.println("牧之测试架构4AccessToken：" + accessToken1);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return accessToken1;
    }

    //获取access_token的方法（茅台架构）
    @Override
    public String getMaoTaiAccessToken() {
        DefaultDingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
        OapiGettokenRequest request = new OapiGettokenRequest();
        request.setAppkey(APPKEY2);
        request.setAppsecret(APPSECRET2);
        request.setHttpMethod("GET");
        try {
            OapiGettokenResponse response = client.execute(request);
            accessToken2 = response.getAccessToken();
            System.out.println("茅台架构AccessToken：" + accessToken2);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return accessToken2;
    }
}
