yumeng 3 năm trước cách đây
mục cha
commit
6a517e33fd

+ 59 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/entity/OauthDetail.java

@@ -0,0 +1,59 @@
+package cn.com.ctop.common.module.entity;
+
+import com.baomidou.mybatisplus.annotation.IdType;
+import com.baomidou.mybatisplus.annotation.TableId;
+import com.baomidou.mybatisplus.annotation.TableName;
+import com.fasterxml.jackson.annotation.JsonFormat;
+import io.swagger.annotations.ApiModel;
+import io.swagger.annotations.ApiModelProperty;
+import lombok.Data;
+import lombok.EqualsAndHashCode;
+import lombok.experimental.Accessors;
+import org.jeecgframework.poi.excel.annotation.Excel;
+import org.springframework.format.annotation.DateTimeFormat;
+
+import java.util.Date;
+
+/**
+ * 授权详情信息
+ *
+ * @author jeecg-boot
+ * @version V1.0
+ * @date 2021-12-01
+ */
+@Data
+@TableName("ctop_oauth_detail")
+@EqualsAndHashCode(callSuper = false)
+@Accessors(chain = true)
+@ApiModel(value = "ctop_oauth_detail对象", description = "授权详情信息")
+public class OauthDetail {
+
+    /**
+     * 主键ID
+     */
+    @TableId(type = IdType.UUID)
+    @ApiModelProperty(value = "主键ID")
+    private Long id;
+    /**
+     * 授权信息
+     */
+    @Excel(name = "授权信息", width = 15)
+    @ApiModelProperty(value = "授权信息")
+    private String detailText;
+    /**
+     * 创建时间
+     */
+    @Excel(name = "创建时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "创建时间")
+    private Date createTime;
+    /**
+     * 修改时间
+     */
+    @Excel(name = "修改时间", width = 20, format = "yyyy-MM-dd HH:mm:ss")
+    @JsonFormat(timezone = "GMT+8", pattern = "yyyy-MM-dd HH:mm:ss")
+    @DateTimeFormat(pattern = "yyyy-MM-dd HH:mm:ss")
+    @ApiModelProperty(value = "修改时间")
+    private Date updateTime;
+}

+ 15 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/OauthDetailMapper.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.common.module.mapper;
+
+import cn.com.ctop.common.module.entity.OauthDetail;
+import com.baomidou.mybatisplus.core.mapper.BaseMapper;
+
+/**
+ * 授权详情信息
+ *
+ * @author jeecg-boot
+ * 2021-12-01
+ * @version V1.0
+ */
+public interface OauthDetailMapper extends BaseMapper<OauthDetail> {
+
+}

+ 5 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/mapper/xml/OauthDetailMapper.xml

@@ -0,0 +1,5 @@
+<?xml version="1.0" encoding="UTF-8"?>
+<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
+<mapper namespace="cn.com.ctop.common.module.mapper.OauthDetailMapper">
+
+</mapper>

+ 15 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/IOauthDetailService.java

@@ -0,0 +1,15 @@
+package cn.com.ctop.common.module.service;
+
+import cn.com.ctop.common.module.entity.OauthDetail;
+import com.baomidou.mybatisplus.extension.service.IService;
+
+/**
+ * 授权详情信息
+ *
+ * @author jeecg-boot
+ * 2021-12-01
+ * @version V1.0
+ */
+public interface IOauthDetailService extends IService<OauthDetail> {
+
+}

+ 10 - 1
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/BindAccountAuthServiceImpl.java

@@ -2,9 +2,11 @@ package cn.com.ctop.common.module.service.impl;
 
 import cn.com.ctop.common.module.entity.BindAccountAuth;
 import cn.com.ctop.common.module.entity.OauthConfig;
+import cn.com.ctop.common.module.entity.OauthDetail;
 import cn.com.ctop.common.module.mapper.BindAccountAuthMapper;
 import cn.com.ctop.common.module.service.IBindAccountAuthService;
 import cn.com.ctop.common.module.service.IOauthConfigService;
+import cn.com.ctop.common.module.service.IOauthDetailService;
 import cn.com.ctop.common.module.utils.BytedanceInterfaceConstant;
 import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
 import cn.com.ctop.common.module.utils.PropertiesUtils;
@@ -69,6 +71,8 @@ public class BindAccountAuthServiceImpl extends ServiceImpl<BindAccountAuthMappe
 
     @Autowired
     private IOauthConfigService oauthConfigService;
+    @Autowired
+    private IOauthDetailService detailService;
 
     @Override
     public String getKuaishouCodeUrl(JSONObject state) throws UnsupportedEncodingException {
@@ -78,10 +82,15 @@ public class BindAccountAuthServiceImpl extends ServiceImpl<BindAccountAuthMappe
         OauthConfig config = oauthConfigService.getById(id);
         state.put("appId", config.getAppId());
         state.put("callbackUrl", config.getCallbackUrl());
+        OauthDetail detail = new OauthDetail();
+        detail.setDetailText(state.toJSONString());
+        detailService.save(detail);
+
+
         sb.append(PropertiesUtils.getValue("kuaishou_config", "kuaishou_auth_url"))
                 .append(KuaishouInterfaceConstant.AUTH_PATH)
                 .append("?app_id=" + config.getAppId())
-                .append("&state=" + URLEncoder.encode(URLEncoder.encode(URLEncoder.encode(state.toJSONString()))))
+                .append("&state=" + detail.getId())
                 .append("&redirect_uri=" + URLEncoder.encode(config.getRedirectUri(), "UTF-8"));
         if (config.getOauthType() != 1) {
             sb.append("&scope=%5B%22report_service%22%2C%22ad_query%22%2C%22account_service%22%2C%22ad_manage%22%5D");

+ 19 - 0
jeecg-boot-module-system/src/main/java/cn/com/ctop/common/module/service/impl/OauthDetailServiceImpl.java

@@ -0,0 +1,19 @@
+package cn.com.ctop.common.module.service.impl;
+
+import cn.com.ctop.common.module.entity.OauthDetail;
+import cn.com.ctop.common.module.mapper.OauthDetailMapper;
+import cn.com.ctop.common.module.service.IOauthDetailService;
+import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
+import org.springframework.stereotype.Service;
+
+/**
+ * 授权详情信息
+ *
+ * @author jeecg-boot
+ * 2021-12-01
+ * @version V1.0
+ */
+@Service
+public class OauthDetailServiceImpl extends ServiceImpl<OauthDetailMapper, OauthDetail> implements IOauthDetailService {
+
+}

+ 23 - 11
jeecg-boot-module-system/src/main/java/org/jeecg/modules/ctop/controller/CallbackController.java

@@ -1,17 +1,11 @@
 package org.jeecg.modules.ctop.controller;
 
 import cn.com.ctop.common.module.entity.CtopOauthToken;
+import cn.com.ctop.common.module.entity.OauthDetail;
 import cn.com.ctop.common.module.entity.UserAllocation;
 import cn.com.ctop.common.module.mapper.UserAllocationMapper;
-import cn.com.ctop.common.module.service.IBindAccountAuthService;
-import cn.com.ctop.common.module.service.ICtopOauthTokenService;
-import cn.com.ctop.common.module.service.ISysDepartService;
-import cn.com.ctop.common.module.service.ISysUserService;
-import cn.com.ctop.common.module.utils.BytedanceInterfaceConstant;
-import cn.com.ctop.common.module.utils.Check;
-import cn.com.ctop.common.module.utils.HttpUtils;
-import cn.com.ctop.common.module.utils.KuaishouInterfaceConstant;
-import cn.com.ctop.common.module.utils.PropertiesUtils;
+import cn.com.ctop.common.module.service.*;
+import cn.com.ctop.common.module.utils.*;
 import cn.com.ctop.kuaishou.modules.ai.service.IKuaishouAppPackageService;
 import cn.com.ctop.kuaishou.modules.batch.service.IKuaishouInterfaceService;
 import cn.com.ctop.kuaishou.modules.material.entity.KuaishouAccessToken;
@@ -69,6 +63,8 @@ public class CallbackController {
     private IReportService reportService;
     @Autowired
     private IKuaishouAppPackageService kuaishouAppPackageService;
+    @Autowired
+    private IOauthDetailService detailService;
 
     @GetMapping("/qywexin")
     public void qywexin(HttpServletRequest request,
@@ -120,13 +116,27 @@ public class CallbackController {
      * @param state
      * @return
      */
+
+
     @GetMapping("/kuaishou")
     public String kuaishouCallback(HttpServletRequest request, HttpServletResponse response, @RequestParam("auth_code") String authCode, @RequestParam("state") String state) {
+        Long id = Long.valueOf(state);
         try {
-            JSONObject json = JSONObject.parseObject(state);
-            if (Check.isNull(json)) {
+            //    JSONObject json = JSONObject.parseObject(state);
+
+            OauthDetail byId = detailService.getById(id);
+            if (Check.isNull(byId)) {
                 throw new Exception("回调信息为空");
             }
+            String detailText = byId.getDetailText();
+            if (Check.isNull(detailText)) {
+                throw new Exception("用户授权信息为空");
+            }
+            JSONObject json = JSONObject.parseObject(detailText);
+            if (Check.isNull(json)) {
+                throw new Exception("数据转化异常");
+            }
+
             log.info("快手授权返回信息:{}", json);
             log.info("快手授权返回oauthCode:{}", authCode);
             Integer agentType = json.getInteger("agentType");
@@ -244,11 +254,13 @@ public class CallbackController {
                     };
                     t.start();
                 }
+                detailService.removeById(id);
                 return "授权绑定成功";
             }
         } catch (Exception e) {
             e.printStackTrace();
         }
+        detailService.removeById(id);
         return "授权绑定失败!";
     }