package org.dromara.web.common;


import cn.hutool.http.HttpRequest;
import cn.hutool.http.HttpUtil;
import com.alibaba.fastjson.JSONObject;

/**
 * @author Maosw
 */
public class WxXcxUtils {

    static String appid = "wxf1d78a0b58fc890c";
    static String secret = "e1a3e888471d48addf1a23e4c9ea7f84";

    public static String getAccessToken(){
        String url = "https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid="+appid+"&secret="+secret;
        String result = HttpUtil.get(url);
        JSONObject jsonObject = JSONObject.parseObject(result);
        return jsonObject.get("access_token").toString();
    }

    public static JSONObject getUserPhoneNumber(String code){
        String accessToken = getAccessToken();
        String url = "https://api.weixin.qq.com/wxa/business/getuserphonenumber?access_token="+accessToken;

        JSONObject json = new JSONObject();
        json.put("code", code);
        String result = HttpRequest.post(url).body(json.toString()).execute().body();

        JSONObject jsonObject = JSONObject.parseObject(result);
        return jsonObject;
    }

}
