This commit is contained in:
2021-07-08 17:32:05 +08:00
parent 1824bdb02a
commit 10ce978324
6 changed files with 103 additions and 2 deletions
@@ -34,6 +34,8 @@ public interface XcxUserInfoService {
* @return
*/
public XcxKey getOpenId(String code);
public XcxKey getOpenId(String code, String appId, String secret);
/**
* 获取有多少人查询过他们自己的故事
* @return
@@ -101,6 +101,39 @@ public class XcxUserInfoServiceImpl implements XcxUserInfoService {
return null;
}
@Override
public XcxKey getOpenId(String code, String appId, String secret) {
HttpRequest http = new HttpRequest();
//»ñÈ¡openid
HashMap<String, String> map = new HashMap<String, String>();
map.put("appid", appId);
map.put("secret", secret);
map.put("grant_type", XCXConstant.GRANT_TYPE);
map.put("js_code", code);
String result = null;
try {
result = http.get(XCXConstant.OPENID_URL, map, "utf-8");
System.out.println(result);
} catch (HttpRequestException e) {
e.printStackTrace();
}
//½âÎöresult
if(StringUtils.isNotBlank(result)){
JSONObject json = JSONObject.fromObject(result);
if(json!=null&&json.get("openid")!=null){
String openId = (json.get("openid")!=null)?json.get("openid").toString():null;
String sessionKey = (json.get("session_key")!=null)?json.get("session_key").toString():null;
XcxKey xcxKey = new XcxKey();
xcxKey.setOpenId(openId);
xcxKey.setSessionKey(sessionKey);
return xcxKey;
}
}
return null;
}
@Override
public int havaReviewStory() {