feat:微信工具添加openid获取方法

master
tangfudong 2024-03-27 14:54:07 +08:00
parent 21894f1f57
commit 404b7acb72
1 changed files with 9 additions and 0 deletions

View File

@ -33,6 +33,8 @@ import java.util.Arrays;
@Slf4j @Slf4j
public class WeChatUtil { public class WeChatUtil {
private static String authUrl="https://api.weixin.qq.com/sns/jscode2session";
public static String httpRequest(String requestUrl, String requestMethod, String output) { public static String httpRequest(String requestUrl, String requestMethod, String output) {
try { try {
URL url = new URL(requestUrl); URL url = new URL(requestUrl);
@ -66,6 +68,13 @@ public class WeChatUtil {
return ""; return "";
} }
public static String getOp(String appId, String secret, String code) {
String url=authUrl+"?appid="+appId+"&secret="+secret+"&js_code="+code+"&grant_type=authorization_code";
String ret=WeChatUtil.httpRequest(url,"GET",null);
String openid = JsonUtils.parseMap(ret).getStr("openid");
return openid;
}
public static String decryptData(String encryptDataB64, String sessionKeyB64, String ivB64) { public static String decryptData(String encryptDataB64, String sessionKeyB64, String ivB64) {
return new String( return new String(
decryptOfDiyIv( decryptOfDiyIv(