import java.util.HashMap;
import java.util.Map;
public class Test {
public static void main(String[] args) {
String param = String.format("grant_type=authorization_code&code=%s&redirect_uri=%s&client_id=%s&client_secret=%s",
"1", "2", "3", "4");
System.out.println(param+" *********");
String ss ="access_token=FE04************************CCE2&expires_in=7776000&refresh_token=88E4************************BE14";
Map<String, String> stringStringMap = params2Map(ss);
System.out.println(stringStringMap+" ---------");
String accessToken = stringStringMap.get("access_token");
System.out.println(accessToken+" &&&&&&&&&&");
}
public static Map<String, String> params2Map(String params) {
Map<String, String> map = new HashMap<>();
String[] tmp = params.trim().split("&");
for (String s : tmp) {
System.out.println(s+" ==========");
}
for (String param : tmp) {
String[] kv = param.split("=");
for (String s : kv) {
System.out.println(s+" +++++++++");
}
if (kv.length == 2) {
map.put(kv[0], kv[1]);
}
}
return map;
}
}
grant_type=authorization_code&code=1&redirect_uri=2&client_id=3&client_secret=4 *********
access_token=FE04************************CCE2 ==========
expires_in=7776000 ==========
refresh_token=88E4************************BE14 ==========
access_token +++++++++
FE04************************CCE2 +++++++++
expires_in +++++++++
7776000 +++++++++
refresh_token +++++++++
88E4************************BE14 +++++++++
{access_token=FE04************************CCE2, refresh_token=88E4************************BE14, expires_in=7776000} ---------
FE04************************CCE2 &&&&&&&&&&
String openIdResp= "callback( {\"client_id\":\"YOUR_APPID\",\"openid\":\"YOUR_OPENID\"} )";
// String substring = openIdResp.substring(openIdResp.indexOf("{"), openIdResp.indexOf("}") + 1);
// System.out.println(substring);
JSON parse = JSONUtil.parse(openIdResp.substring(openIdResp.indexOf("{"), openIdResp.indexOf("}") + 1));
String openId = (String) parse.getByPath("openid");
System.out.println(substring);
{"client_id":"YOUR_APPID","openid":"YOUR_OPENID"}
估计是这个依赖
<dependency>
<groupId>cn.hutool</groupId>
<artifactId>hutool-all</artifactId>
<version>5.7.17</version>
</dependency>
这辈子坚持与不坚持都不可怕,怕的是独自走在坚持的道路上!!!