package com.muzhi.mt.service.impl;

import com.dingtalk.api.DefaultDingTalkClient;
import com.dingtalk.api.DingTalkClient;
import com.dingtalk.api.request.OapiV2UserGetuserinfoRequest;
import com.dingtalk.api.response.OapiV2UserGetuserinfoResponse;
import com.muzhi.mt.service.DingAccessTokenService;
import com.muzhi.mt.service.MiandengService;
import com.taobao.api.ApiException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;


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

@Service
public class MiandengServiceImpl implements MiandengService {


    @Autowired
    private DingAccessTokenService dingAccessTokenService;

    public static String result = null;

    //通过免登码获取用户信息（牧之测试架构4）
    @Override
    public String getuserinfo(String code) {

        try {
            DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/topapi/v2/user/getuserinfo");
            OapiV2UserGetuserinfoRequest req = new OapiV2UserGetuserinfoRequest();
            req.setCode(code);
            OapiV2UserGetuserinfoResponse rsp = client.execute(req, dingAccessTokenService.getMuZhiAccessToken());
            result = rsp.getBody();
            System.out.println(rsp.getBody());
        } catch (ApiException e) {
            e.printStackTrace();
        }

        return result;
    }
}
