|
@@ -13,7 +13,27 @@ import cn.com.ctop.toutiao.entity.ByteDanceAdvertiser;
|
|
import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
|
|
import cn.com.ctop.toutiao.service.IByteDanceAdvertiserDataService;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.alibaba.fastjson.JSONObject;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
|
|
|
|
+import lombok.val;
|
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
|
+import me.chanjar.weixin.cp.api.WxCpOAuth2Service;
|
|
|
|
+import me.chanjar.weixin.cp.api.WxCpUserService;
|
|
|
|
+import me.chanjar.weixin.cp.api.impl.WxCpOAuth2ServiceImpl;
|
|
|
|
+import me.chanjar.weixin.cp.api.impl.WxCpServiceImpl;
|
|
|
|
+import me.chanjar.weixin.cp.api.impl.WxCpUserServiceImpl;
|
|
|
|
+import me.chanjar.weixin.cp.bean.WxCpOauth2UserInfo;
|
|
|
|
+import me.chanjar.weixin.cp.bean.WxCpUser;
|
|
|
|
+import me.chanjar.weixin.cp.config.impl.WxCpDefaultConfigImpl;
|
|
import org.apache.commons.lang.StringUtils;
|
|
import org.apache.commons.lang.StringUtils;
|
|
|
|
+import org.jeecg.common.api.vo.Result;
|
|
|
|
+import org.jeecg.common.constant.CommonConstant;
|
|
|
|
+import org.jeecg.common.system.api.ISysBaseApi;
|
|
|
|
+import org.jeecg.common.system.util.JwtUtil;
|
|
|
|
+import org.jeecg.common.util.RedisUtil;
|
|
|
|
+import org.jeecg.modules.system.entity.SysDepart;
|
|
|
|
+import org.jeecg.modules.system.entity.SysUser;
|
|
|
|
+import org.jeecg.modules.system.service.ISysDepartService;
|
|
|
|
+import org.jeecg.modules.system.service.ISysLogService;
|
|
|
|
+import org.jeecg.modules.system.service.ISysUserService;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.Logger;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.slf4j.LoggerFactory;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -25,14 +45,25 @@ import org.springframework.web.bind.annotation.ResponseBody;
|
|
|
|
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletRequest;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
import javax.servlet.http.HttpServletResponse;
|
|
|
|
+import java.io.IOException;
|
|
import java.util.Date;
|
|
import java.util.Date;
|
|
import java.util.HashMap;
|
|
import java.util.HashMap;
|
|
|
|
+import java.util.List;
|
|
import java.util.Map;
|
|
import java.util.Map;
|
|
|
|
|
|
@Controller
|
|
@Controller
|
|
public class CallbackController {
|
|
public class CallbackController {
|
|
private static final Logger logger = LoggerFactory.getLogger(CallbackController.class);
|
|
private static final Logger logger = LoggerFactory.getLogger(CallbackController.class);
|
|
-
|
|
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysUserService sysUserService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysBaseApi sysBaseApi;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysLogService logService;
|
|
|
|
+ @Autowired
|
|
|
|
+ private RedisUtil redisUtil;
|
|
|
|
+ @Autowired
|
|
|
|
+ private ISysDepartService sysDepartService;
|
|
@Autowired
|
|
@Autowired
|
|
private IKuaishouInterfaceService kuaishouInterfaceService;
|
|
private IKuaishouInterfaceService kuaishouInterfaceService;
|
|
|
|
|
|
@@ -47,10 +78,46 @@ public class CallbackController {
|
|
|
|
|
|
@GetMapping("/qywexin")
|
|
@GetMapping("/qywexin")
|
|
@ResponseBody
|
|
@ResponseBody
|
|
- public String qywexin(HttpServletRequest request,
|
|
|
|
- HttpServletResponse response){
|
|
|
|
- System.out.println(request.getQueryString());
|
|
|
|
- return request.getQueryString();
|
|
|
|
|
|
+ public void qywexin(HttpServletRequest request,
|
|
|
|
+ HttpServletResponse response,
|
|
|
|
+ @RequestParam("code") String code,
|
|
|
|
+ @RequestParam("state") String state) throws IOException {
|
|
|
|
+ response.sendRedirect(state+"?code="+code);
|
|
|
|
+ }
|
|
|
|
+
|
|
|
|
+ /**
|
|
|
|
+ * 用户信息
|
|
|
|
+ *
|
|
|
|
+ * @param sysUser
|
|
|
|
+ * @param result
|
|
|
|
+ * @return
|
|
|
|
+ */
|
|
|
|
+ private Result<JSONObject> userInfo(SysUser sysUser, Result<JSONObject> result) {
|
|
|
|
+ String syspassword = sysUser.getPassword();
|
|
|
|
+ String username = sysUser.getUsername();
|
|
|
|
+ // 生成token
|
|
|
|
+ String token = JwtUtil.sign(username, syspassword);
|
|
|
|
+ redisUtil.set(CommonConstant.PREFIX_USER_TOKEN + token, token);
|
|
|
|
+ // 设置超时时间
|
|
|
|
+ redisUtil.expire(CommonConstant.PREFIX_USER_TOKEN + token, JwtUtil.EXPIRE_TIME / 1000);
|
|
|
|
+
|
|
|
|
+ // 获取用户部门信息
|
|
|
|
+ JSONObject obj = new JSONObject();
|
|
|
|
+ List<SysDepart> departs = sysDepartService.queryUserDeparts(sysUser.getId());
|
|
|
|
+ obj.put("departs", departs);
|
|
|
|
+ if (departs == null || departs.size() == 0) {
|
|
|
|
+ obj.put("multi_depart", 0);
|
|
|
|
+ } else if (departs.size() == 1) {
|
|
|
|
+ sysUserService.updateUserDepart(username, departs.get(0).getOrgCode());
|
|
|
|
+ obj.put("multi_depart", 1);
|
|
|
|
+ } else {
|
|
|
|
+ obj.put("multi_depart", 2);
|
|
|
|
+ }
|
|
|
|
+ obj.put("token", token);
|
|
|
|
+ obj.put("userInfo", sysUser);
|
|
|
|
+ result.setResult(obj);
|
|
|
|
+ result.success("登录成功");
|
|
|
|
+ return result;
|
|
}
|
|
}
|
|
/**
|
|
/**
|
|
* TODO 授权绑定成功/失败 需要跳转特定页面
|
|
* TODO 授权绑定成功/失败 需要跳转特定页面
|