package com.muzhi.dingtalk.test.service.impl;

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


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

@Service
public class DingAccessTokenServiceImpl implements DingAccessTokenService{
    //DingAccessTokenService

    //云璞
    //APPKEY
    private static String APPKEY = "ding3fb18v3xnh7njhql";
    //APPSECRET
    private static String APPSECRET = "U7vRU_Nao5Kz3B8lgCp9IpAfN5wsIl0FYOabSIOtwfHr8kXjyn1r27Nhu3V4VdYc";

    public static String accessToken = null;


    //牧之测试架构
//    //APPKEY
//    private static String APPKEY1 = "ding9egkigh3qrhgvupo";
//    //APPSECRET
//    private static String APPSECRET1 = "5ZZzIqNeU194KfKLJUv8iR0K67MYKSm_409BUe5G5wkmQtl4eNGsPLHVv4Z9jq4l";

    //牧之测试架构1
    //APPKEY
    private static String APPKEY1 = "dingezwch2vhdculejdp";
    //APPSECRET
    private static String APPSECRET1 = "3Tbm6FahjPKUyhtvRUdgUG-kqkOJd7Dusxcf3KxGToYnMTRByuxM30I6O9bV51s-";

    public static String accessToken1 = null;


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

    //获取access_token的方法（牧之测试架构）
    @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("牧之测试架构AccessToken：" + accessToken1);
        } catch (ApiException e) {
            e.printStackTrace();
        }
        return accessToken1;
    }
}
