commit
a7f2a1af91
20 changed files with 2457 additions and 0 deletions
@ -0,0 +1,6 @@
|
||||
# open-JSD-10364 |
||||
|
||||
JSD-10364 单点集成和用户集成\ |
||||
免责说明:该源码为第三方爱好者提供,不保证源码和方案的可靠性,也不提供任何形式的源码教学指导和协助!\ |
||||
仅作为开发者学习参考使用!禁止用于任何商业用途!\ |
||||
为保护开发者隐私,开发者信息已隐去!若原开发者希望公开自己的信息,可联系【pioneer】处理。 |
@ -0,0 +1,24 @@
|
||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?><plugin> |
||||
<id>com.eco.plugin.xx.zjgintegrate</id> |
||||
<name><![CDATA[统一集成_EK]]></name> |
||||
<active>yes</active> |
||||
<version>1.0.8</version> |
||||
<env-version>10.0</env-version> |
||||
<jartime>2018-07-31</jartime> |
||||
<vendor>fr.open</vendor> |
||||
<description><![CDATA[统一集成_EK]]></description> |
||||
<change-notes><![CDATA[ |
||||
[2022-07-11] 插件JSD-10364 初始化 |
||||
]]></change-notes> |
||||
<main-package>com.eco.plugin.xx.zjgintegrate</main-package> |
||||
<lifecycle-monitor class="com.eco.plugin.xx.zjgintegrate.config.InitializeMonitor"/> |
||||
|
||||
<extra-decision> |
||||
<GlobalRequestFilterProvider class="com.eco.plugin.xx.zjgintegrate.sso.pc.filter.SSOFilter"/> |
||||
<LogInOutEventProvider class="com.eco.plugin.xx.zjgintegrate.sso.pc.logout.Logout"/> |
||||
<ControllerRegisterProvider class="com.eco.plugin.xx.zjgintegrate.sync.controller.ControllerRegisterProvider"/> |
||||
</extra-decision> |
||||
|
||||
<function-recorder class="com.eco.plugin.xx.zjgintegrate.config.PCSSSOConfig"/> |
||||
|
||||
</plugin> |
@ -0,0 +1,23 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.config; |
||||
|
||||
import com.fr.plugin.context.PluginContext; |
||||
import com.fr.plugin.observer.inner.AbstractPluginLifecycleMonitor; |
||||
|
||||
/** |
||||
* @author xx |
||||
* @version 10.0 |
||||
* Created by xx on 2021-12-03 |
||||
*/ |
||||
public class InitializeMonitor extends AbstractPluginLifecycleMonitor { |
||||
@Override |
||||
public void afterRun(PluginContext pluginContext) { |
||||
PluginSimpleConfig.getInstance(); |
||||
PCSSSOConfig.getInstance(); |
||||
MobileSSSOConfig.getInstance(); |
||||
} |
||||
|
||||
@Override |
||||
public void beforeStop(PluginContext pluginContext) { |
||||
|
||||
} |
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.config; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
|
||||
@Visualization(category = "移动端单点配置") |
||||
@EnableMetrics |
||||
public class MobileSSSOConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile MobileSSSOConfig config = null; |
||||
|
||||
@Focus(id="com.eco.plugin.xx.zjgintegrate.config", text = "移动端单点配置", source = Original.PLUGIN) |
||||
public static MobileSSSOConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(MobileSSSOConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "appkey", name = "appkey", description = "appkey", status = Status.SHOW) |
||||
private Conf<String> appkey = Holders.simple(""); |
||||
|
||||
@Identifier(value = "userurl", name = "用户信息接口", description = "用户信息接口", status = Status.SHOW) |
||||
private Conf<String> userurl = Holders.simple(""); |
||||
|
||||
public String getAppkey() { |
||||
return appkey.get(); |
||||
} |
||||
|
||||
public void setAppkey(String url) { |
||||
this.appkey.set(url); |
||||
} |
||||
|
||||
public String getUserurl() { |
||||
return userurl.get(); |
||||
} |
||||
|
||||
public void setUserurl(String url) { |
||||
this.userurl.set(url); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
MobileSSSOConfig cloned = (MobileSSSOConfig) super.clone(); |
||||
// cloned.text = (Conf<String>) text.clone();
|
||||
// cloned.count = (Conf<Integer>) count.clone();
|
||||
// cloned.price = (Conf<Double>) price.clone();
|
||||
// cloned.time = (Conf<Long>) time.clone();
|
||||
// cloned.student = (Conf<Boolean>) student.clone();
|
||||
return cloned; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,111 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.config; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
|
||||
@Visualization(category = "pc单点配置") |
||||
@EnableMetrics |
||||
public class PCSSSOConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile PCSSSOConfig config = null; |
||||
|
||||
@Focus(id="com.eco.plugin.xx.zjgintegrate.config", text = "pc单点配置", source = Original.PLUGIN) |
||||
public static PCSSSOConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(PCSSSOConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "clientid", name = "应用id", description = "应用id", status = Status.SHOW) |
||||
private Conf<String> clientid = Holders.simple(""); |
||||
|
||||
@Identifier(value = "secret", name = "应用秘钥", description = "应用秘钥", status = Status.SHOW) |
||||
private Conf<String> secret = Holders.simple(""); |
||||
|
||||
@Identifier(value = "authurl", name = "获取授权码接口", description = "获取授权码接口", status = Status.SHOW) |
||||
private Conf<String> authurl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "tokenurl", name = "获取token接口", description = "获取token接口", status = Status.SHOW) |
||||
private Conf<String> tokenurl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "userurl", name = "获取用户信息接口", description = "获取用户信息接口", status = Status.SHOW) |
||||
private Conf<String> userurl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "logouturl", name = "登出接口", description = "登出接口", status = Status.SHOW) |
||||
private Conf<String> logouturl = Holders.simple(""); |
||||
|
||||
@Identifier(value = "forbidlogin", name = "是否屏蔽登陆页", description = "是否屏蔽登陆页", status = Status.SHOW) |
||||
private Conf<Boolean> forbidlogin = Holders.simple(false); |
||||
|
||||
public Boolean getForbidlogin() { |
||||
return forbidlogin.get(); |
||||
} |
||||
|
||||
public void setForbidlogin(Boolean url) { |
||||
this.forbidlogin.set(url); |
||||
} |
||||
|
||||
public String getClientid() { |
||||
return clientid.get(); |
||||
} |
||||
|
||||
public void setClientid(String url) { |
||||
this.clientid.set(url); |
||||
} |
||||
|
||||
public String getSecret() { |
||||
return secret.get(); |
||||
} |
||||
|
||||
public void setSecret(String url) { |
||||
this.secret.set(url); |
||||
} |
||||
|
||||
public String getAuthurl() { |
||||
return authurl.get(); |
||||
} |
||||
|
||||
public void setAuthurl(String url) { |
||||
this.authurl.set(url); |
||||
} |
||||
|
||||
public String getTokenurl() { |
||||
return tokenurl.get(); |
||||
} |
||||
|
||||
public void setTokenurl(String url) { |
||||
this.tokenurl.set(url); |
||||
} |
||||
|
||||
public String getUserurl() { |
||||
return userurl.get(); |
||||
} |
||||
|
||||
public void setUserurl(String url) { |
||||
this.userurl.set(url); |
||||
} |
||||
|
||||
public String getLogouturl() { |
||||
return logouturl.get(); |
||||
} |
||||
|
||||
public void setLogouturl(String url) { |
||||
this.logouturl.set(url); |
||||
} |
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
PCSSSOConfig cloned = (PCSSSOConfig) super.clone(); |
||||
// cloned.text = (Conf<String>) text.clone();
|
||||
// cloned.count = (Conf<Integer>) count.clone();
|
||||
// cloned.price = (Conf<Double>) price.clone();
|
||||
// cloned.time = (Conf<Long>) time.clone();
|
||||
// cloned.student = (Conf<Boolean>) student.clone();
|
||||
return cloned; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,57 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.config; |
||||
|
||||
import com.fr.config.*; |
||||
import com.fr.config.holder.Conf; |
||||
import com.fr.config.holder.factory.Holders; |
||||
import com.fr.intelli.record.Focus; |
||||
import com.fr.intelli.record.Original; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
|
||||
@Visualization(category = "数据同步配置") |
||||
@EnableMetrics |
||||
public class PluginSimpleConfig extends DefaultConfiguration { |
||||
|
||||
private static volatile PluginSimpleConfig config = null; |
||||
|
||||
@Focus(id="com.eco.plugin.xx.zjgintegrate.config", text = "数据同步配置", source = Original.PLUGIN) |
||||
public static PluginSimpleConfig getInstance() { |
||||
if (config == null) { |
||||
config = ConfigContext.getConfigInstance(PluginSimpleConfig.class); |
||||
} |
||||
return config; |
||||
} |
||||
|
||||
@Identifier(value = "username", name = "应用账户", description = "应用账户", status = Status.SHOW) |
||||
private Conf<String> username = Holders.simple(""); |
||||
|
||||
@Identifier(value = "psd", name = "应用密码", description = "应用密码", status = Status.SHOW) |
||||
private Conf<String> psd = Holders.simple(""); |
||||
|
||||
public String getUsername() { |
||||
return username.get(); |
||||
} |
||||
|
||||
public void setUsername(String url) { |
||||
this.username.set(url); |
||||
} |
||||
|
||||
public String getPsd() { |
||||
return psd.get(); |
||||
} |
||||
|
||||
public void setPsd(String url) { |
||||
this.psd.set(url); |
||||
} |
||||
|
||||
@Override |
||||
public Object clone() throws CloneNotSupportedException { |
||||
PluginSimpleConfig cloned = (PluginSimpleConfig) super.clone(); |
||||
// cloned.text = (Conf<String>) text.clone();
|
||||
// cloned.count = (Conf<Integer>) count.clone();
|
||||
// cloned.price = (Conf<Double>) price.clone();
|
||||
// cloned.time = (Conf<Long>) time.clone();
|
||||
// cloned.student = (Conf<Boolean>) student.clone();
|
||||
return cloned; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,103 @@
|
||||
|
||||
package com.eco.plugin.xx.zjgintegrate.kit; |
||||
|
||||
import com.eco.plugin.xx.zjgintegrate.utils.Utils; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType; |
||||
import com.fr.decision.authority.data.Department; |
||||
import com.fr.decision.webservice.exception.general.DuplicatedNameException; |
||||
import com.fr.decision.webservice.v10.user.DepartmentService; |
||||
import com.fr.general.ComparatorUtils; |
||||
import com.fr.stable.StableUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.restriction.Restriction; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
import java.util.ArrayList; |
||||
import java.util.Collections; |
||||
import java.util.List; |
||||
|
||||
/** |
||||
* <Function Description><br> |
||||
* <DepartmentServiceKit> |
||||
* |
||||
* @author xx |
||||
* @since 1.0.0 |
||||
*/ |
||||
public class DepartmentServiceKit extends DepartmentService { |
||||
public static final String DECISION_DEP_ROOT = "decision-dep-root"; |
||||
private static volatile DepartmentServiceKit departmentServiceKit = null; |
||||
|
||||
public DepartmentServiceKit() { |
||||
} |
||||
|
||||
public static DepartmentServiceKit getInstance() { |
||||
if (departmentServiceKit == null) { |
||||
departmentServiceKit = new DepartmentServiceKit(); |
||||
} |
||||
return departmentServiceKit; |
||||
} |
||||
|
||||
/** |
||||
* 根据id获取部门 |
||||
* @param id |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public Department getByid(String id) throws Exception { |
||||
return AuthorityContext.getInstance().getDepartmentController().getById(id); |
||||
} |
||||
|
||||
/** |
||||
* 添加部门 |
||||
* @param id |
||||
* @param pId |
||||
* @param depName |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public Department addDepartment(String id, String pId, String depName) throws Exception { |
||||
if ((Utils.isNotNullStr(pId) && pId.equals(DECISION_DEP_ROOT)) || Utils.isNullStr(pId)) { |
||||
pId = null; |
||||
} |
||||
this.checkDuplicatedDepartmentName(pId, depName); |
||||
Department department = (new Department()).id(id).name(depName).parentId(pId).creationType(ManualOperationType.KEY).lastOperationType(ManualOperationType.KEY).enable(true); |
||||
AuthorityContext.getInstance().getDepartmentController().add(department); |
||||
return department; |
||||
} |
||||
|
||||
private void checkDuplicatedDepartmentName(String parentId, String depName) throws Exception { |
||||
QueryCondition condition = QueryFactory.create().addRestriction(RestrictionFactory.and(new Restriction[]{RestrictionFactory.eq("name", depName), RestrictionFactory.eq("parentId", parentId)})); |
||||
Department sameNameDep = AuthorityContext.getInstance().getDepartmentController().findOne(condition); |
||||
if (sameNameDep != null) { |
||||
throw new DuplicatedNameException(); |
||||
} |
||||
} |
||||
|
||||
private String getDepartmentFullPath(String pId, String depName, String splitter) throws Exception { |
||||
List<String> paths = new ArrayList<>(); |
||||
paths.add(depName); |
||||
while (!ComparatorUtils.equals(pId, DECISION_DEP_ROOT) && pId != null) { |
||||
Department parentDepartment = AuthorityContext.getInstance().getDepartmentController().getById(pId); |
||||
paths.add(parentDepartment.getName()); |
||||
pId = parentDepartment.getParentId(); |
||||
} |
||||
Collections.reverse(paths); |
||||
return StableUtils.join(paths.toArray(new String[0]), splitter); |
||||
} |
||||
|
||||
public void editDepartment(String departmentId, String depName, String pId) throws Exception { |
||||
if (Utils.isNotNullStr(pId) && pId.equals(DECISION_DEP_ROOT)) { |
||||
pId = null; |
||||
} |
||||
Department department = AuthorityContext.getInstance().getDepartmentController().getById(departmentId); |
||||
String departmentFullPath = DepartmentService.getInstance().getDepartmentFullPath(departmentId); |
||||
if (!ComparatorUtils.equals(department.getName(), depName)) { |
||||
this.checkDuplicatedDepartmentName(department.getParentId(), depName); |
||||
department.setName(depName); |
||||
department.setParentId(pId); |
||||
AuthorityContext.getInstance().getDepartmentController().update(department); |
||||
} |
||||
} |
||||
} |
@ -0,0 +1,23 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.kit; |
||||
|
||||
import com.fr.locale.InterProviderFactory; |
||||
|
||||
import java.util.Locale; |
||||
import java.util.Map; |
||||
|
||||
public class I18nKit { |
||||
public I18nKit() { |
||||
} |
||||
|
||||
public static String getLocText(String string) { |
||||
return InterProviderFactory.getProvider().getLocText(string); |
||||
} |
||||
|
||||
public static String getLocText(String string, String... args) { |
||||
return InterProviderFactory.getProvider().getLocText(string, args); |
||||
} |
||||
|
||||
public static Map<String, String> getEntireKV(Locale locale) { |
||||
return InterProviderFactory.getClientProvider().getEntireKV(locale); |
||||
} |
||||
} |
@ -0,0 +1,97 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.kit; |
||||
|
||||
import com.eco.plugin.xx.zjgintegrate.utils.FRUtils; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.base.constant.SoftRoleType; |
||||
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.base.util.UUIDUtil; |
||||
import com.fr.decision.privilege.encrpt.PasswordValidator; |
||||
import com.fr.decision.webservice.bean.user.UserBean; |
||||
import com.fr.decision.webservice.exception.general.DuplicatedNameException; |
||||
import com.fr.decision.webservice.exception.general.SpecialCharProhibitException; |
||||
import com.fr.decision.webservice.exception.login.UserPasswordCanNotEmptyException; |
||||
import com.fr.decision.webservice.utils.CharLimitType; |
||||
import com.fr.decision.webservice.utils.UserSourceFactory; |
||||
import com.fr.decision.webservice.utils.WebServiceUtils; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.condition.QueryCondition; |
||||
import com.fr.stable.query.restriction.Restriction; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
|
||||
public class UserServiceKit extends UserService { |
||||
private static volatile UserServiceKit userServiceKit = null; |
||||
|
||||
public UserServiceKit() { |
||||
} |
||||
|
||||
public static UserServiceKit getInstance() { |
||||
if (userServiceKit == null) { |
||||
userServiceKit = new UserServiceKit(); |
||||
} |
||||
return userServiceKit; |
||||
} |
||||
|
||||
public void editUser(UserBean userBean, String var2) throws Exception { |
||||
this.editUserInfo(userBean); |
||||
if (userBean.isResetPassword()) { |
||||
this.resetPassword(userBean); |
||||
} |
||||
|
||||
this.updateUserRoles(var2, userBean); |
||||
this.updateUserDepartmentPost(var2, userBean); |
||||
} |
||||
|
||||
/** |
||||
* 添加用户 |
||||
* @param userBean |
||||
* @throws Exception |
||||
*/ |
||||
public void addUser(UserBean userBean) throws Exception { |
||||
if (StringUtils.isEmpty(userBean.getPassword())) { |
||||
throw new UserPasswordCanNotEmptyException(); |
||||
} else { |
||||
String username = userBean.getUsername(); |
||||
String mobile = userBean.getMobile(); |
||||
String email = userBean.getEmail(); |
||||
String id = userBean.getId(); |
||||
String psd = userBean.getPassword(); |
||||
this.checkUsernameLegal(username, CharLimitType.USER_LIMIT); |
||||
this.checkNonRequiredField(mobile, CharLimitType.MOBILE_LIMIT); |
||||
this.checkNonRequiredField(email, CharLimitType.EMAIL_LIMIT); |
||||
this.checkDuplicatedUser(username); |
||||
String salt = UUIDUtil.generate(); |
||||
PasswordValidator var8 = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator(); |
||||
User user = (new User()).userName(username).realName(userBean.getRealName()).password(var8.encode(username, psd, salt)).salt(salt).email(userBean.getEmail()).mobile(userBean.getMobile()).creationType(ManualOperationType.KEY).lastOperationType(ManualOperationType.KEY).enable(true).id(id); |
||||
FRUtils.FRLogInfo(user.toString()); |
||||
AuthorityContext.getInstance().getUserController().add(user); |
||||
this.deleteSoftData(user.getUserName()); |
||||
} |
||||
} |
||||
|
||||
private void checkUsernameLegal(String var1, CharLimitType var2) throws SpecialCharProhibitException { |
||||
if (WebServiceUtils.containSQLChars(var1) || WebServiceUtils.containIllegalChars(var2, var1)) { |
||||
throw new SpecialCharProhibitException(); |
||||
} |
||||
} |
||||
|
||||
private void checkNonRequiredField(String var1, CharLimitType var2) { |
||||
if (StringUtils.isNotEmpty(var1) && WebServiceUtils.containIllegalChars(var2, var1)) { |
||||
throw new SpecialCharProhibitException(); |
||||
} |
||||
} |
||||
|
||||
private void checkDuplicatedUser(String var1) throws Exception { |
||||
User var2 = this.getUserByUserName(var1); |
||||
if (var2 != null) { |
||||
throw new DuplicatedNameException("Duplicated names! ", var1); |
||||
} |
||||
} |
||||
|
||||
private void deleteSoftData(String var1) throws Exception { |
||||
QueryCondition var2 = QueryFactory.create().addRestriction(RestrictionFactory.and(new Restriction[]{RestrictionFactory.eq("deletedName", var1), RestrictionFactory.eq("type", SoftRoleType.USER)})); |
||||
AuthorityContext.getInstance().getSoftDataController().remove(var2); |
||||
} |
||||
} |
@ -0,0 +1,145 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.sso.pc.filter; |
||||
|
||||
import com.eco.plugin.xx.zjgintegrate.config.PCSSSOConfig; |
||||
import com.eco.plugin.xx.zjgintegrate.utils.FRUtils; |
||||
import com.eco.plugin.xx.zjgintegrate.utils.HttpUtils; |
||||
import com.eco.plugin.xx.zjgintegrate.utils.Utils; |
||||
import com.fr.decision.fun.impl.AbstractGlobalRequestFilterProvider; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.record.analyzer.EnableMetrics; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
import javax.servlet.FilterChain; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.IOException; |
||||
import java.net.URLEncoder; |
||||
|
||||
@EnableMetrics |
||||
@Authorize(callSignKey = "com.eco.plugin.xx.zjgintegrate") |
||||
public class SSOFilter extends AbstractGlobalRequestFilterProvider { |
||||
@Override |
||||
public String filterName() { |
||||
return "fqlssoFilter"; |
||||
} |
||||
|
||||
@Override |
||||
public String[] urlPatterns() { |
||||
return new String[]{"/*"}; |
||||
} |
||||
|
||||
@Override |
||||
public void doFilter(HttpServletRequest req, HttpServletResponse res, FilterChain chain ){ |
||||
|
||||
if(PluginContexts.currentContext().isAvailable()){ |
||||
PCSSSOConfig psc = PCSSSOConfig.getInstance(); |
||||
|
||||
//是否放行
|
||||
boolean release = isRelease(req); |
||||
if(release){ |
||||
FRUtils.FRLogInfo(""); |
||||
release(req,res,chain); |
||||
return; |
||||
} |
||||
|
||||
String code = req.getParameter("code"); |
||||
|
||||
if(Utils.isNullStr(code)){ |
||||
//跳转认证中心
|
||||
redirect(req,res,psc); |
||||
return; |
||||
} |
||||
|
||||
//获取token
|
||||
String token = getToken(code,psc); |
||||
|
||||
//获取userInfo
|
||||
String username = getUsername(token,psc); |
||||
String redirect = Utils.getRedirectUrl(req,"code"); |
||||
//登录
|
||||
FRUtils.login(req,res,username,redirect); |
||||
} |
||||
|
||||
release(req,res,chain); |
||||
} |
||||
|
||||
private boolean isRelease(HttpServletRequest req) { |
||||
String url = FRUtils.getAllUrl(req); |
||||
String origin = req.getParameter("origin"); |
||||
String code = req.getParameter("code"); |
||||
if((url.contains("/login") && Utils.isNotNullStr(origin)) || Utils.isNotNullStr(code)){ |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
|
||||
//跳转认证中心
|
||||
private void redirect(HttpServletRequest req,HttpServletResponse res, PCSSSOConfig psc) { |
||||
String redirect = ""; |
||||
try { |
||||
redirect = FRUtils.getOriginUrl(req); |
||||
redirect = URLEncoder.encode(redirect); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("获取redirect异常:"+e.getMessage()); |
||||
} |
||||
String authurl = psc.getAuthurl()+"?redirect_uri="+redirect+"&state=1&client_id="+psc.getClientid()+"&response_type=code"; |
||||
|
||||
try { |
||||
res.sendRedirect(authurl); |
||||
} catch (IOException e) { |
||||
FRUtils.FRLogInfo("跳转认证中心异常:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
//获取token
|
||||
private String getToken(String code,PCSSSOConfig psc) { |
||||
String tokenurl = psc.getTokenurl()+"?client_id="+psc.getClientid()+"&grant_type=authorization_code&code="+code+"&client_secret="+psc.getSecret(); |
||||
|
||||
String result = HttpUtils.HttpPostJson(tokenurl,"",null); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject json = new JSONObject(result); |
||||
|
||||
if(json == null ){ |
||||
return ""; |
||||
} |
||||
|
||||
String token = json.getString("access_token"); |
||||
return token; |
||||
} |
||||
|
||||
//获取用户名
|
||||
private String getUsername(String openId,PCSSSOConfig psc) { |
||||
String tokenurl = psc.getUserurl()+"?access_token="+openId+"&client_id="+psc.getClientid(); |
||||
|
||||
String result = HttpUtils.httpGet(tokenurl,null,null); |
||||
|
||||
if(Utils.isNullStr(result)){ |
||||
return ""; |
||||
} |
||||
|
||||
JSONObject json = new JSONObject(result); |
||||
|
||||
if(json == null ){ |
||||
return ""; |
||||
} |
||||
|
||||
String username = json.getString("loginName"); |
||||
return username; |
||||
} |
||||
|
||||
//放行拦截器
|
||||
private void release(HttpServletRequest req, HttpServletResponse res, FilterChain chain) { |
||||
try{ |
||||
chain.doFilter(req,res); |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogInfo("拦截失败"); |
||||
} |
||||
} |
||||
} |
||||
|
@ -0,0 +1,20 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.sso.pc.logout; |
||||
|
||||
import com.eco.plugin.xx.zjgintegrate.config.PCSSSOConfig; |
||||
import com.fr.decision.fun.impl.AbstractLogInOutEventProvider; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
|
||||
import javax.servlet.http.HttpSession; |
||||
|
||||
public class Logout extends AbstractLogInOutEventProvider { |
||||
|
||||
@Override |
||||
public String logoutAction(LogInOutResultInfo result) { |
||||
HttpSession session = result.getRequest().getSession(true); |
||||
LoginService.getInstance().crossDomainLogout(result.getRequest(),result.getResponse(),""); |
||||
session.invalidate(); |
||||
return PCSSSOConfig.getInstance().getLogouturl(); |
||||
} |
||||
} |
||||
|
@ -0,0 +1,20 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.sync.controller; |
||||
|
||||
import com.fr.decision.fun.impl.AbstractControllerRegisterProvider; |
||||
import com.fr.plugin.context.PluginContexts; |
||||
import com.fr.stable.fun.Authorize; |
||||
|
||||
@Authorize(callSignKey = "com.eco.plugin.xx.zjgintegrate") |
||||
public class ControllerRegisterProvider extends AbstractControllerRegisterProvider { |
||||
@Override |
||||
public Class<?>[] getControllers() { |
||||
|
||||
if(!PluginContexts.currentContext().isAvailable()) { |
||||
return new Class[]{}; |
||||
} |
||||
|
||||
return new Class[]{ |
||||
ControllerSelf.class |
||||
}; |
||||
} |
||||
} |
@ -0,0 +1,428 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.sync.controller; |
||||
|
||||
import com.eco.plugin.xx.zjgintegrate.config.MobileSSSOConfig; |
||||
import com.eco.plugin.xx.zjgintegrate.config.PluginSimpleConfig; |
||||
import com.eco.plugin.xx.zjgintegrate.kit.DepartmentServiceKit; |
||||
import com.eco.plugin.xx.zjgintegrate.kit.UserServiceKit; |
||||
import com.eco.plugin.xx.zjgintegrate.utils.*; |
||||
import com.fr.decision.authority.data.Department; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.webservice.annotation.LoginStatusChecker; |
||||
import com.fr.decision.webservice.bean.user.UserBean; |
||||
import com.fr.decision.webservice.bean.user.UserUpdateBean; |
||||
import com.fr.json.JSONArray; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.plugin.transform.FunctionRecorder; |
||||
import com.fr.third.springframework.stereotype.Controller; |
||||
import com.fr.third.springframework.web.bind.annotation.GetMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.PostMapping; |
||||
import com.fr.third.springframework.web.bind.annotation.ResponseBody; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.util.HashMap; |
||||
import java.util.Map; |
||||
import java.util.UUID; |
||||
|
||||
@Controller |
||||
@LoginStatusChecker(required = false) |
||||
@FunctionRecorder |
||||
public class ControllerSelf { |
||||
|
||||
/** |
||||
* 帆软用户组织字段信息 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/SchemaService") |
||||
@ResponseBody |
||||
public void SchemaService(HttpServletRequest req,HttpServletResponse res){ |
||||
JSONObject param = Utils.getRequestBody(req); |
||||
boolean auth = auth(param,res); |
||||
|
||||
if(auth){ |
||||
JSONObject result = getResultJson(param); |
||||
|
||||
//用户字段
|
||||
JSONArray userField = new JSONArray(); |
||||
String id = "{\"multivalued\":false,\"name\":\"uid\",\"required\":true,\"type\":\"String\"}"; |
||||
String username = "{\"multivalued\":false,\"name\":\"username\",\"required\":true,\"type\":\"String\"}"; |
||||
String realname = "{\"multivalued\":false,\"name\":\"realname\",\"required\":true,\"type\":\"String\"}"; |
||||
String orgId = "{\"multivalued\":false,\"name\":\"orgId\",\"required\":false,\"type\":\"String\"}"; |
||||
String mobile = "{\"multivalued\":false,\"name\":\"mobile\",\"required\":false,\"type\":\"String\"}"; |
||||
String email = "{\"multivalued\":false,\"name\":\"email\",\"required\":false,\"type\":\"String\"}"; |
||||
userField.add(new JSONObject(id)).add(new JSONObject(username)).add(new JSONObject(realname)) |
||||
.add(new JSONObject(orgId)).add(new JSONObject(mobile)).add(new JSONObject(email)); |
||||
result.put("account",userField); |
||||
|
||||
//部门字段
|
||||
JSONArray deptField = new JSONArray(); |
||||
String orgid = "{\"multivalued\":false,\"name\":\"orgId\",\"required\":true,\"type\":\"String\"}"; |
||||
String orgName = "{\"multivalued\":false,\"name\":\"orgName\",\"required\":true,\"type\":\"String\"}"; |
||||
String pid = "{\"multivalued\":false,\"name\":\"pid\",\"required\":false,\"type\":\"String\"}"; |
||||
deptField.add(new JSONObject(orgid)).add(new JSONObject(orgName)).add(new JSONObject(pid)); |
||||
result.put("organization",deptField); |
||||
|
||||
ResponseUtils.response(res,result); |
||||
} |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 创建组织 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/OrgCreateService") |
||||
@ResponseBody |
||||
public void OrgCreateService(HttpServletRequest req,HttpServletResponse res) { |
||||
JSONObject param = Utils.getRequestBody(req); |
||||
boolean auth = auth(param, res); |
||||
|
||||
if (auth) { |
||||
JSONObject result = getResultJson(param); |
||||
String id = param.getString("orgId"); |
||||
String orgName = param.getString("orgName"); |
||||
String pid = param.getString("pid"); |
||||
|
||||
if(Utils.isNullStr(id)){ |
||||
id = UUID.randomUUID().toString(); |
||||
} |
||||
|
||||
try { |
||||
DepartmentServiceKit.getInstance().addDepartment(id,pid,orgName); |
||||
} catch (Exception e) { |
||||
result.put("resultCode","-1"); |
||||
result.put("message","创建失败"); |
||||
FRUtils.FRLogInfo("OrgCreateService exception:"+e.getMessage()); |
||||
|
||||
ResponseUtils.response(res,result); |
||||
return ; |
||||
} |
||||
|
||||
result.put("orgId",id); |
||||
ResponseUtils.response(res,result); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 创建组织 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/OrgUpdateService") |
||||
@ResponseBody |
||||
public void OrgUpdateService(HttpServletRequest req,HttpServletResponse res) { |
||||
JSONObject param = Utils.getRequestBody(req); |
||||
boolean auth = auth(param, res); |
||||
|
||||
if (auth) { |
||||
JSONObject result = getResultJson(param); |
||||
String id = param.getString("orgId"); |
||||
String orgName = param.getString("orgName"); |
||||
String pid = param.getString("pid"); |
||||
|
||||
try { |
||||
Department department = DepartmentServiceKit.getInstance().getByid(id); |
||||
|
||||
if(Utils.isNullStr(orgName)){ |
||||
orgName = department.getName(); |
||||
} |
||||
|
||||
if(pid == null){ |
||||
pid = department.getParentId(); |
||||
} |
||||
|
||||
DepartmentServiceKit.getInstance().editDepartment(id,orgName,pid); |
||||
} catch (Exception e) { |
||||
result.put("resultCode","-1"); |
||||
result.put("message","修改失败"); |
||||
FRUtils.FRLogInfo("OrgUpdateService exception:"+e.getMessage()); |
||||
|
||||
ResponseUtils.response(res,result); |
||||
return ; |
||||
} |
||||
|
||||
result.put("orgId",id); |
||||
ResponseUtils.response(res,result); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 创建组织 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/OrgDeleteService") |
||||
@ResponseBody |
||||
public void OrgDeleteService(HttpServletRequest req,HttpServletResponse res) { |
||||
JSONObject param = Utils.getRequestBody(req); |
||||
boolean auth = auth(param, res); |
||||
|
||||
if (auth) { |
||||
JSONObject result = getResultJson(param); |
||||
String id = param.getString("orgId"); |
||||
|
||||
try { |
||||
DepartmentServiceKit.getInstance().deleteDepartment(id); |
||||
} catch (Exception e) { |
||||
result.put("resultCode","-1"); |
||||
result.put("message","删除失败"); |
||||
FRUtils.FRLogInfo("OrgDeleteService exception:"+e.getMessage()); |
||||
|
||||
ResponseUtils.response(res,result); |
||||
return ; |
||||
} |
||||
|
||||
result.put("orgId",id); |
||||
ResponseUtils.response(res,result); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 创建用户 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/UserCreateService") |
||||
@ResponseBody |
||||
public void UserCreateService(HttpServletRequest req,HttpServletResponse res) { |
||||
JSONObject param = Utils.getRequestBody(req); |
||||
boolean auth = auth(param, res); |
||||
|
||||
if (auth) { |
||||
JSONObject result = getResultJson(param); |
||||
String id = param.getString("uid"); |
||||
String username = param.getString("username"); |
||||
String realname = param.getString("realname"); |
||||
String orgId = param.getString("orgId"); |
||||
String mobile = param.getString("mobile"); |
||||
String email = param.getString("email"); |
||||
String psd = "123456"; |
||||
boolean status = param.getInt("status") == 0; |
||||
|
||||
if(Utils.isNullStr(id)){ |
||||
id = username; |
||||
} |
||||
|
||||
try { |
||||
UserBean userBean = new UserBean(); |
||||
userBean.setUsername(username); |
||||
userBean.setRealName(realname); |
||||
userBean.setMobile(mobile); |
||||
userBean.setEmail(email); |
||||
userBean.setPassword(psd); |
||||
userBean.setId(id); |
||||
UserServiceKit.getInstance().addUser(userBean); |
||||
User user = FRUserUtils.getUserByUserName(username); |
||||
FRUserUtils.forbidUser(user.getId(),status); |
||||
UserUpdateBean userUpdateBean = new UserUpdateBean(); |
||||
userUpdateBean.setAddUserIds(new String[]{user.getId()}); |
||||
FRUserUtils.updateDepartmentPostUsers(orgId,"",userUpdateBean); |
||||
} catch (Exception e) { |
||||
result.put("resultCode","-1"); |
||||
result.put("message","添加失败"); |
||||
FRUtils.FRLogInfo("UserCreateService exception:"+e.getMessage()); |
||||
|
||||
ResponseUtils.response(res,result); |
||||
return ; |
||||
} |
||||
|
||||
result.put("uid",id); |
||||
ResponseUtils.response(res,result); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 创建用户 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/UserUpdateService") |
||||
@ResponseBody |
||||
public void UserUpdateService(HttpServletRequest req,HttpServletResponse res) { |
||||
JSONObject param = Utils.getRequestBody(req); |
||||
boolean auth = auth(param, res); |
||||
|
||||
if (auth) { |
||||
JSONObject result = getResultJson(param); |
||||
String id = param.getString("uid"); |
||||
String username = param.getString("username"); |
||||
String realname = param.getString("realname"); |
||||
String orgId = param.getString("orgId"); |
||||
String mobile = param.getString("mobile"); |
||||
String email = param.getString("email"); |
||||
String statusStr = param.getString("status"); |
||||
boolean status = param.getInt("status") == 0; |
||||
|
||||
try { |
||||
User user = FRUserUtils.getUserByUserName(FRUserUtils.getUser(id).getUsername()); |
||||
|
||||
if(Utils.isNullStr(realname)){ |
||||
realname = user.getRealName(); |
||||
} |
||||
|
||||
if(Utils.isNullStr(mobile)){ |
||||
mobile = user.getMobile(); |
||||
} |
||||
|
||||
if(Utils.isNullStr(email)){ |
||||
email = user.getEmail(); |
||||
} |
||||
|
||||
UserBean userBean = new UserBean(); |
||||
userBean.setId(user.getId()); |
||||
userBean.setUsername(user.getUserName()); |
||||
userBean.setRealName(realname); |
||||
userBean.setMobile(mobile); |
||||
userBean.setEmail(email); |
||||
FRUserUtils.updateUser(userBean); |
||||
if(!Utils.isNullStr(statusStr)){ |
||||
FRUserUtils.forbidUser(user.getId(),status); |
||||
} |
||||
|
||||
if(!Utils.isNullStr(orgId)){ |
||||
UserUpdateBean userUpdateBean = new UserUpdateBean(); |
||||
userUpdateBean.setAddUserIds(new String[]{user.getId()}); |
||||
FRUserUtils.updateDepartmentPostUsers(orgId,"",userUpdateBean); |
||||
} |
||||
} catch (Exception e) { |
||||
result.put("resultCode","-1"); |
||||
result.put("message","修改失败"); |
||||
FRUtils.FRLogInfo("UserUpdateService exception:"+e.getMessage()); |
||||
|
||||
ResponseUtils.response(res,result); |
||||
return ; |
||||
} |
||||
|
||||
result.put("uid",id); |
||||
ResponseUtils.response(res,result); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 创建用户 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/UserDeleteService") |
||||
@ResponseBody |
||||
public void UserDeleteService(HttpServletRequest req,HttpServletResponse res) { |
||||
JSONObject param = Utils.getRequestBody(req); |
||||
boolean auth = auth(param, res); |
||||
|
||||
if (auth) { |
||||
JSONObject result = getResultJson(param); |
||||
String id = param.getString("uid"); |
||||
|
||||
try { |
||||
User user = FRUserUtils.getUserByUserName(FRUserUtils.getUser(id).getUsername()); |
||||
FRUserUtils.deleteUser(user); |
||||
} catch (Exception e) { |
||||
result.put("resultCode","-1"); |
||||
result.put("message","删除失败"); |
||||
FRUtils.FRLogInfo("UserDeleteService exception:"+e.getMessage()); |
||||
|
||||
ResponseUtils.response(res,result); |
||||
return ; |
||||
} |
||||
|
||||
result.put("uid",id); |
||||
ResponseUtils.response(res,result); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取appkey |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@PostMapping(value = "/getAppkey") |
||||
@ResponseBody |
||||
public void getAppkey(HttpServletRequest req,HttpServletResponse res) { |
||||
JSONObject json = new JSONObject(); |
||||
json.put("appKey",MobileSSSOConfig.getInstance().getAppkey()); |
||||
ResponseUtils.response(res,json); |
||||
} |
||||
|
||||
/** |
||||
* 单点登陆 |
||||
* @param req |
||||
* @param res |
||||
*/ |
||||
@GetMapping(value = "/ssoLogin") |
||||
@ResponseBody |
||||
public void ssoLogin(HttpServletRequest req,HttpServletResponse res) { |
||||
String ticket = req.getParameter("ticket"); |
||||
String redirect = req.getParameter("redirect"); |
||||
MobileSSSOConfig psc = MobileSSSOConfig.getInstance(); |
||||
String url = psc.getUserurl(); |
||||
JSONObject param = new JSONObject(); |
||||
param.put("device",psc.getAppkey()); |
||||
param.put("encryptedString",ticket); |
||||
|
||||
Map<String,String> header = new HashMap<String,String>(); |
||||
header.put("operator","hw"); |
||||
|
||||
FRUtils.FRLogInfo("header:"+header.toString()); |
||||
FRUtils.FRLogInfo("param:"+param.toString()); |
||||
|
||||
String resultStr = HttpUtils.HttpPostJson(url,param.toString(),header); |
||||
|
||||
if(Utils.isNullStr(resultStr)){ |
||||
ResponseUtils.failedResponse(res,"获取用户信息失败!"); |
||||
return ; |
||||
} |
||||
|
||||
JSONObject resultJson = new JSONObject(resultStr); |
||||
String code = resultJson.getString("code"); |
||||
|
||||
if(!"info.common.success".equals(code)){ |
||||
ResponseUtils.failedResponse(res,"获取用户信息失败!"); |
||||
return ; |
||||
} |
||||
|
||||
String username = resultJson.getJSONObject("body").getString("username"); |
||||
|
||||
FRUtils.login(req,res,username,Utils.encodeCH(redirect)); |
||||
} |
||||
|
||||
/** |
||||
* 获取返回值json |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
private static JSONObject getResultJson(JSONObject param){ |
||||
String iamRequestId = param.getString("iamRequestId"); |
||||
JSONObject result = new JSONObject(); |
||||
result.put("iamRequestId",iamRequestId); |
||||
result.put("resultCode","0"); |
||||
result.put("message","成功"); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* 鉴权 |
||||
* @param param |
||||
* @param res |
||||
* @return |
||||
*/ |
||||
private static boolean auth(JSONObject param, HttpServletResponse res){ |
||||
PluginSimpleConfig psc = PluginSimpleConfig.getInstance(); |
||||
String iamRemoteUser = param.getString("iamRemoteUser"); |
||||
String iamRemotePwd = param.getString("iamRemotePwd"); |
||||
|
||||
boolean success = iamRemoteUser.equals(psc.getUsername()) && iamRemotePwd.equals(psc.getPsd()); |
||||
|
||||
if(!success){ |
||||
JSONObject result = new JSONObject(); |
||||
result.put("resultCode","302"); |
||||
result.put("message","鉴权失败!"); |
||||
ResponseUtils.response(res,result); |
||||
return false; |
||||
} |
||||
|
||||
return true; |
||||
} |
||||
} |
@ -0,0 +1,210 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.utils; |
||||
|
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.privilege.TransmissionTool; |
||||
import com.fr.decision.webservice.bean.user.*; |
||||
import com.fr.decision.webservice.v10.login.ExtendTokenProcessor; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
|
||||
public class FRUserUtils { |
||||
|
||||
/** |
||||
* 获取用户Service |
||||
* @return |
||||
*/ |
||||
public static UserService getUserService(){ |
||||
return UserService.getInstance(); |
||||
} |
||||
|
||||
/** |
||||
* 获取全量用户 |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<UserAdditionBean> getAllUsers() throws Exception { |
||||
|
||||
List<UserAdditionBean> users = new ArrayList<UserAdditionBean>(); |
||||
getAllUser(getAdminUser().getUsername(),0,1000,users); |
||||
return users; |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param adminUsername 管理员用户名 |
||||
* @param page 页数 |
||||
* @param num 每页的数据 |
||||
* @param users 保存用户的列表 |
||||
*/ |
||||
private static void getAllUser(String adminUsername,int page,int num,List<UserAdditionBean> users) throws Exception { |
||||
Map<String,Object> result = getUserService().getAllUsers(adminUsername,page,num,"","",true); |
||||
Long total = (Long)result.get("total"); |
||||
List<UserAdditionBean> item = (List<UserAdditionBean>)result.get("items"); |
||||
users.addAll(item); |
||||
|
||||
page = page+1; |
||||
|
||||
if(page * num >= total){ |
||||
return ; |
||||
} |
||||
|
||||
getAllUser(adminUsername,page,num,users); |
||||
} |
||||
/** |
||||
* 添加用户 |
||||
* @param userBean |
||||
*/ |
||||
public static void addUser(UserBean userBean) throws Exception { |
||||
userBean.setPassword(TransmissionTool.defaultEncrypt(userBean.getPassword())); |
||||
getUserService().addUser(userBean); |
||||
} |
||||
|
||||
/** |
||||
* 删除用户 |
||||
* @param userBean |
||||
*/ |
||||
public static void updateUser(UserBean userBean) throws Exception { |
||||
getUserService().editUser(userBean,getAdminUser().getId()); |
||||
} |
||||
|
||||
/** |
||||
* 删除用户 |
||||
* @param user |
||||
* @return |
||||
*/ |
||||
public static int deleteUser(User user) throws Exception { |
||||
String userId = user.getId(); |
||||
|
||||
UserUpdateBean userUpdateBean = new UserUpdateBean(); |
||||
userUpdateBean.setRemoveUserIds(new String[]{userId}); |
||||
|
||||
return getUserService().deleteUsers(userUpdateBean); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户实体 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static User getUserByUserName(String userName) throws Exception { |
||||
return getUserService().getUserByUserName(userName); |
||||
} |
||||
|
||||
/** |
||||
* 根据用户名获取用户实体 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static UserBean getUserBeanByUserName(String userName ) throws Exception { |
||||
String id = getUserService().getUserByUserName(userName).getId(); |
||||
return getUser(id); |
||||
} |
||||
|
||||
/** |
||||
* 根据id获取用户 |
||||
* @param id |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static UserBean getUser(String id) throws Exception { |
||||
return getUserService().getUser(id); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String username) throws Exception{ |
||||
return getUserService().isAdmin(getUserByUserName(username).getId()); |
||||
} |
||||
|
||||
/** |
||||
* 禁用启用用户 |
||||
* @param userId |
||||
* @param state false 禁用 true 启用 |
||||
* @throws Exception 异常说明失败 |
||||
*/ |
||||
public static void forbidUser(String userId,boolean state) throws Exception { |
||||
getUserService().forbidUser(userId,state); |
||||
} |
||||
|
||||
/** |
||||
* 修改用户部门 |
||||
* @param departmentId |
||||
* @param postId |
||||
* @param ud |
||||
* @throws Exception |
||||
*/ |
||||
public static void updateDepartmentPostUsers(String departmentId, String postId, UserUpdateBean ud) throws Exception { |
||||
getUserService().updateDepartmentPostUsers(departmentId,"",ud); |
||||
} |
||||
|
||||
|
||||
|
||||
public static User getCurrentUser(HttpServletRequest req) throws Exception { |
||||
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
||||
|
||||
if(Utils.isNullStr(username)){ |
||||
return null; |
||||
} |
||||
|
||||
return getUserByUserName(username); |
||||
} |
||||
|
||||
public static UserBean getCurrentUserBean(HttpServletRequest req) throws Exception { |
||||
String username = LoginService.getInstance().getCurrentUserNameFromRequestCookie(req); |
||||
|
||||
if(Utils.isNullStr(username)){ |
||||
return null; |
||||
} |
||||
|
||||
return getUserBeanByUserName(username); |
||||
} |
||||
|
||||
/** |
||||
* 获取用户部门角色 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
private static UserRolesBean getUserRolesBean(String username) throws Exception { |
||||
return FRUserUtils.getUserService().getUserDepAndCustomRoles(username); |
||||
} |
||||
|
||||
/** |
||||
* 获取部门职务 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<DepRoleBean> getDepRoleBean(String username) throws Exception{ |
||||
return getUserRolesBean(username).getDepRoles(); |
||||
} |
||||
|
||||
/** |
||||
* 获取角色 |
||||
* @param username |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static List<String> getCustomRoles(String username) throws Exception{ |
||||
return getUserRolesBean(username).getCustomRoles(); |
||||
} |
||||
|
||||
public static UserBean getAdminUser() throws Exception { |
||||
String adminid = getUserService().getAdminUserIdList().get(0); |
||||
return getUser(adminid); |
||||
} |
||||
|
||||
public static String getUsernameFromToken(String token){ |
||||
String username = ExtendTokenProcessor.KEY.getUsername(token); |
||||
return username; |
||||
} |
||||
|
||||
} |
@ -0,0 +1,325 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.utils; |
||||
|
||||
import com.fr.base.ServerConfig; |
||||
import com.fr.base.TableData; |
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.decision.authority.AuthorityContext; |
||||
import com.fr.decision.authority.base.constant.type.operation.ManualOperationType; |
||||
import com.fr.decision.authority.data.User; |
||||
import com.fr.decision.base.util.UUIDUtil; |
||||
import com.fr.decision.privilege.encrpt.PasswordValidator; |
||||
import com.fr.decision.webservice.bean.authentication.OriginUrlResponseBean; |
||||
import com.fr.decision.webservice.interceptor.handler.ReportTemplateRequestChecker; |
||||
import com.fr.decision.webservice.login.LogInOutResultInfo; |
||||
import com.fr.decision.webservice.utils.DecisionServiceConstants; |
||||
import com.fr.decision.webservice.utils.DecisionStatusService; |
||||
import com.fr.decision.webservice.utils.UserSourceFactory; |
||||
import com.fr.decision.webservice.v10.login.LoginService; |
||||
import com.fr.decision.webservice.v10.login.event.LogInOutEvent; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.event.EventDispatcher; |
||||
import com.fr.file.TableDataConfig; |
||||
import com.fr.general.data.DataModel; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.script.Calculator; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.stable.query.QueryFactory; |
||||
import com.fr.stable.query.restriction.RestrictionFactory; |
||||
import com.fr.third.springframework.web.method.HandlerMethod; |
||||
import com.fr.web.controller.ReportRequestService; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import javax.servlet.http.HttpSession; |
||||
import java.io.IOException; |
||||
import java.util.List; |
||||
|
||||
public class FRUtils { |
||||
/** |
||||
* 判断用户是否存在 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static boolean isUserExist(String userName){ |
||||
if (StringUtils.isEmpty(userName)) { |
||||
return false; |
||||
} else { |
||||
try { |
||||
List userList = AuthorityContext.getInstance().getUserController().find(QueryFactory.create().addRestriction(RestrictionFactory.eq("userName", userName))); |
||||
return userList != null && !userList.isEmpty(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage()); |
||||
return false; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 判断是否登录FR |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isLogin(HttpServletRequest req){ |
||||
return LoginService.getInstance().isLogged(req); |
||||
} |
||||
|
||||
/** |
||||
* 帆软登录 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param userName |
||||
* @param url |
||||
*/ |
||||
public static void login(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String userName,String url){ |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名:"+userName); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||
|
||||
|
||||
//判断用户名是否为空
|
||||
if(!Utils.isNullStr(userName)){ |
||||
if(isUserExist(userName)){ |
||||
String FRToken = ""; |
||||
|
||||
try { |
||||
//HttpSession session = httpServletRequest.getSession(true);
|
||||
|
||||
FRToken = LoginService.getInstance().login(httpServletRequest, httpServletResponse, userName); |
||||
|
||||
//httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,FRToken);
|
||||
|
||||
//session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, FRToken);
|
||||
EventDispatcher.fire(LogInOutEvent.LOGIN,new LogInOutResultInfo(httpServletRequest,httpServletResponse,userName,true)); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登陆成功!"); |
||||
|
||||
if(!Utils.isNullStr(url)){ |
||||
httpServletResponse.sendRedirect(url); |
||||
} |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"登录异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登录异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户在报表系统中不存在!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:用户在报表系统中不存在!"); |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"用户名不能为空!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:用户名不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 帆软登录 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param token |
||||
* @param url |
||||
*/ |
||||
public static void loginByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token,String url){ |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:token:"+token); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转链接:"+url); |
||||
|
||||
|
||||
//判断用户名是否为空
|
||||
if(!Utils.isNullStr(token)){ |
||||
writeToken2Cookie(httpServletResponse,token,-1); |
||||
|
||||
HttpSession session = httpServletRequest.getSession(true); |
||||
|
||||
httpServletRequest.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME,token); |
||||
|
||||
session.setAttribute(DecisionServiceConstants.FINE_AUTH_TOKEN_NAME, token); |
||||
|
||||
if(!Utils.isNullStr(url)){ |
||||
try { |
||||
httpServletResponse.sendRedirect(url); |
||||
} catch (IOException e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"跳转异常!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:跳转异常!"); |
||||
} |
||||
} |
||||
}else{ |
||||
ResponseUtils.failedResponse(httpServletResponse,"token不能为空!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:token不能为空!"); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 获取token |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static String getToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String username){ |
||||
String token = ""; |
||||
try { |
||||
token = LoginService.getInstance().login(httpServletRequest, httpServletResponse, username); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:获取token失败"+e.getMessage()); |
||||
} |
||||
|
||||
return token; |
||||
} |
||||
|
||||
private static void writeToken2Cookie(HttpServletResponse req, String token, int num) { |
||||
try { |
||||
if (StringUtils.isNotEmpty(token)) { |
||||
Cookie cookie = new Cookie("fine_auth_token", token); |
||||
long maxAge = num == -2 ? 1209600000L : (long)num; |
||||
cookie.setMaxAge((int)maxAge); |
||||
cookie.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
req.addCookie(cookie); |
||||
Cookie rememberCookie = new Cookie("fine_remember_login", String.valueOf(num == -2 ? -2 : -1)); |
||||
rememberCookie.setMaxAge((int)maxAge); |
||||
rememberCookie.setPath(ServerConfig.getInstance().getCookiePath()); |
||||
req.addCookie(rememberCookie); |
||||
} else { |
||||
FineLoggerFactory.getLogger().error("empty token cannot save."); |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().error(e.getMessage(), e); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 后台登出 |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
*/ |
||||
public static void logoutByToken(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse,String token) |
||||
{ |
||||
httpServletRequest.setAttribute("fine_auth_token",token); |
||||
logout(httpServletRequest,httpServletResponse); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param httpServletRequest |
||||
* @param httpServletResponse |
||||
*/ |
||||
public static void logout(HttpServletRequest httpServletRequest,HttpServletResponse httpServletResponse) |
||||
{ |
||||
if(!isLogin(httpServletRequest)){ |
||||
return ; |
||||
} |
||||
|
||||
try { |
||||
LoginService.getInstance().logout(httpServletRequest,httpServletResponse); |
||||
} catch (Exception e) { |
||||
ResponseUtils.failedResponse(httpServletResponse,"登出异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:登出异常,请联系管理员!"); |
||||
FineLoggerFactory.getLogger().info("FRLOGException:"+e.getMessage()); |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 打印FR日志 |
||||
* @param message |
||||
*/ |
||||
public static void FRLogInfo(String message){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:"+message); |
||||
} |
||||
|
||||
/** |
||||
* 打印FR日志-error |
||||
* @param message |
||||
*/ |
||||
public static void FRLogError(String message){ |
||||
FineLoggerFactory.getLogger().error("FRLOG:"+message); |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 根据用户名获取用户信息 |
||||
* @param userName |
||||
* @return |
||||
*/ |
||||
public static User getFRUserByUserName(String userName){ |
||||
try { |
||||
return UserService.getInstance().getUserByUserName(userName); |
||||
} catch (Exception e) { |
||||
FRLogInfo("获取用户信息异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return null; |
||||
} |
||||
|
||||
|
||||
/** |
||||
* 根据明文密码生成数据库中的密码,用户密码校验用 |
||||
* @return |
||||
*/ |
||||
public static String getDBPsd(String username,String password){ |
||||
PasswordValidator pv = UserSourceFactory.getInstance().getUserSource(ManualOperationType.KEY).getPasswordValidator(); |
||||
String uuid = UUIDUtil.generate(); |
||||
|
||||
return pv.encode(username, password, uuid); |
||||
} |
||||
|
||||
/** |
||||
* 获取带参数的访问链接 |
||||
* @return |
||||
*/ |
||||
public static String getAllUrl(HttpServletRequest httpServletRequest){ |
||||
return WebUtils.getOriginalURL(httpServletRequest); |
||||
} |
||||
|
||||
/** |
||||
* 根据originKey获取源链接 |
||||
* @param req |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static String getOriginUrl(HttpServletRequest req) throws Exception { |
||||
String url = getAllUrl(req); |
||||
String domain = url.split(TemplateUtils.render("${fineServletURL}"))[0]; |
||||
String origin = req.getParameter("origin"); |
||||
if (StringUtils.isNotEmpty(origin)) { |
||||
OriginUrlResponseBean originUrlResponseBean = (OriginUrlResponseBean) DecisionStatusService.originUrlStatusService().get(origin); |
||||
DecisionStatusService.originUrlStatusService().delete(origin); |
||||
if (originUrlResponseBean != null) { |
||||
return domain+originUrlResponseBean.getOriginUrl(); |
||||
} |
||||
} |
||||
|
||||
return domain+new OriginUrlResponseBean(TemplateUtils.render("${fineServletURL}")).getOriginUrl(); |
||||
} |
||||
|
||||
/** |
||||
* 判断是否开启模板认证 |
||||
* @param |
||||
* @return |
||||
* @throws Exception |
||||
*/ |
||||
public static boolean isTempAuth(HttpServletRequest req,HttpServletResponse res) throws Exception { |
||||
ReportTemplateRequestChecker checker = new ReportTemplateRequestChecker(); |
||||
HandlerMethod hm = new HandlerMethod(new ReportRequestService(),ReportRequestService.class.getMethod("preview", HttpServletRequest.class, HttpServletResponse.class, String.class)); |
||||
return checker.checkRequest(req,res,hm); |
||||
} |
||||
|
||||
/** |
||||
* 获取数据集数据 |
||||
* @param serverDataSetName |
||||
* @return |
||||
*/ |
||||
public static DataModel getTableData(String serverDataSetName){ |
||||
TableData userInfo = TableDataConfig.getInstance().getTableData(serverDataSetName); |
||||
DataModel userInfoDM = userInfo.createDataModel(Calculator.createCalculator()); |
||||
// userInfoDM.getRowCount();
|
||||
// userInfoDM.getColumnIndex();
|
||||
// userInfoDM.getValueAt()
|
||||
return userInfoDM; |
||||
} |
||||
|
||||
public static String getIndex(HttpServletRequest req){ |
||||
String url = req.getScheme()+"://"+req.getServerName()+":"+String.valueOf(req.getServerPort())+req.getRequestURI(); |
||||
return url; |
||||
} |
||||
} |
@ -0,0 +1,262 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.utils; |
||||
|
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.third.org.apache.http.HttpEntity; |
||||
import com.fr.third.org.apache.http.HttpResponse; |
||||
import com.fr.third.org.apache.http.HttpStatus; |
||||
import com.fr.third.org.apache.http.NameValuePair; |
||||
import com.fr.third.org.apache.http.client.CookieStore; |
||||
import com.fr.third.org.apache.http.client.entity.UrlEncodedFormEntity; |
||||
import com.fr.third.org.apache.http.client.methods.HttpGet; |
||||
import com.fr.third.org.apache.http.client.methods.HttpPost; |
||||
import com.fr.third.org.apache.http.conn.ssl.NoopHostnameVerifier; |
||||
import com.fr.third.org.apache.http.entity.StringEntity; |
||||
import com.fr.third.org.apache.http.impl.client.BasicCookieStore; |
||||
import com.fr.third.org.apache.http.impl.client.CloseableHttpClient; |
||||
import com.fr.third.org.apache.http.impl.client.HttpClients; |
||||
import com.fr.third.org.apache.http.impl.cookie.BasicClientCookie; |
||||
import com.fr.third.org.apache.http.message.BasicNameValuePair; |
||||
import com.fr.third.org.apache.http.ssl.SSLContexts; |
||||
import com.fr.third.org.apache.http.ssl.TrustStrategy; |
||||
import com.fr.third.org.apache.http.util.EntityUtils; |
||||
|
||||
import javax.net.ssl.SSLContext; |
||||
import javax.servlet.http.Cookie; |
||||
import java.io.UnsupportedEncodingException; |
||||
import java.security.cert.CertificateException; |
||||
import java.security.cert.X509Certificate; |
||||
import java.util.ArrayList; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.Set; |
||||
|
||||
public class HttpUtils { |
||||
|
||||
/** |
||||
* httpGet请求 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String httpGet(String url,Cookie[] cookies,Map<String,String> header){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--url:"+url); |
||||
|
||||
//创建httpClient
|
||||
CloseableHttpClient httpclient = createHttpClient(cookies); |
||||
|
||||
HttpGet getMethod = new HttpGet(url); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
getMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(getMethod); |
||||
int status =response.getStatusLine().getStatusCode(); |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
|
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--status:"+status); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--returnResult:"+returnResult); |
||||
|
||||
httpclient.close(); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpUtils.get--exception:"+e.getMessage()); |
||||
} |
||||
|
||||
try { |
||||
httpclient.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
/** |
||||
* HttpPost请求 |
||||
* @param postMethod |
||||
* @return |
||||
*/ |
||||
private static String HttpPost(HttpPost postMethod){ |
||||
CloseableHttpClient httpclient = createHttpClient(null); |
||||
|
||||
try { |
||||
HttpResponse response = httpclient.execute(postMethod); |
||||
int status = response.getStatusLine().getStatusCode(); |
||||
HttpEntity entity = response.getEntity(); |
||||
String returnResult = EntityUtils.toString(entity, "utf-8"); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:status:"+status); |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:returnResult:"+returnResult); |
||||
httpclient.close(); |
||||
|
||||
if (status == HttpStatus.SC_OK) { |
||||
return returnResult; |
||||
} |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPost:exception:"+e.getMessage()); |
||||
} |
||||
|
||||
try { |
||||
httpclient.close(); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:http关闭异常:"+e.getMessage()); |
||||
} |
||||
|
||||
return ""; |
||||
} |
||||
|
||||
public static String HttpPostXML(String url, String xmlParam){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-type", "text/html"); |
||||
HttpEntity entity = null; |
||||
try { |
||||
entity = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostXML:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity); |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostText(String url, String xmlParam){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-type", "text/plain"); |
||||
HttpEntity entity = null; |
||||
try { |
||||
entity = new StringEntity(xmlParam); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostText:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity); |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostJson(String url, String param,Map<String,String> header){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
postMethod.setHeader("Content-Type","application/json"); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(!Utils.isNullStr(param)){ |
||||
HttpEntity entity = null; |
||||
try { |
||||
entity = new StringEntity(param); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpPostJSON:参数异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
|
||||
postMethod.setEntity(entity); |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
public static String HttpPostWWWForm(String url, Map<String,String> header,Map<String,String> param){ |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:url:"+url); |
||||
|
||||
HttpPost postMethod = new HttpPost(url); |
||||
|
||||
if(header != null && header.size() > 0){ |
||||
Set<String> keySet = header.keySet(); |
||||
|
||||
for(String key : keySet){ |
||||
postMethod.setHeader(key,header.get(key)); |
||||
} |
||||
} |
||||
|
||||
if(param != null && param.size() > 0){ |
||||
List<NameValuePair> params = new ArrayList<NameValuePair>(param.size()); |
||||
|
||||
for(Map.Entry<String,String> map : param.entrySet()){ |
||||
params.add(new BasicNameValuePair(map.getKey(), map.getValue())); |
||||
} |
||||
|
||||
try { |
||||
postMethod.setEntity(new UrlEncodedFormEntity(params, "UTF-8")); |
||||
} catch (UnsupportedEncodingException e) { |
||||
FineLoggerFactory.getLogger().info("FRLOG:HttpWWWForm:异常:"+e.getMessage()); |
||||
return ""; |
||||
} |
||||
} |
||||
|
||||
return HttpPost(postMethod); |
||||
} |
||||
|
||||
private static CloseableHttpClient createHttpClient(Cookie[] cookies){ |
||||
|
||||
SSLContext sslContext = null; |
||||
try { |
||||
sslContext = SSLContexts.custom().loadTrustMaterial(null, new TrustStrategy() { |
||||
@Override |
||||
public boolean isTrusted(X509Certificate[] x509Certificates, String s) throws CertificateException { |
||||
return true; |
||||
} |
||||
}).build(); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("exception:"+e.getMessage()); |
||||
} |
||||
|
||||
CloseableHttpClient httpclient = null; |
||||
|
||||
if(cookies != null && cookies.length > 0){ |
||||
CookieStore cookieStore = cookieToCookieStore(cookies); |
||||
|
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).setDefaultCookieStore(cookieStore).build(); |
||||
} |
||||
else{ |
||||
httpclient = HttpClients.custom().setSslcontext(sslContext). |
||||
setSSLHostnameVerifier(new NoopHostnameVerifier()).build(); |
||||
} |
||||
|
||||
return httpclient; |
||||
} |
||||
|
||||
/** |
||||
* cookies转cookieStore |
||||
* @param cookies |
||||
* @return |
||||
*/ |
||||
public static CookieStore cookieToCookieStore(Cookie[] cookies){ |
||||
CookieStore cookieStore = new BasicCookieStore(); |
||||
|
||||
if(cookies != null && cookies.length>0){ |
||||
for(Cookie cookie : cookies){ |
||||
BasicClientCookie cookie1 = new BasicClientCookie(cookie.getName(), cookie.getValue()); |
||||
cookieStore.addCookie(cookie1); |
||||
} |
||||
} |
||||
|
||||
return cookieStore; |
||||
} |
||||
} |
@ -0,0 +1,108 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.utils; |
||||
|
||||
import com.fr.json.JSONObject; |
||||
import com.fr.log.FineLoggerFactory; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.PrintWriter; |
||||
|
||||
public class ResponseUtils { |
||||
private static final int SUCCESS = 200; |
||||
private static final int FAILED = -1; |
||||
|
||||
public static void successResponse(HttpServletResponse res, String body) { |
||||
response(res, body, SUCCESS); |
||||
} |
||||
|
||||
public static void failedResponse(HttpServletResponse res, String body) { |
||||
response(res, body, FAILED); |
||||
} |
||||
|
||||
private static void response(HttpServletResponse res, String body, int code) { |
||||
JSONObject object = new JSONObject(); |
||||
PrintWriter pw; |
||||
try { |
||||
object.put("code", code); |
||||
object.put("data", body); |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("application/json;charset=utf-8"); |
||||
String result = object.toString(); |
||||
pw.println(result); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void response(HttpServletResponse res,JSONObject json){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("application/json;charset=utf-8"); |
||||
String result = json.toString(); |
||||
pw.println(result); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void responseText(HttpServletResponse res,String text){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/html;charset=utf-8"); |
||||
pw.println(text); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void responseXml(HttpServletResponse res,String xml){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/xml;charset=utf-8"); |
||||
pw.println(xml); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
|
||||
public static void setCSRFHeader(HttpServletResponse httpServletResponse){ |
||||
httpServletResponse.setHeader("Access-Control-Allow-Origin", "*"); |
||||
httpServletResponse.setHeader("Access-Control-Allow-Methods", "POST,GET,OPTIONS,DELETE,HEAD,PUT,PATCH"); |
||||
httpServletResponse.setHeader("Access-Control-Max-Age", "36000"); |
||||
httpServletResponse.setHeader("Access-Control-Allow-Headers", "Origin, X-Requested-With, Content-Type, Accept,Authorization,authorization"); |
||||
} |
||||
|
||||
public static void responseJsonp(HttpServletRequest req, HttpServletResponse res, JSONObject json){ |
||||
PrintWriter pw; |
||||
try { |
||||
pw = WebUtils.createPrintWriter(res); |
||||
} catch (Exception e) { |
||||
FineLoggerFactory.getLogger().info(e.getMessage()); |
||||
return; |
||||
} |
||||
res.setContentType("text/javascript;charset=utf-8;charset=utf-8"); |
||||
String result = json.toString(); |
||||
|
||||
String jsonp=req.getParameter("callback"); |
||||
|
||||
pw.println(jsonp+"("+result+")"); |
||||
pw.flush(); |
||||
pw.close(); |
||||
} |
||||
} |
@ -0,0 +1,329 @@
|
||||
package com.eco.plugin.xx.zjgintegrate.utils; |
||||
|
||||
import com.fr.base.TemplateUtils; |
||||
import com.fr.data.NetworkHelper; |
||||
import com.fr.decision.webservice.v10.user.UserService; |
||||
import com.fr.io.utils.ResourceIOUtils; |
||||
import com.fr.json.JSONObject; |
||||
import com.fr.stable.CodeUtils; |
||||
import com.fr.stable.StringUtils; |
||||
import com.fr.third.org.apache.commons.codec.digest.DigestUtils; |
||||
import com.fr.web.utils.WebUtils; |
||||
|
||||
import javax.servlet.http.Cookie; |
||||
import javax.servlet.http.HttpServletRequest; |
||||
import javax.servlet.http.HttpServletResponse; |
||||
import java.io.BufferedReader; |
||||
import java.io.InputStream; |
||||
import java.net.URLEncoder; |
||||
import java.util.HashMap; |
||||
import java.util.List; |
||||
import java.util.Map; |
||||
import java.util.UUID; |
||||
import java.util.regex.Matcher; |
||||
import java.util.regex.Pattern; |
||||
|
||||
public class Utils { |
||||
|
||||
/** |
||||
* 判断字符串是否为空 |
||||
* @param str |
||||
* @return true 空字符串 false 非空字符串 |
||||
*/ |
||||
public static boolean isNullStr(String str){ |
||||
return !(str != null && !str.isEmpty() && !"null".equals(str)); |
||||
} |
||||
|
||||
/** |
||||
* 判断字符串是否非空 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static boolean isNotNullStr(String str){ |
||||
return !isNullStr(str); |
||||
} |
||||
|
||||
/** |
||||
* MD5加密 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static String getMd5Str(String str) |
||||
{ |
||||
return DigestUtils.md5Hex(str); |
||||
} |
||||
|
||||
/** |
||||
* 帆软shaEncode加密 |
||||
*/ |
||||
|
||||
public static String shaEncode(String str){ |
||||
return CodeUtils.sha256Encode(str); |
||||
} |
||||
|
||||
/** |
||||
* 获取uuid |
||||
*/ |
||||
public static String uuid(){ |
||||
return UUID.randomUUID().toString(); |
||||
} |
||||
|
||||
/** |
||||
* 替换空字符串 |
||||
* @param str |
||||
* @param replace |
||||
* @return |
||||
*/ |
||||
public static String replaceNullStr(String str,String replace){ |
||||
if(isNullStr(str)){ |
||||
return replace; |
||||
} |
||||
|
||||
return str; |
||||
} |
||||
|
||||
/** |
||||
* 获取请求体 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static JSONObject getRequestBody(HttpServletRequest req){ |
||||
StringBuffer sb = new StringBuffer(); |
||||
String line = null; |
||||
try { |
||||
BufferedReader reader = req.getReader(); |
||||
while ((line = reader.readLine()) != null) |
||||
sb.append(line); |
||||
} catch (Exception e) { |
||||
FRUtils.FRLogInfo("getRequestBody:exception:"+e.getMessage()); |
||||
} |
||||
//将空格和换行符替换掉避免使用反序列化工具解析对象时失败
|
||||
String jsonString = sb.toString().replaceAll("\\s","").replaceAll("\n",""); |
||||
FRUtils.FRLogInfo("reqBody:"+jsonString); |
||||
JSONObject json = new JSONObject(jsonString); |
||||
|
||||
return json; |
||||
} |
||||
|
||||
/** |
||||
* 获取ip |
||||
* @return |
||||
*/ |
||||
public static String getIp(HttpServletRequest req){ |
||||
String realIp = req.getHeader("X-Real-IP"); |
||||
String fw = req.getHeader("X-Forwarded-For"); |
||||
if (StringUtils.isNotEmpty(fw) && !"unKnown".equalsIgnoreCase(fw)) { |
||||
int para3 = fw.indexOf(","); |
||||
return para3 != -1 ? fw.substring(0, para3) : fw; |
||||
} else { |
||||
fw = realIp; |
||||
if (StringUtils.isNotEmpty(realIp) && !"unKnown".equalsIgnoreCase(realIp)) { |
||||
return realIp; |
||||
} else { |
||||
if (StringUtils.isBlank(realIp) || "unknown".equalsIgnoreCase(realIp)) { |
||||
fw = req.getHeader("Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("WL-Proxy-Client-IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_CLIENT_IP"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getHeader("HTTP_X_FORWARDED_FOR"); |
||||
} |
||||
|
||||
if (StringUtils.isBlank(fw) || "unknown".equalsIgnoreCase(fw)) { |
||||
fw = req.getRemoteAddr(); |
||||
} |
||||
|
||||
return fw; |
||||
} |
||||
} |
||||
} |
||||
|
||||
/** |
||||
* 根据key获取cookie |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static String getCookieByKey(HttpServletRequest req,String key){ |
||||
Cookie[] cookies = req.getCookies(); |
||||
String cookie = ""; |
||||
|
||||
if(cookies == null || cookies.length <=0){ |
||||
return ""; |
||||
} |
||||
|
||||
for(int i = 0; i < cookies.length; i++) { |
||||
Cookie item = cookies[i]; |
||||
if (item.getName().equalsIgnoreCase(key)) { |
||||
cookie = item.getValue(); |
||||
} |
||||
} |
||||
|
||||
FRUtils.FRLogInfo("cookie:"+cookie); |
||||
|
||||
return cookie; |
||||
} |
||||
|
||||
/** |
||||
* 判断是否是手机端的链接 |
||||
* @param req |
||||
* @return |
||||
*/ |
||||
public static boolean isMobile(HttpServletRequest req) { |
||||
String[] mobileArray = {"iPhone", "iPad", "android", "windows phone", "xiaomi"}; |
||||
String userAgent = req.getHeader("user-agent"); |
||||
if (userAgent != null && userAgent.toUpperCase().contains("MOBILE")) { |
||||
for(String mobile : mobileArray) { |
||||
if(userAgent.toUpperCase().contains(mobile.toUpperCase())) { |
||||
return true; |
||||
} |
||||
} |
||||
} |
||||
return NetworkHelper.getDevice(req).isMobile(); |
||||
} |
||||
|
||||
/** |
||||
* 只编码中文 |
||||
* @param url |
||||
* @return |
||||
*/ |
||||
public static String encodeCH(String url ){ |
||||
Matcher matcher = Pattern.compile("[\\u4e00-\\u9fa5]").matcher(url); |
||||
|
||||
while(matcher.find()){ |
||||
String chn = matcher.group(); |
||||
url = url.replaceAll(chn, URLEncoder.encode(chn)); |
||||
} |
||||
|
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 获取web-inf文件夹下的文件 |
||||
* filename /resources/ip4enc.properties |
||||
*/ |
||||
public static InputStream getResourcesFile(String filename){ |
||||
return ResourceIOUtils.read(filename); |
||||
} |
||||
|
||||
/** |
||||
* |
||||
* @param res |
||||
* @param path /com/fr/plugin/loginAuth/html/getMac.html |
||||
* @param parameterMap |
||||
*/ |
||||
public static void toErrorPage(HttpServletResponse res,String path,Map<String, String> parameterMap){ |
||||
if(parameterMap == null){ |
||||
parameterMap = new HashMap<String, String>(); |
||||
} |
||||
|
||||
try { |
||||
String macPage = TemplateUtils.renderTemplate(path, parameterMap); |
||||
WebUtils.printAsString(res, macPage); |
||||
}catch (Exception e){ |
||||
FRUtils.FRLogError("跳转页面异常"); |
||||
} |
||||
|
||||
} |
||||
|
||||
/** |
||||
* 判断是否是管理员 |
||||
* @param username |
||||
* @return |
||||
*/ |
||||
public static boolean isAdmin(String username) throws Exception{ |
||||
return UserService.getInstance().isAdmin(UserService.getInstance().getUserByUserName(username).getId()); |
||||
} |
||||
|
||||
/** |
||||
* 去掉浏览器中的参数 |
||||
* @param url |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
public static String removeParam(String url,String param){ |
||||
if(!url.contains("?"+param) && !url.contains("&"+param)){ |
||||
return url; |
||||
} |
||||
|
||||
return url.substring(0,url.indexOf(url.contains("?"+param) ? "?"+param : "&"+param)); |
||||
} |
||||
|
||||
/** |
||||
* 获取跳转链接 |
||||
* @param req |
||||
* @param param |
||||
* @return |
||||
*/ |
||||
public static String getRedirectUrl(HttpServletRequest req,String param){ |
||||
String url = FRUtils.getAllUrl(req); |
||||
|
||||
if(isNotNullStr(param)){ |
||||
url = removeParam(url,param); |
||||
} |
||||
|
||||
url = encodeCH(url); |
||||
|
||||
return url; |
||||
} |
||||
|
||||
/** |
||||
* 去除空格换行 |
||||
* @param str |
||||
* @return |
||||
*/ |
||||
public static String trim(String str){ |
||||
return str.trim().replaceAll("\n","").replaceAll("\r",""); |
||||
} |
||||
|
||||
/** |
||||
* list 转化为指定字符分割的字符串 |
||||
* @param list |
||||
* @param list |
||||
* @return |
||||
*/ |
||||
public static String listToStr(List<String> list, String split){ |
||||
String result = ""; |
||||
|
||||
if(list == null || list.size() <= 0){ |
||||
return result; |
||||
} |
||||
|
||||
for(String str : list){ |
||||
result+=","+str; |
||||
} |
||||
|
||||
result = result.substring(1); |
||||
|
||||
return result; |
||||
} |
||||
|
||||
/** |
||||
* array 转化为指定字符分割的字符串 |
||||
* @param list |
||||
* @param list |
||||
* @return |
||||
*/ |
||||
public static String arrayToStr(String[] list, String split){ |
||||
String result = ""; |
||||
|
||||
if(list == null ||list.length <= 0){ |
||||
return result; |
||||
} |
||||
|
||||
for(int i=0;i<list.length;i++){ |
||||
String str = list[i]; |
||||
result+=","+str; |
||||
} |
||||
|
||||
result = result.substring(1); |
||||
|
||||
return result; |
||||
} |
||||
} |
@ -0,0 +1,50 @@
|
||||
<!DOCTYPE html> |
||||
<html> |
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<meta name="viewport" content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover"> |
||||
<title>单点登陆</title> |
||||
<script src="../lib/xmmp.sdk.min.js"></script> |
||||
<script src="../lib/vconsole.min.js"></script> |
||||
<script> |
||||
var vConsole = new window.VConsole(); |
||||
|
||||
var frindex = "http://xx/webroot/decision" |
||||
|
||||
function GetRequest() { |
||||
var urlStr = window.location.href; |
||||
if (typeof urlStr == "undefined") { |
||||
// 获取url中"?"符后的字符串 |
||||
var url = decodeURI(location.search); |
||||
} else { |
||||
var url = "?" + urlStr.split("?")[1]; |
||||
} |
||||
var theRequest = new Object(); |
||||
if (url.indexOf("?") != -1) { |
||||
var str = url.substr(1); |
||||
strs = str.split("&"); |
||||
for (var i = 0; i < strs.length; i++) { |
||||
theRequest[strs[i].split("=")[0]] = decodeURI(strs[i].split("=")[1]); |
||||
} |
||||
} |
||||
|
||||
return theRequest; |
||||
} |
||||
|
||||
window.onload = function(){ |
||||
xm.getAuthCode({appkey: 'SZKB'}).then(function(res){ |
||||
var ticket = encodeURIComponent(res); |
||||
var redirect = GetRequest().redirect; |
||||
var url = frindex+"/ssoLogin?ticket="+ticket+"&redirect=http://xx/webroot/decision"; |
||||
console.log(url); |
||||
// window.location.href = frindex+"/ssoLogin?ticket="+ticket+"&redirect="+redirect; |
||||
window.location.href = url; |
||||
}); |
||||
} |
||||
|
||||
|
||||
</script> |
||||
</head> |
||||
<body> |
||||
</body> |
||||
</html> |
@ -0,0 +1,59 @@
|
||||
<!DOCTYPE html> |
||||
<html> |
||||
|
||||
<head> |
||||
<meta charset="UTF-8"> |
||||
<meta name="viewport" |
||||
content="width=device-width,initial-scale=1,minimum-scale=1,maximum-scale=1,user-scalable=no,viewport-fit=cover"> |
||||
<title>token</title> |
||||
<link rel="stylesheet" href="../styles/index.css"> |
||||
<script src="../lib/xmmp.sdk.min.js"></script> |
||||
<script src="../lib/vconsole.min.js"></script> |
||||
</head> |
||||
|
||||
<body> |
||||
<div class="api"> |
||||
<span>xm.getAuthCode/xm.getToken</span> |
||||
</div> |
||||
|
||||
<div class="tip">注意:getAuthCode为获取华为IAM SSO票据的API,SDK只负责统一调用API的方式,需要接入SDK的客户端实现此函数</div> |
||||
|
||||
<div class="form"> |
||||
<div class="form-item"><label>authCode</label><input id="J_code" disabled /></div> |
||||
</div> |
||||
|
||||
<div class="btn-wrap"> |
||||
<button class="btn" id="J_getAuthCode">getAuthCode</button> |
||||
</div> |
||||
|
||||
<div class="tip">注意:getToken为获取业务方自有token的API,SDK只负责统一调用API的方式,需要接入SDK的客户端实现此函数</div> |
||||
<div class="form"> |
||||
<div class="form-item"><label>token</label><input id="J_token" disabled /></div> |
||||
</div> |
||||
<div class="btn-wrap"> |
||||
<button class="btn" id="J_getToken">getToken</button> |
||||
</div> |
||||
|
||||
<script> |
||||
var vConsole = new window.VConsole(); |
||||
console.log("🚀 ~ file: token.html ~ line 36 ~ vConsole", "click") |
||||
document.getElementById('J_getAuthCode').addEventListener('click', function () { |
||||
console.log("🚀 ~ file: token.html ~ line 38 ~ vConsole", "进入了getAuthCode方法") |
||||
xm.getAuthCode({ |
||||
appkey: 'SZKB' |
||||
}).then(function (res) { |
||||
console.log("🚀 ~ file: token.html ~ line 45 ~ res", res) |
||||
}) |
||||
}) |
||||
|
||||
document.getElementById('J_getToken').addEventListener('click', function () { |
||||
xm.getToken().then(function (res) { |
||||
console.log("token", res) |
||||
|
||||
document.getElementById('J_token').value = res |
||||
}) |
||||
}) |
||||
</script> |
||||
</body> |
||||
|
||||
</html> |
Loading…
Reference in new issue