package cn.iocoder.yudao.util;

import cn.hutool.json.JSONObject;
import cn.hutool.json.JSONUtil;
import cn.iocoder.yudao.common.WechatCommon;
import org.checkerframework.checker.units.qual.A;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.stereotype.Component;
import java.util.Map;


/**
 * @Author vinjor-m
 * @Description 微信模块工具类
 **/
@Component
public class WeChatLoginUtil {
    @Autowired
    private WechatCommon wechatCommon;

    /**
     * @param code 授权后拿到的code
     * @return net.sf.json.JSONObject
     * ---modify history---
     * Modify By             Date           Description
     * @Author PQZ
     * @Description 获取网页的token
     * @Date 17:12 2021/1/26
     **/
    public JSONObject getTokenJson(String code) {
        //请求获取网页的token
        String url = wechatCommon.getTokeUrl() + "&code=" + code + "&grant_type=authorization_code";
        NetWorkHelper helper = new NetWorkHelper();
        String response = helper.getHttpsResponse(url, "");
        return JSONUtil.parseObj(response);
    }

}
