package com.mortals.xhx.busiz.dingtalk.api;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.fasterxml.jackson.databind.annotation.JsonSerialize;
import com.mortals.framework.common.Rest;
import com.mortals.xhx.busiz.dingtalk.config.TalkConfiguration;
import com.mortals.xhx.busiz.dingtalk.req.DingTalkBaseReq;
import com.mortals.xhx.common.code.YesNoEnum;
import com.mortals.xhx.common.pdu.ApiRespPdu;
import lombok.extern.apachecommons.CommonsLog;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

/**
 * 钉钉相关外部接口
 *
 * @Author:
 */
@RestController
@Slf4j
public class TalkApiController {

    @Autowired
    private TalkConfiguration talkConfiguration;


    /**
     * 获取token
     *
     * @return
     */
    @PostMapping("/dingtalk/gettoken")
    public Rest<String> getToken(@RequestBody DingTalkBaseReq dingTalkBaseReq) {
        log.info("收到【getToken】请求【请求体】--> {}", JSON.toJSONString(dingTalkBaseReq));

        try {



         //   DingTalkClient client = new DefaultDingTalkClient("https://oapi.dingtalk.com/gettoken");
//            OapiGettokenRequest req = new OapiGettokenRequest();
//            req.setHttpMethod("GET");
//            OapiGettokenResponse rsp = client.execute(req);
          /*  DingTalkClient client = new DefaultDingTalkClient(talkConfiguration.getGetTokneUrl());
            OapiGettokenRequest req = new OapiGettokenRequest();
            req.setAppkey(apiKey);
            req.setAppsecret(appsecret);
            req.setHttpMethod("GET");
            OapiGettokenResponse rsp = client.execute(req);
            log.info("gettoken rsp:" + rsp.getBody());
            if (rsp.getErrcode() == 0) {
                apiRespPdu.setData(rsp.getAccessToken());
            } else {
                throw new AppException(String.format("errorCode:%s,errorMsg:%s", rsp.getErrcode(), rsp.getErrmsg()));
            }
*/
        } catch (Exception e) {
            log.error("异常", e);
            return Rest.fail(e.getMessage());
        }
        return Rest.ok();
    }


}
