위챗 오픈 id 및 세션 가져오기key
1446 단어 위챗으로 사용자 정보 얻기
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;
}
}
}