⚡ 优化代码
This commit is contained in:
@@ -4,6 +4,7 @@ import cn.hutool.http.HttpRequest;
|
|||||||
import cn.hutool.http.HttpResponse;
|
import cn.hutool.http.HttpResponse;
|
||||||
import com.alibaba.fastjson.JSONArray;
|
import com.alibaba.fastjson.JSONArray;
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.JSONPath;
|
||||||
import me.zhyd.oauth.config.AuthConfig;
|
import me.zhyd.oauth.config.AuthConfig;
|
||||||
import me.zhyd.oauth.config.AuthSource;
|
import me.zhyd.oauth.config.AuthSource;
|
||||||
import me.zhyd.oauth.enums.AuthUserGender;
|
import me.zhyd.oauth.enums.AuthUserGender;
|
||||||
@@ -120,13 +121,8 @@ public class AuthLinkedinRequest extends AuthDefaultRequest {
|
|||||||
.execute();
|
.execute();
|
||||||
JSONObject emailObj = JSONObject.parseObject(emailResponse.body());
|
JSONObject emailObj = JSONObject.parseObject(emailResponse.body());
|
||||||
this.checkResponse(emailObj);
|
this.checkResponse(emailObj);
|
||||||
if (emailObj.containsKey("elements")) {
|
Object obj = JSONPath.eval(emailObj, "$['elements'][0]['handle~']['emailAddress']");
|
||||||
email = emailObj.getJSONArray("elements")
|
return null == obj ? null : (String) obj;
|
||||||
.getJSONObject(0)
|
|
||||||
.getJSONObject("handle~")
|
|
||||||
.getString("emailAddress");
|
|
||||||
}
|
|
||||||
return email;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
private String getUserName(JSONObject userInfoObject, String nameKey) {
|
private String getUserName(JSONObject userInfoObject, String nameKey) {
|
||||||
|
|||||||
@@ -1,7 +1,16 @@
|
|||||||
package me.zhyd.oauth.utils;
|
package me.zhyd.oauth.utils;
|
||||||
|
|
||||||
|
import com.alibaba.fastjson.JSON;
|
||||||
|
import com.alibaba.fastjson.JSONArray;
|
||||||
|
import com.alibaba.fastjson.JSONObject;
|
||||||
|
import com.alibaba.fastjson.JSONPath;
|
||||||
import org.junit.Test;
|
import org.junit.Test;
|
||||||
|
|
||||||
|
import java.util.ArrayList;
|
||||||
|
import java.util.HashMap;
|
||||||
|
import java.util.List;
|
||||||
|
import java.util.Map;
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
* @author yadong.zhang (yadong.zhang0415(a)gmail.com)
|
||||||
* @version 1.0
|
* @version 1.0
|
||||||
@@ -60,4 +69,22 @@ public class CustomTest {
|
|||||||
// }
|
// }
|
||||||
return stackTrace[2].getMethodName();
|
return stackTrace[2].getMethodName();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@Test
|
||||||
|
public void jsonpath(){
|
||||||
|
List<Map<String, Map<String, Object>>> list = new ArrayList<>();
|
||||||
|
|
||||||
|
Map<String, Map<String, Object>> map = new HashMap<>();
|
||||||
|
Map<String, Object> node = new HashMap<>();
|
||||||
|
node.put("emailAddress", "xxxx");
|
||||||
|
map.put("handle~", node);
|
||||||
|
list.add(map);
|
||||||
|
|
||||||
|
|
||||||
|
Map<String, Object> master = new HashMap<>();
|
||||||
|
// master.put("elements", list);
|
||||||
|
JSONObject emailObj = JSONObject.parseObject(JSON.toJSONString(master));
|
||||||
|
Object object = JSONPath.eval(emailObj, "$['elements'][0]['handle~']['emailAddress']");
|
||||||
|
System.out.println(object);
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user