위챗 오픈 id 및 세션 가져오기key

코드에 따라 위챗 오픈 id 및session 가져오기key
import com.alibaba.druid.util.StringUtils;
import com.alibaba.fastjson.JSONObject;
import com.hegao.pdos.core.config.AdminConst;

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

public class OpenIdUtils {
    public static Map getOpenId(String code) {
        //AdminConst.GET_OPENID   https://api.weixin.qq.com/sns/jscode2session?appid=APPID&secret=SECRET&js_code=JSCODE&grant_type=authorization_code
        //AdminConst.wx_appid  appid
        //AdminConst.wx_secret  secret
        String url = AdminConst.GET_OPENID.replace("APPID", AdminConst.wx_appid).replace("SECRET", AdminConst.wx_secret).replace("JSCODE", code);
        JSONObject jsonObject = BaseRequest.doGet(url);
        System.out.println(jsonObject.toString());
        String errCode = jsonObject.getString("errcode");
        if (StringUtils.isEmpty(errCode) && !StringUtils.isEmpty(jsonObject.getString("openid").toString())) {
            String openid = jsonObject.get("openid").toString();
            String session_key = jsonObject.get("session_key").toString();
            Map param=new HashMap<>();
            param.put("session_key",session_key);
            param.put("openid",openid);
            return param;
        } else {
            return null;
        }
    }
}

좋은 웹페이지 즐겨찾기