项目初始化创建
This commit is contained in:
45
src/com/seeyon/apps/qrCodeForm/QrCodeFormPluginApi.java
Normal file
45
src/com/seeyon/apps/qrCodeForm/QrCodeFormPluginApi.java
Normal file
@@ -0,0 +1,45 @@
|
||||
package com.seeyon.apps.qrCodeForm;
|
||||
|
||||
import com.seeyon.apps.common.plugin.api.APluginInfoApi;
|
||||
import com.seeyon.apps.common.plugin.vo.ConfigVo;
|
||||
import com.seeyon.apps.qrCodeForm.constant.QrCodeFormConstants;
|
||||
|
||||
/**
|
||||
* 功能描述:<br>
|
||||
* <pre>
|
||||
*
|
||||
* </pre>
|
||||
*
|
||||
* @Author: FanGaowei
|
||||
* @Date: 2022/8/11
|
||||
*/
|
||||
public class QrCodeFormPluginApi extends APluginInfoApi {
|
||||
|
||||
@Override
|
||||
public String getPluginId() {
|
||||
return QrCodeFormConstants.getPluginId();
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getCreateUser() {
|
||||
return "致威互联";
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getDescription() {
|
||||
return "微信扫码制单";
|
||||
}
|
||||
|
||||
@Override
|
||||
public ConfigVo getDefaultConfig() {
|
||||
ConfigVo configVo = new ConfigVo();
|
||||
for (QrCodeFormConstants value : QrCodeFormConstants.values()) {
|
||||
if(value != QrCodeFormConstants.plugin) {
|
||||
configVo.getDevParams().put(value.name(), value.getDefaultValue());
|
||||
configVo.getProdParams().put(value.name(), value.getDefaultValue());
|
||||
configVo.getParamMap().put(value.name(), value.getDescription());
|
||||
}
|
||||
}
|
||||
return configVo;
|
||||
}
|
||||
}
|
||||
@@ -0,0 +1,23 @@
|
||||
package com.seeyon.apps.qrCodeForm;
|
||||
|
||||
import com.seeyon.apps.qrCodeForm.util.InitQrCodeFormUitl;
|
||||
import com.seeyon.ctp.common.AbstractSystemInitializer;
|
||||
import com.seeyon.ctp.common.exceptions.BusinessException;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
public class QrCodeFormPluginInitializer extends AbstractSystemInitializer {
|
||||
private static Log log = LogFactory.getLog(QrCodeFormPluginInitializer.class);
|
||||
|
||||
public QrCodeFormPluginInitializer() {
|
||||
}
|
||||
|
||||
public void destroy() {
|
||||
log.info("◆二维码扫码填单插件销毁成功!");
|
||||
}
|
||||
|
||||
public void initialize() {
|
||||
InitQrCodeFormUitl.initMenu();
|
||||
log.info("◆二维码扫码填单插件初始化成功!");
|
||||
}
|
||||
}
|
||||
15
src/com/seeyon/apps/qrCodeForm/constant/Constants.java
Normal file
15
src/com/seeyon/apps/qrCodeForm/constant/Constants.java
Normal file
@@ -0,0 +1,15 @@
|
||||
package com.seeyon.apps.qrCodeForm.constant;
|
||||
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
|
||||
public class Constants {
|
||||
|
||||
//模拟移动端登录认证方式
|
||||
public static final String _REDIRECTURI = "/qrCodeForm.do?method=newMain&html=";
|
||||
//流程表单跳转地址
|
||||
public static final String FLOW_URL = "/seeyon/m3/apps/v5/collaboration/html/newCollaboration.html?qc=ext&templateId=";
|
||||
//无流程表单跳转地址
|
||||
public static final String UNFLOW_URL = "/seeyon/m3/apps/v5/cap4/htmls/native/form/index.html?";
|
||||
|
||||
|
||||
}
|
||||
@@ -0,0 +1,32 @@
|
||||
package com.seeyon.apps.qrCodeForm.constant;
|
||||
|
||||
public enum QrCodeFormConstants {
|
||||
|
||||
plugin("qrCodeForm","插件ID"),
|
||||
oaAddress("https://oa.dhx.com.cn", "OA地址"),
|
||||
qwAppId("", "企微APPID"),
|
||||
restId("qrcode", "rest账号"),
|
||||
restPwd("f39f8102-1c7f-423c-8e6c-57e1d19b9a6f", "rest密码"),
|
||||
qrcode_loginname("hr", "发起人账号");
|
||||
|
||||
QrCodeFormConstants(String defaultValue, String description) {
|
||||
this.defaultValue = defaultValue;
|
||||
this.description = description;
|
||||
}
|
||||
|
||||
private String defaultValue;
|
||||
private String description;
|
||||
|
||||
public String getDefaultValue() {
|
||||
return defaultValue;
|
||||
}
|
||||
|
||||
public String getDescription() {
|
||||
return description;
|
||||
}
|
||||
|
||||
public static String getPluginId() {
|
||||
return plugin.defaultValue;
|
||||
}
|
||||
|
||||
}
|
||||
31
src/com/seeyon/apps/qrCodeForm/constant/SupportTypeEnum.java
Normal file
31
src/com/seeyon/apps/qrCodeForm/constant/SupportTypeEnum.java
Normal file
@@ -0,0 +1,31 @@
|
||||
package com.seeyon.apps.qrCodeForm.constant;
|
||||
|
||||
import com.seeyon.ctp.common.code.EnumsCode;
|
||||
import com.seeyon.ctp.common.i18n.ResourceUtil;
|
||||
|
||||
public enum SupportTypeEnum implements EnumsCode {
|
||||
ALL(0, "全部"),
|
||||
FLOW(1, "仅支持流程表单"),
|
||||
UNFLOW(2, "仅支持无流程表单");
|
||||
|
||||
private int key;
|
||||
private String text;
|
||||
|
||||
private SupportTypeEnum(int key, String text) {
|
||||
this.key = key;
|
||||
this.text = text;
|
||||
}
|
||||
|
||||
public String getValue() {
|
||||
return String.valueOf(this.key);
|
||||
}
|
||||
|
||||
public int getKey() {
|
||||
return this.key;
|
||||
}
|
||||
|
||||
public String getText() {
|
||||
return ResourceUtil.getString(this.text);
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,110 @@
|
||||
package com.seeyon.apps.qrCodeForm.controller;
|
||||
|
||||
import com.seeyon.apps.common.config.ICstConfigApi;
|
||||
import com.seeyon.apps.qrCodeForm.constant.QrCodeFormConstants;
|
||||
import com.seeyon.apps.qrCodeForm.manager.QrCodeFormManager;
|
||||
import com.seeyon.apps.qrCodeForm.util.LoginUtil;
|
||||
import com.seeyon.apps.weixin.util.SecurityCertUtil;
|
||||
import com.seeyon.apps.weixin.util.WeixinUtil;
|
||||
import com.seeyon.ctp.common.SystemEnvironment;
|
||||
import com.seeyon.ctp.common.constants.ProductEditionEnum;
|
||||
import com.seeyon.ctp.common.controller.BaseController;
|
||||
import com.seeyon.ctp.common.flag.SysFlag;
|
||||
import com.seeyon.ctp.common.formula.FormulaUtil;
|
||||
import com.seeyon.ctp.common.log.CtpLogFactory;
|
||||
import com.seeyon.ctp.organization.bo.V3xOrgMember;
|
||||
import com.seeyon.ctp.organization.manager.OrgManager;
|
||||
import com.seeyon.ctp.util.Strings;
|
||||
import com.seeyon.ctp.util.annotation.Inject;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.springframework.web.servlet.ModelAndView;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.net.URLDecoder;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public class QrCodeFormController extends BaseController {
|
||||
private static Log log = CtpLogFactory.getLog(QrCodeFormController.class);
|
||||
@Inject
|
||||
private QrCodeFormManager qrCodeFormManager;
|
||||
@Inject
|
||||
private OrgManager orgManager;
|
||||
@Inject
|
||||
private ICstConfigApi cstConfigApi;
|
||||
|
||||
public ModelAndView index(HttpServletRequest request, HttpServletResponse response) {
|
||||
log.info("访问二维码生成页面!");
|
||||
ModelAndView mav = new ModelAndView("plugin/qrCodeForm/qrCodeFormIndex");
|
||||
Map map = new HashMap<String, Object>();
|
||||
map.put("bizType", "1");
|
||||
map.put("type", "owner-authed-biz");
|
||||
map.put("businessType", 0);
|
||||
map.put("activeTab", "mineapp");
|
||||
List<Map<String, Object>> bizList = qrCodeFormManager.listBusiness(map);
|
||||
mav.addObject("bizList", bizList);
|
||||
return mav;
|
||||
}
|
||||
|
||||
|
||||
public ModelAndView newMain(HttpServletRequest request, HttpServletResponse response) throws Exception {
|
||||
ModelAndView mav = new ModelAndView("/wechat/collaborationContent");
|
||||
String html = "";
|
||||
String type = request.getParameter("type");
|
||||
if(Strings.isNotBlank(type)) {
|
||||
html = cstConfigApi.getConfig(QrCodeFormConstants.getPluginId(), "url" + type);
|
||||
}
|
||||
if(Strings.isBlank(html)) {
|
||||
html = URLDecoder.decode(request.getParameter("html"), "UTF-8");
|
||||
}
|
||||
// String loginName = qrCodeFormManager.getLoginMember(code);
|
||||
/**
|
||||
* 客开改动,固定登录名
|
||||
*/
|
||||
//String loginName = (String) FormulaUtil.getVar("qrcode_loginname");
|
||||
String loginName = cstConfigApi.getConfig(QrCodeFormConstants.getPluginId(), QrCodeFormConstants.qrcode_loginname.name());
|
||||
log.info("登录认证获取loginName为:" + loginName);
|
||||
if(Strings.isEmpty(loginName)){
|
||||
// mav.addObject("msg", "未获取到人员信息!")b;
|
||||
// return mav;
|
||||
loginName = "seeyon";
|
||||
}
|
||||
|
||||
V3xOrgMember member = orgManager.getMemberByLoginName(loginName);
|
||||
if(member == null){
|
||||
mav.addObject("msg", "人员不存在!");
|
||||
return mav;
|
||||
}
|
||||
SecurityCertUtil.login(request, loginName);
|
||||
|
||||
Map map = LoginUtil.getToken(String.valueOf(member.getId()), member.getLoginName(), request, response);
|
||||
String success = String.valueOf(map.get("success"));
|
||||
if (success != null && "false".equals(success)) {
|
||||
// String message = map.get("message").toString();
|
||||
// if (message.contains("User not found")) {
|
||||
// mav.addObject("msg", ResourceUtil.getString("wxt.user.binding.miss")
|
||||
// + "," + ResourceUtil.getString("wxt.user.name") + wechatUser.getXtUserName() +
|
||||
// "," + ResourceUtil.getString("wxt.dingding.user.id") + wechatUser.getXtUserId());
|
||||
// } else {
|
||||
// }
|
||||
mav.addObject("msg", (String) map.get("message"));
|
||||
return mav;
|
||||
}
|
||||
|
||||
String token = (String) map.get("id");
|
||||
String suffix = (String) SysFlag.mobileEditionSuffix.getFlag();
|
||||
String edition = ProductEditionEnum.getCurrentProductEditionEnum().getValue();
|
||||
String v5timestamp = WeixinUtil.getV5Timestamp();
|
||||
String address = cstConfigApi.getConfig(QrCodeFormConstants.getPluginId(), QrCodeFormConstants.oaAddress.name());
|
||||
if (Strings.isNotBlank(html)) {
|
||||
String url = address + "" + SystemEnvironment.getContextPath() + "/H5/collaboration/index.html?token=" + token + "&edition=" + edition + "&suffix=" + suffix + "&v5timestamp=" + v5timestamp + "&loginName=" + member.getLoginName() + "&html=" + URLEncoder.encode(html, "UTF-8") + "&isAccount=&accountid=" + member.getOrgAccountId() + "&appid=";
|
||||
return new ModelAndView("redirect:" + url);
|
||||
} else {
|
||||
return new ModelAndView("redirect:" + address + "" + SystemEnvironment.getContextPath() + "/H5/collaboration/index.html?token=" + token + "&edition=" + edition + "&suffix=" + suffix + "&v5timestamp=" + v5timestamp + "&loginName=" + member.getLoginName() + "&html=&isAccount=&accountid=" + member.getOrgAccountId());
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
@@ -0,0 +1,18 @@
|
||||
package com.seeyon.apps.qrCodeForm.manager;
|
||||
|
||||
import com.seeyon.cap4.form.modules.business.FormAppBO;
|
||||
import com.seeyon.ctp.util.annotation.AjaxAccess;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
public interface QrCodeFormManager {
|
||||
@AjaxAccess
|
||||
List<Map<String, Object>> listBusiness(Map<String, Object> params);
|
||||
|
||||
@AjaxAccess
|
||||
List<FormAppBO> listFormApp(Map<String, Object> params);
|
||||
|
||||
Map<String, Object> qrCodeFormUrl(Map<String, Object> params) throws UnsupportedEncodingException;
|
||||
}
|
||||
@@ -0,0 +1,160 @@
|
||||
package com.seeyon.apps.qrCodeForm.manager;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.seeyon.apps.common.config.ICstConfigApi;
|
||||
import com.seeyon.apps.qrCodeForm.constant.Constants;
|
||||
import com.seeyon.apps.qrCodeForm.constant.QrCodeFormConstants;
|
||||
import com.seeyon.apps.qrCodeForm.constant.SupportTypeEnum;
|
||||
import com.seeyon.apps.weixin.manager.WechatUserManager;
|
||||
import com.seeyon.apps.weixin.po.WechatUser;
|
||||
import com.seeyon.cap4.form.api.FormApi4Cap4;
|
||||
import com.seeyon.cap4.form.modules.business.BusinessSourceTypeManager;
|
||||
import com.seeyon.cap4.form.modules.business.FormAppBO;
|
||||
import com.seeyon.cap4.form.util.BizUtil;
|
||||
import com.seeyon.cap4.form.util.Enums;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.SystemEnvironment;
|
||||
import com.seeyon.ctp.common.exceptions.BusinessException;
|
||||
import com.seeyon.ctp.common.log.CtpLogFactory;
|
||||
import com.seeyon.ctp.organization.bo.V3xOrgMember;
|
||||
import com.seeyon.ctp.organization.manager.OrgManager;
|
||||
import com.seeyon.ctp.util.FlipInfo;
|
||||
import com.seeyon.ctp.util.HttpClientUtil;
|
||||
import com.seeyon.ctp.util.ParamUtil;
|
||||
import com.seeyon.ctp.util.Strings;
|
||||
import com.seeyon.ctp.util.annotation.AjaxAccess;
|
||||
import com.seeyon.ctp.util.annotation.Inject;
|
||||
import org.apache.commons.logging.Log;
|
||||
|
||||
import java.io.UnsupportedEncodingException;
|
||||
import java.net.URLEncoder;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.stream.Collectors;
|
||||
|
||||
public class QrCodeFormManagerImpl implements QrCodeFormManager {
|
||||
|
||||
private static Log log = CtpLogFactory.getLog(QrCodeFormManagerImpl.class);
|
||||
|
||||
@Inject
|
||||
private FormApi4Cap4 formApi4Cap4;
|
||||
@Inject
|
||||
private OrgManager orgManager;
|
||||
@Inject
|
||||
private ICstConfigApi cstConfigApi;
|
||||
@Inject
|
||||
public WechatUserManager wechatUserManager;
|
||||
|
||||
|
||||
/**
|
||||
* 获取应用包数据
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@Override
|
||||
@AjaxAccess
|
||||
public List<Map<String, Object>> listBusiness(Map<String, Object> params) {
|
||||
List<Map<String, Object>> listMap = new ArrayList<Map<String, Object>>();
|
||||
try {
|
||||
FlipInfo fi = new FlipInfo(1, -1);
|
||||
Map<String, Object> resultMap = formApi4Cap4.listBusiness(fi, params);
|
||||
if (Strings.isNotEmpty(fi.getData())) {
|
||||
listMap = fi.getData();
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
return listMap;
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取所有的应用下的模板
|
||||
*
|
||||
* @param params
|
||||
* @return
|
||||
*/
|
||||
@AjaxAccess
|
||||
@Override
|
||||
public List<FormAppBO> listFormApp(Map<String, Object> params) {
|
||||
List<FormAppBO> returnList = new ArrayList<>();
|
||||
String type = ParamUtil.getString(params, "type");
|
||||
String bizConfigId = ParamUtil.getString(params, "bizConfigId");
|
||||
BusinessSourceTypeManager sourceType = BizUtil.getSourceTypeById(type);
|
||||
Long bizConfigL = 0L;
|
||||
if (Strings.isNotBlank(bizConfigId)) {
|
||||
bizConfigL = Long.parseLong(bizConfigId);
|
||||
}
|
||||
try {
|
||||
List<FormAppBO> allList = sourceType.getFormAppBOList(AppContext.getCurrentUser(), "", "", false, bizConfigL);
|
||||
if (Strings.isNotEmpty(allList)) {
|
||||
returnList = allList.stream().filter(a -> !"PARENT".equals(a.getSourctTypeName())).collect(Collectors.toList());
|
||||
}
|
||||
} catch (BusinessException e) {
|
||||
log.error("获取所有模板异常", e);
|
||||
}
|
||||
return returnList;
|
||||
}
|
||||
|
||||
@Override
|
||||
@AjaxAccess
|
||||
public Map<String, Object> qrCodeFormUrl(Map<String, Object> params) throws UnsupportedEncodingException {
|
||||
Map<String, Object> result = new HashMap<>();
|
||||
Integer sourceType = ParamUtil.getInt(params, "sourceType");
|
||||
//String fillUrl = Constants._URLTPL.replaceAll("\\{corpId}", Constants._CORPID);
|
||||
String fillUrl;
|
||||
String _redirecturi = Constants._REDIRECTURI;
|
||||
if (sourceType == Enums.SourceType.SOURCE_TYPE_FLOWTEMPLATE.getKey()) {
|
||||
String templateId = ParamUtil.getString(params, "templateId");
|
||||
String tourl = Constants.FLOW_URL + templateId;
|
||||
try {
|
||||
// fillUrl = fillUrl + URLEncoder.encode(
|
||||
String address = cstConfigApi.getConfig(QrCodeFormConstants.getPluginId(), QrCodeFormConstants.oaAddress.name());;
|
||||
fillUrl = address + SystemEnvironment.getContextPath() + _redirecturi;
|
||||
fillUrl += URLEncoder.encode(tourl, "UTF-8");
|
||||
// "http://172.16.30.123:8081"+ SystemEnvironment.getContextPath() + _redirecturi + tourl, "UTF-8"
|
||||
// ) + Constants._FIXURL;
|
||||
result.put("fillUrl", fillUrl);
|
||||
return result;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("地址处理异常", e);
|
||||
}
|
||||
} else if (sourceType == Enums.SourceType.SOURCE_TYPE_INFOMANAGE.getKey()) {
|
||||
String formType = ParamUtil.getString(params, "formType");
|
||||
String type = ParamUtil.getString(params, "type");
|
||||
String title = ParamUtil.getString(params, "title");
|
||||
String moduleId = ParamUtil.getString(params, "moduleId");
|
||||
String formTemplateId = ParamUtil.getString(params, "formTemplateId");
|
||||
String moduleType = ParamUtil.getString(params, "moduleType");
|
||||
String operateType = ParamUtil.getString(params, "operateType");
|
||||
String rightId = ParamUtil.getString(params, "rightId");
|
||||
//http://127.0.0.1/seeyon/qrCodeForm.do?method=newMain&html=/seeyon/m3/apps/v5/cap4/htmls/native/form/index.html?cusType=true&formTemplateId=-4624141853295951831&moduleId=-4624141853295951831&moduleType=42&formType=main&type=new&operateType=0&rightId=-1
|
||||
String tourl = Constants.UNFLOW_URL + "cusType=true"
|
||||
+ "&formTemplateId=" + formTemplateId
|
||||
+ "&moduleId=" + moduleId
|
||||
+ "&moduleType=" + moduleType
|
||||
+ "&formType=" + formType
|
||||
+ "&type=" + type
|
||||
+ "&rightId=" + rightId
|
||||
+ "&operateType=" + operateType;
|
||||
try {
|
||||
// fillUrl = fillUrl + URLEncoder.encode(
|
||||
String address = cstConfigApi.getConfig(QrCodeFormConstants.getPluginId(), QrCodeFormConstants.oaAddress.name());
|
||||
fillUrl = address + SystemEnvironment.getContextPath() + _redirecturi;
|
||||
|
||||
fillUrl += URLEncoder.encode(tourl, "UTF-8");
|
||||
// "http://172.16.30.123:80"+ SystemEnvironment.getContextPath() + _redirecturi + tourl, "UTF-8"
|
||||
// ) + Constants._FIXURL;
|
||||
log.info("生成地址为:" + fillUrl);
|
||||
result.put("fillUrl", fillUrl);
|
||||
return result;
|
||||
} catch (UnsupportedEncodingException e) {
|
||||
log.error("地址处理异常", e);
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
|
||||
}
|
||||
141
src/com/seeyon/apps/qrCodeForm/sso/WechatQRHandShake.java
Normal file
141
src/com/seeyon/apps/qrCodeForm/sso/WechatQRHandShake.java
Normal file
@@ -0,0 +1,141 @@
|
||||
package com.seeyon.apps.qrCodeForm.sso;
|
||||
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.seeyon.apps.weixin.manager.WechatUserManager;
|
||||
import com.seeyon.apps.weixin.po.WechatUser;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.log.CtpLogFactory;
|
||||
import com.seeyon.ctp.organization.bo.V3xOrgMember;
|
||||
import com.seeyon.ctp.organization.manager.OrgManager;
|
||||
import com.seeyon.ctp.portal.sso.SSOLoginContext;
|
||||
import com.seeyon.ctp.portal.sso.SSOLoginHandshakeAbstract;
|
||||
import com.seeyon.ctp.util.HttpClientUtil;
|
||||
import com.seeyon.ctp.util.Strings;
|
||||
import com.seeyon.ctp.util.annotation.Inject;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.springframework.beans.factory.annotation.Autowired;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* @author
|
||||
* @title: WechatQRHandShake
|
||||
* @description: 企业微信扫码发起单据
|
||||
* @date 2021/11/30 9:47
|
||||
*/
|
||||
public class WechatQRHandShake extends SSOLoginHandshakeAbstract {
|
||||
|
||||
private static final Log log = CtpLogFactory.getLog(WechatQRHandShake.class);
|
||||
//企业微信appid
|
||||
public static final String _CORPID = AppContext.getSystemProperty("qrCodeForm.corpid");
|
||||
//企业微信corpsecret
|
||||
public static final String _corpsecret = AppContext.getSystemProperty("qrCodeForm.corpsecret");
|
||||
//验证方式
|
||||
public static final String handshakeType = AppContext.getSystemProperty("qrCodeForm.handshakeType");
|
||||
|
||||
@Inject
|
||||
public WechatUserManager wechatUserManager;
|
||||
@Autowired
|
||||
private OrgManager orgManager;
|
||||
@Override
|
||||
public String handshake(String s) {
|
||||
log.info("--进入企业微信回调接口!");
|
||||
HttpServletRequest request = AppContext.getRawRequest();
|
||||
String code =request.getParameter("code");
|
||||
|
||||
String corpid =_CORPID;
|
||||
String corpsecret =_corpsecret;
|
||||
|
||||
log.info("获取access接口url:https://qyapi.weixin.qq.com/cgi-bin/gettoken?"+"corpid="+corpid+"&corpsecret="+corpsecret);
|
||||
String access = null;
|
||||
try {
|
||||
access = HttpClientUtil.getContent("https://qyapi.weixin.qq.com/cgi-bin/gettoken?corpid="+corpid+"&corpsecret="+corpsecret);
|
||||
log.info("获取access接口返回:"+access);
|
||||
if(access==null || access.equals("")){
|
||||
log.error("--未获取到access!");
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject jsonObject = JSONObject.parseObject(access);
|
||||
if(jsonObject==null){
|
||||
log.error("--未获取到access的jsonObject!");
|
||||
return null;
|
||||
}
|
||||
|
||||
String accessToken = (String)jsonObject.get("access_token");
|
||||
if(accessToken==null || accessToken.equals("")){
|
||||
log.error("--未获取到accessToken!");
|
||||
return null;
|
||||
}
|
||||
|
||||
log.info("--获取访问用户身份接口url:https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?"+"access_token=" + accessToken + "&code=" + code);
|
||||
String user = HttpClientUtil.getContent("https://qyapi.weixin.qq.com/cgi-bin/user/getuserinfo?access_token=" + accessToken + "&code=" + code);
|
||||
log.info("--获取访问用户身份接口返回值:" + user);
|
||||
if(user==null || user.equals("")){
|
||||
log.error("--未获取到user!");
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject userJson = JSONObject.parseObject(user);
|
||||
if(userJson==null){
|
||||
log.error("--未获取到user的jsonObject!");
|
||||
return null;
|
||||
}
|
||||
|
||||
String userid = userJson.getString("UserId");
|
||||
if(userid==null || userid.equals("")){
|
||||
log.error("--未获取到userid!");
|
||||
return null;
|
||||
}
|
||||
String Loginname = null;
|
||||
// if("1".equals(handshakeType)){//使用标准模块的微信绑定
|
||||
if(false){ //企业微信、微协同绑定等信息存储在微协同云服务中,废弃逻辑
|
||||
WechatUser wechatUser =wechatUserManager.getWechatUserByUserIdAndcorpId(userid,corpid);
|
||||
Loginname=wechatUser.getXtLoginName();
|
||||
}else {//自定义如何根据微信得用户id获取OA的用户
|
||||
log.info("--获取成员接口url:https://qyapi.weixin.qq.com/cgi-bin/user/get?"+"access_token=" + accessToken + "&userid=" + userid);
|
||||
String member = HttpClientUtil.getContent("https://qyapi.weixin.qq.com/cgi-bin/user/get?access_token=" + accessToken + "&userid=" + userid);
|
||||
log.info("获取成员接口返回值:" + member);
|
||||
if(member==null || member.equals("")){
|
||||
log.error("--未获取到member!");
|
||||
return null;
|
||||
}
|
||||
|
||||
JSONObject memberJson = JSONObject.parseObject(member);
|
||||
if(userJson==null){
|
||||
log.error("--未获取到member的jsonObject!");
|
||||
return null;
|
||||
}
|
||||
|
||||
String mobile = memberJson.getString("mobile");
|
||||
if(mobile==null || mobile.equals("")){
|
||||
log.error("--未获取到mobile!");
|
||||
return null;
|
||||
}
|
||||
List<V3xOrgMember> memberList=orgManager.getMemberListByMobile(mobile,null);
|
||||
Loginname = memberList!=null?memberList.get(0).getLoginName():null;
|
||||
}
|
||||
if(Loginname ==null || Loginname.equals("")){
|
||||
log.error("--未获取到loginName!");
|
||||
return null;
|
||||
}
|
||||
return Loginname;
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("获取微信验证失败",e);
|
||||
}
|
||||
|
||||
return null;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void logoutNotify(String s) {
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public String getToUrl(HttpServletRequest req, SSOLoginContext ssoLoginContext, String ticket) {
|
||||
return req.getParameter("tourl");
|
||||
}
|
||||
}
|
||||
117
src/com/seeyon/apps/qrCodeForm/util/InitQrCodeFormUitl.java
Normal file
117
src/com/seeyon/apps/qrCodeForm/util/InitQrCodeFormUitl.java
Normal file
@@ -0,0 +1,117 @@
|
||||
package com.seeyon.apps.qrCodeForm.util;
|
||||
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.exceptions.BusinessException;
|
||||
import com.seeyon.ctp.privilege.bo.PrivMenuBO;
|
||||
import com.seeyon.ctp.privilege.enums.PrivMenuTypeEnums;
|
||||
import com.seeyon.ctp.privilege.manager.PrivilegeMenuManager;
|
||||
import com.seeyon.ctp.privilege.po.PrivMenu;
|
||||
import com.seeyon.ctp.util.DBAgent;
|
||||
import com.seeyon.ctp.util.DateUtil;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import java.text.ParseException;
|
||||
import java.text.SimpleDateFormat;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Calendar;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
|
||||
public class InitQrCodeFormUitl {
|
||||
private static Log log = LogFactory.getLog(InitQrCodeFormUitl.class);
|
||||
private static PrivilegeMenuManager privilegeMenuManager = (PrivilegeMenuManager) AppContext.getBean("privilegeMenuManager");
|
||||
|
||||
public static void initMenu() {
|
||||
try {
|
||||
List<PrivMenu> listmenu = new ArrayList<PrivMenu>();
|
||||
|
||||
StringBuffer queryString = new StringBuffer(" FROM ");
|
||||
queryString.append(PrivMenu.class.getSimpleName()).append(" where ")
|
||||
.append(" path = '711' ");
|
||||
|
||||
listmenu = DBAgent.find(queryString.toString());
|
||||
if (listmenu == null || listmenu.size() < 1) {
|
||||
creatFileImportMenu();//创建菜单资源
|
||||
}
|
||||
log.info("模板二维码菜单完成");
|
||||
|
||||
} catch (Exception e) {
|
||||
log.error("模板二维码菜单失败", e);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* 配置菜单
|
||||
*
|
||||
* @return
|
||||
* @throws BusinessException
|
||||
*/
|
||||
private static void creatFileImportMenu() {
|
||||
try {
|
||||
List<PrivMenu> menus = new ArrayList<PrivMenu>();
|
||||
PrivMenu configmenu = new PrivMenu();
|
||||
configmenu.setNewId();
|
||||
configmenu.setName("模板二维码");
|
||||
configmenu.setIcon("conferencearrangemen.png");
|
||||
configmenu.setSortid(1);
|
||||
configmenu.setPath("711");
|
||||
configmenu.setExt1("0");
|
||||
configmenu.setExt2("1");
|
||||
configmenu.setExt3("");
|
||||
configmenu.setExt4(1);
|
||||
configmenu.setExt7(configmenu.getName());
|
||||
configmenu.setExt8("");
|
||||
configmenu.setExt9("");
|
||||
configmenu.setExt10("");
|
||||
configmenu.setExt11("");
|
||||
configmenu.setExt12(0);
|
||||
configmenu.setExt13(0);
|
||||
configmenu.setExt14(0);
|
||||
configmenu.setExt15(0);
|
||||
configmenu.setExt16(0);
|
||||
Date nowDate = new Date();
|
||||
configmenu.setCreatedate(nowDate);
|
||||
configmenu.setUpdatedate(nowDate);
|
||||
configmenu.setType(PrivMenuTypeEnums.systemPresetMenu.getKey());
|
||||
configmenu.setParentId(0L);
|
||||
menus.add(configmenu);
|
||||
|
||||
PrivMenu syncConfig = new PrivMenu();//二维码生成
|
||||
syncConfig.setNewId();
|
||||
syncConfig.setName("二维码生成");
|
||||
syncConfig.setIcon("b_menu_thridpartyspace.png");
|
||||
syncConfig.setTarget("mainfrm");
|
||||
syncConfig.setSortid(1);
|
||||
syncConfig.setPath("711001");
|
||||
syncConfig.setExt1("0");
|
||||
syncConfig.setExt2("2");
|
||||
syncConfig.setExt3("");
|
||||
syncConfig.setExt4(1);
|
||||
syncConfig.setExt7(syncConfig.getName());
|
||||
syncConfig.setExt8("0");
|
||||
syncConfig.setExt9("0");
|
||||
syncConfig.setExt10("0");
|
||||
syncConfig.setExt11("1");
|
||||
syncConfig.setExt19(2L);
|
||||
syncConfig.setEnterResource(1);
|
||||
syncConfig.setResourceNavurl("/qrCodeForm.do?method=index");
|
||||
syncConfig.setResourceCode("qrCodeForm");
|
||||
syncConfig.setResourceModuleid("none");
|
||||
syncConfig.setCreatedate(nowDate);
|
||||
syncConfig.setUpdatedate(nowDate);
|
||||
syncConfig.setUpdateuserid(1L);
|
||||
syncConfig.setShow(true);
|
||||
syncConfig.setControl(true);
|
||||
syncConfig.setType(PrivMenuTypeEnums.systemPresetMenu.getKey());
|
||||
syncConfig.setParentId(configmenu.getId());
|
||||
menus.add(syncConfig);
|
||||
|
||||
DBAgent.saveAll(menus);
|
||||
} catch (Exception e) {
|
||||
log.error("组织机构同步菜单异常", e);
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
71
src/com/seeyon/apps/qrCodeForm/util/LoginUtil.java
Normal file
71
src/com/seeyon/apps/qrCodeForm/util/LoginUtil.java
Normal file
@@ -0,0 +1,71 @@
|
||||
package com.seeyon.apps.qrCodeForm.util;
|
||||
|
||||
import cn.hutool.cache.CacheUtil;
|
||||
import cn.hutool.cache.impl.TimedCache;
|
||||
import com.seeyon.apps.common.config.ICstConfigApi;
|
||||
import com.seeyon.apps.common.plugin.vo.ConfigVo;
|
||||
import com.seeyon.apps.qrCodeForm.constant.QrCodeFormConstants;
|
||||
import com.seeyon.ctp.common.AppContext;
|
||||
import com.seeyon.ctp.common.constants.Constants;
|
||||
import com.seeyon.ctp.rest.util.TokenUtil;
|
||||
import com.seeyon.ctp.services.UserToken;
|
||||
import com.seeyon.ctp.util.Strings;
|
||||
import com.seeyon.ctp.util.TextEncoder;
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
import javax.servlet.http.HttpServletResponse;
|
||||
import java.util.HashMap;
|
||||
import java.util.Map;
|
||||
|
||||
public class LoginUtil {
|
||||
private static Log log = LogFactory.getLog(LoginUtil.class);
|
||||
|
||||
private static ICstConfigApi cstConfigApi = (ICstConfigApi) AppContext.getBean("cstConfigApi");
|
||||
|
||||
private static TimedCache<String, String> tokenCache = CacheUtil.newTimedCache(14 * 60 * 1000);
|
||||
|
||||
//rest信息
|
||||
// public static final String restName = AppContext.getSystemProperty("qrCodeForm.restName");
|
||||
// public static final String restPassword = AppContext.getSystemProperty("qrCodeForm.restPassword");
|
||||
|
||||
|
||||
/**
|
||||
* 获取token
|
||||
*
|
||||
* @param loginName 登录名
|
||||
* @return
|
||||
*/
|
||||
public static Map getToken(String memberId, String loginName, HttpServletRequest request, HttpServletResponse response) {
|
||||
Map<String, Object> map = new HashMap<String, Object>();
|
||||
String tokenId = tokenCache.get(memberId);
|
||||
if(null != tokenId) {
|
||||
map.put("id", tokenId);
|
||||
map.put("success", true);
|
||||
return map;
|
||||
}
|
||||
try {
|
||||
ConfigVo config = cstConfigApi.getConfig(QrCodeFormConstants.getPluginId());
|
||||
String userName = config.getParamVal(QrCodeFormConstants.restId.name());
|
||||
String password = config.getParamVal(QrCodeFormConstants.restPwd.name());
|
||||
password = TextEncoder.decode(password);
|
||||
Long userId = null;
|
||||
if (Strings.isNotBlank(memberId)) {
|
||||
userId = Long.parseLong(memberId);
|
||||
}
|
||||
UserToken token = TokenUtil._getToken(userName, password, userId, loginName, null, Constants.login_useragent_from.wechat.name(), request, response);
|
||||
if (token != null) {
|
||||
map.put("success", true);
|
||||
map.put("id", token.getId());
|
||||
tokenCache.put(memberId, token.getId());
|
||||
}
|
||||
} catch (Exception e) {
|
||||
log.error("", e);
|
||||
map.put("success", false);
|
||||
map.put("message", e.getMessage());
|
||||
}
|
||||
return map;
|
||||
}
|
||||
|
||||
}
|
||||
Reference in New Issue
Block a user