package com.fs.baidu.utils;

import com.alibaba.fastjson.JSONObject;
import com.fs.common.exception.base.BaseException;

import java.util.HashMap;
import java.util.Map;

public class BaiduToken {

    private static Map<Integer, String> accessTokenMap = new HashMap<>();
    private static Map<Integer, String> refreshTokenMap = new HashMap<>();

    public static JSONObject getUserAccessToken(String authCode, Integer userId) {
        Map<String, Object> param = new HashMap<>();
        param.put("appId", "dd0a366847434e037b86325517931092");
        param.put("secretKey", "9c4a058d26569ddd1786a87b1d7562d1");
        param.put("grant_type", "auth_code");
        param.put("authCode", authCode);
        param.put("userId", userId);
        JSONObject result = HttpUtils.sendPost("https://u.baidu.com/oauth/accessToken", param);
        if(result.getInteger("code") != 0){
            throw new BaseException("获取百度accessToken失败：" + result.getString("message"));
        }
        return result.getJSONObject("data");
    }

}
