|
@@ -1,12 +1,14 @@
|
|
|
package org.fouram.controller;
|
|
|
|
|
|
-import java.util.Map;
|
|
|
-
|
|
|
+import com.google.common.collect.Maps;
|
|
|
+import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo;
|
|
|
import org.apache.commons.lang3.StringUtils;
|
|
|
import org.fouram.constants.WebConstants;
|
|
|
import org.fouram.core.base.controller.BaseController;
|
|
|
+import org.fouram.core.plugin.weixin.cp.core.WXCpMailList;
|
|
|
import org.fouram.core.util.AppUtil;
|
|
|
import org.fouram.core.util.AppUtil.ResultConstant;
|
|
|
+import org.fouram.core.util.ConfConfig;
|
|
|
import org.fouram.core.util.LoggerUtil;
|
|
|
import org.fouram.service.SapOrgService;
|
|
|
import org.fouram.service.SapUserService;
|
|
@@ -15,7 +17,10 @@ import org.springframework.stereotype.Controller;
|
|
|
import org.springframework.web.bind.annotation.RequestMapping;
|
|
|
import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
-import com.google.common.collect.Maps;
|
|
|
+import javax.servlet.http.HttpServletRequest;
|
|
|
+import javax.servlet.http.HttpServletResponse;
|
|
|
+import javax.servlet.http.HttpSession;
|
|
|
+import java.util.Map;
|
|
|
|
|
|
@Controller
|
|
|
@RequestMapping(value = "/API")
|
|
@@ -26,13 +31,48 @@ public class ApiController extends BaseController {
|
|
|
@Autowired
|
|
|
private SapUserService sapUserService;
|
|
|
|
|
|
+ private static final String TOKEN="UserId";
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取授权url
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ @RequestMapping(value = "/getAuthUrl", produces = "application/json;charset=utf-8")
|
|
|
+ @ResponseBody
|
|
|
+ public Object getAuthUrl(String url) {
|
|
|
+ try {
|
|
|
+ String redirectUri = ConfConfig.getConfigString("wxCp.redirectUri");
|
|
|
+ String authUri = WXCpMailList.oauth2Service.buildAuthorizationUrl(redirectUri,url);
|
|
|
+ return AppUtil.success(authUri, null);
|
|
|
+ } catch (Exception e) {
|
|
|
+ LoggerUtil.error(e);
|
|
|
+ return AppUtil.error(ResultConstant.WEB_ERR_MSG);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
+ @RequestMapping(value = "/wxCpLogin", produces = "application/json;charset=utf-8")
|
|
|
+ @ResponseBody
|
|
|
+ public void wxCpLogin(String code,String state,HttpServletRequest request, HttpServletResponse response) throws Exception {
|
|
|
+ WxCpOauth2UserInfo userInfo = WXCpMailList.oauth2Service.getUserInfo(code);
|
|
|
+ if(StringUtils.isEmpty(userInfo.getUserId())){
|
|
|
+ response.getWriter().println("无权限访问!");
|
|
|
+ }else{
|
|
|
+ HttpSession httpSession = request.getSession();
|
|
|
+ httpSession.setAttribute(TOKEN,userInfo.getUserId());
|
|
|
+ response.sendRedirect(state);
|
|
|
+ }
|
|
|
+ }
|
|
|
+
|
|
|
/**
|
|
|
* 根据部门id查询下级部门和用户
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/getChildDepartAndUserListByDepartId", produces = "application/json;charset=utf-8")
|
|
|
@ResponseBody
|
|
|
- public Object getChildDepartAndUserListByDepartId() {
|
|
|
+ public Object getChildDepartAndUserListByDepartId(HttpServletRequest request) {
|
|
|
+ if(!isLogin(request)){
|
|
|
+ return AppUtil.error(ResultConstant.TOKEN_ERR_MSG);
|
|
|
+ }
|
|
|
try {
|
|
|
String departId = getPageData().getString("departId");
|
|
|
if (StringUtils.isBlank(departId)) {
|
|
@@ -54,7 +94,10 @@ public class ApiController extends BaseController {
|
|
|
*/
|
|
|
@RequestMapping(value = "/getDepartAndUserListByName", produces = "application/json;charset=utf-8")
|
|
|
@ResponseBody
|
|
|
- public Object getDepartAndUserListByName() {
|
|
|
+ public Object getDepartAndUserListByName(HttpServletRequest request) {
|
|
|
+ if(!isLogin(request)){
|
|
|
+ return AppUtil.error(ResultConstant.TOKEN_ERR_MSG);
|
|
|
+ }
|
|
|
try {
|
|
|
String name = getPageData().getString("name");
|
|
|
Map<String, Object> result = Maps.newHashMap();
|
|
@@ -66,14 +109,17 @@ public class ApiController extends BaseController {
|
|
|
return AppUtil.error(ResultConstant.WEB_ERR_MSG);
|
|
|
}
|
|
|
}
|
|
|
-
|
|
|
+
|
|
|
/**
|
|
|
* 根据id查询用户信息
|
|
|
* @return
|
|
|
*/
|
|
|
@RequestMapping(value = "/getUserInfoByUserId", produces = "application/json;charset=utf-8")
|
|
|
@ResponseBody
|
|
|
- public Object getUserInfoById() {
|
|
|
+ public Object getUserInfoById(HttpServletRequest request) {
|
|
|
+ if(!isLogin(request)){
|
|
|
+ return AppUtil.error(ResultConstant.TOKEN_ERR_MSG);
|
|
|
+ }
|
|
|
try {
|
|
|
String userId = getPageData().getString("userId");
|
|
|
return AppUtil.success(sapUserService.getDetailById(userId), null);
|
|
@@ -82,4 +128,18 @@ public class ApiController extends BaseController {
|
|
|
return AppUtil.error(ResultConstant.WEB_ERR_MSG);
|
|
|
}
|
|
|
}
|
|
|
-}
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 判断是否经过授权
|
|
|
+ * @param request
|
|
|
+ * @return
|
|
|
+ */
|
|
|
+ public boolean isLogin(HttpServletRequest request){
|
|
|
+// HttpSession httpSession = request.getSession();
|
|
|
+// if(null==httpSession.getAttribute(TOKEN)){
|
|
|
+// return false;
|
|
|
+// }
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+
|
|
|
+}
|