You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
121 lines
3.2 KiB
121 lines
3.2 KiB
4 years ago
|
package com.fr.plugin.zjsso.handler;
|
||
|
|
||
|
import com.fr.decision.fun.impl.BaseHttpHandler;
|
||
|
import com.fr.json.JSONObject;
|
||
|
import com.fr.plugin.transform.FunctionRecorder;
|
||
|
import com.fr.plugin.zjsso.config.PluginSimpleConfig;
|
||
|
import com.fr.plugin.zjsso.utils.*;
|
||
|
import com.fr.third.springframework.web.bind.annotation.RequestMethod;
|
||
|
import javax.servlet.http.HttpServletRequest;
|
||
|
import javax.servlet.http.HttpServletResponse;
|
||
|
import java.net.URLEncoder;
|
||
|
import java.util.HashMap;
|
||
|
import java.util.Map;
|
||
|
|
||
|
@FunctionRecorder
|
||
|
public class ZJLogin extends BaseHttpHandler {
|
||
|
|
||
|
|
||
|
public ZJLogin() {
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public RequestMethod getMethod() {
|
||
|
return RequestMethod.GET;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public String getPath() {
|
||
|
return "/zjLogin";
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public boolean isPublic() {
|
||
|
return true;
|
||
|
}
|
||
|
|
||
|
@Override
|
||
|
public void handle(HttpServletRequest req, HttpServletResponse res) throws Exception {
|
||
|
boolean isLogin = FRUtils.isLogin(req);
|
||
|
|
||
|
if(!isLogin){
|
||
|
ResponseUtils.failedResponse(res,"请先登录");
|
||
|
}
|
||
|
|
||
|
String username = FRUserUtils.getCurrentUser(req).getUserName();
|
||
|
String redirectUrl = req.getParameter("redirectUrl");
|
||
|
PluginSimpleConfig psc = PluginSimpleConfig.getInstance();
|
||
|
|
||
|
String url = psc.getLogin() + "?mobilePhone="+username+"&url="+ URLEncoder.encode(redirectUrl);
|
||
|
|
||
|
|
||
|
// String token = getToken(username,psc);
|
||
|
//
|
||
|
// String tozj = tozj(token,redirectUrl,psc);
|
||
|
|
||
|
res.sendRedirect(url);
|
||
|
}
|
||
|
|
||
|
private String tozj(String token,String rUrl, PluginSimpleConfig psc) {
|
||
|
String url = psc.getLogin();
|
||
|
String domain = psc.getDomain();
|
||
|
|
||
|
JSONObject param = new JSONObject();
|
||
|
param.put("domain",domain);
|
||
|
param.put("url",rUrl);
|
||
|
param.put("tokenId",token);
|
||
|
|
||
|
Map<String,String> header = new HashMap<String,String>();
|
||
|
header.put("Content-type","application/json;charset=utf-8");
|
||
|
|
||
|
FRUtils.FRLogInfo("str " + param.toString());
|
||
|
String result = HttpUtils.HttpPostJson(url,param.toString(),header);
|
||
|
|
||
|
if(Utils.isNullStr(result)){
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
JSONObject resultJson = new JSONObject(result);
|
||
|
int code = resultJson.getInt("code");
|
||
|
|
||
|
if(code != 200){
|
||
|
return resultJson.getString("message");
|
||
|
}
|
||
|
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
/**
|
||
|
* 获取token
|
||
|
* @param username
|
||
|
* @param psc
|
||
|
* @return
|
||
|
*/
|
||
|
private String getToken(String username,PluginSimpleConfig psc) {
|
||
|
String tokenUrl = psc.getTokenUrl()+"?mobilePhone="+username;
|
||
|
Map<String,String> header = new HashMap<String,String>();
|
||
|
header.put("Content-type","application/x-www-form-urlencoded;charset=utf-8");
|
||
|
|
||
|
String result = HttpUtils.get(tokenUrl,null,header);
|
||
|
|
||
|
if(Utils.isNullStr(result)){
|
||
|
return "";
|
||
|
}
|
||
|
|
||
|
JSONObject resultJson = new JSONObject(result);
|
||
|
int code = resultJson.getInt("code");
|
||
|
|
||
|
if(code == 200){
|
||
|
return resultJson.getString("tokenId");
|
||
|
}
|
||
|
|
||
|
FRUtils.FRLogError("获取token失败 " + resultJson.getString("message"));
|
||
|
|
||
|
return "";
|
||
|
|
||
|
}
|
||
|
|
||
|
|
||
|
}
|
||
|
|