Pārlūkot izejas kodu

自定义授权

xw 1 nedēļu atpakaļ
vecāks
revīzija
2c8f6a97c9

+ 21 - 0
fs-admin/src/main/java/com/fs/course/controller/FsCoursePlaySourceConfigController.java

@@ -99,6 +99,17 @@ public class FsCoursePlaySourceConfigController extends BaseController {
         if (fsCoursePlaySourceConfigService.count(queryWrapper) > 0) {
             return AjaxResult.error("appid已存在");
         }
+        
+        // 校验自定义授权配置
+        if (param.getCustomAuthEnabled() != null && param.getCustomAuthEnabled() == 1) {
+            if (param.getMiniAppAuthType() == null) {
+                return AjaxResult.error("开启自定义授权时必须选择授权方式");
+            }
+            if (param.getMiniAppAuthType() == 2 && (param.getUserCourseAuthDomain() == null || param.getUserCourseAuthDomain().trim().isEmpty())) {
+                return AjaxResult.error("选择服务号授权时必须填写授权域名");
+            }
+        }
+        
         LoginUser loginUser = tokenService.getLoginUser(ServletUtils.getRequest());
         FsCoursePlaySourceConfig config = new FsCoursePlaySourceConfig();
         config.setCreateUserId(loginUser.getUserId());
@@ -130,6 +141,16 @@ public class FsCoursePlaySourceConfigController extends BaseController {
             return AjaxResult.error("appid已存在");
         }
 
+        // 校验自定义授权配置
+        if (param.getCustomAuthEnabled() != null && param.getCustomAuthEnabled() == 1) {
+            if (param.getMiniAppAuthType() == null) {
+                return AjaxResult.error("开启自定义授权时必须选择授权方式");
+            }
+            if (param.getMiniAppAuthType() == 2 && (param.getUserCourseAuthDomain() == null || param.getUserCourseAuthDomain().trim().isEmpty())) {
+                return AjaxResult.error("选择服务号授权时必须填写授权域名");
+            }
+        }
+
         BeanUtils.copyProperties(param, config);
         fsCoursePlaySourceConfigService.updateById(config);
         return AjaxResult.success();

+ 20 - 0
fs-company/src/main/java/com/fs/company/controller/course/FsCoursePlaySourceConfigController.java

@@ -75,6 +75,16 @@ public class FsCoursePlaySourceConfigController extends BaseController {
             return AjaxResult.error("appid已存在");
         }
 
+        // 校验自定义授权配置
+        if (param.getCustomAuthEnabled() != null && param.getCustomAuthEnabled() == 1) {
+            if (param.getMiniAppAuthType() == null) {
+                return AjaxResult.error("开启自定义授权时必须选择授权方式");
+            }
+            if (param.getMiniAppAuthType() == 2 && (param.getUserCourseAuthDomain() == null || param.getUserCourseAuthDomain().trim().isEmpty())) {
+                return AjaxResult.error("选择服务号授权时必须填写授权域名");
+            }
+        }
+
         FsCoursePlaySourceConfig config = new FsCoursePlaySourceConfig();
         BeanUtils.copyProperties(param, config);
 
@@ -111,6 +121,16 @@ public class FsCoursePlaySourceConfigController extends BaseController {
             return AjaxResult.error("非法操作");
         }
 
+        // 校验自定义授权配置
+        if (param.getCustomAuthEnabled() != null && param.getCustomAuthEnabled() == 1) {
+            if (param.getMiniAppAuthType() == null) {
+                return AjaxResult.error("开启自定义授权时必须选择授权方式");
+            }
+            if (param.getMiniAppAuthType() == 2 && (param.getUserCourseAuthDomain() == null || param.getUserCourseAuthDomain().trim().isEmpty())) {
+                return AjaxResult.error("选择服务号授权时必须填写授权域名");
+            }
+        }
+
         BeanUtils.copyProperties(param, config);
         fsCoursePlaySourceConfigService.updateById(config);
         return AjaxResult.success();

+ 16 - 0
fs-service/src/main/java/com/fs/course/domain/FsCoursePlaySourceConfig.java

@@ -109,4 +109,20 @@ public class FsCoursePlaySourceConfig {
      * 商户支付配置id
      */
     private Long merchantConfigId;
+
+    /**
+     * 是否开启自定义授权 0-否 1-是
+     */
+    private Integer customAuthEnabled;
+
+    /**
+     * 小程序授权头像昵称方式(仅自定义授权开启时有效)
+     * 1:小程序原生授权 2:跳转H5服务号授权
+     */
+    private Integer miniAppAuthType;
+
+    /**
+     * 会员看课小程序授权头像昵称,跳转H5服务号授权域名(仅自定义授权开启且授权方式为服务号时有效)
+     */
+    private String userCourseAuthDomain;
 }

+ 9 - 0
fs-service/src/main/java/com/fs/course/param/FsCoursePlaySourceConfigCreateParam.java

@@ -57,4 +57,13 @@ public class FsCoursePlaySourceConfigCreateParam {
 
     @ApiModelProperty("小程序状态:0正常,1半封禁,2封禁")
     private Integer status;
+
+    @ApiModelProperty("是否开启自定义授权 0-否 1-是")
+    private Integer customAuthEnabled;
+
+    @ApiModelProperty("小程序授权头像昵称方式(仅自定义授权开启时有效) 1:小程序原生授权 2:跳转H5服务号授权")
+    private Integer miniAppAuthType;
+
+    @ApiModelProperty("会员看课小程序授权头像昵称,跳转H5服务号授权域名(仅自定义授权开启且授权方式为服务号时有效)")
+    private String userCourseAuthDomain;
 }

+ 9 - 0
fs-service/src/main/java/com/fs/course/param/FsCoursePlaySourceConfigEditParam.java

@@ -58,4 +58,13 @@ public class FsCoursePlaySourceConfigEditParam {
 
     @ApiModelProperty("商户支付配置id")
     private Long merchantConfigId;
+
+    @ApiModelProperty("是否开启自定义授权 0-否 1-是")
+    private Integer customAuthEnabled;
+
+    @ApiModelProperty("小程序授权头像昵称方式(仅自定义授权开启时有效) 1:小程序原生授权 2:跳转H5服务号授权")
+    private Integer miniAppAuthType;
+
+    @ApiModelProperty("会员看课小程序授权头像昵称,跳转H5服务号授权域名(仅自定义授权开启且授权方式为服务号时有效)")
+    private String userCourseAuthDomain;
 }

+ 9 - 0
fs-service/src/main/java/com/fs/course/vo/FsCoursePlaySourceConfigVO.java

@@ -64,4 +64,13 @@ public class FsCoursePlaySourceConfigVO {
 
     @ApiModelProperty("小程序状态:0正常,1半封禁,2封禁")
     private Integer status;
+
+    @ApiModelProperty("是否开启自定义授权 0-否 1-是")
+    private Integer customAuthEnabled;
+
+    @ApiModelProperty("小程序授权头像昵称方式(仅自定义授权开启时有效) 1:小程序原生授权 2:跳转H5服务号授权")
+    private Integer miniAppAuthType;
+
+    @ApiModelProperty("会员看课小程序授权头像昵称,跳转H5服务号授权域名(仅自定义授权开启且授权方式为服务号时有效)")
+    private String userCourseAuthDomain;
 }

+ 33 - 1
fs-user-app/src/main/java/com/fs/app/controller/store/CommonScrmController.java

@@ -14,6 +14,9 @@ import com.fs.common.exception.file.OssException;
 import com.fs.company.service.ICompanyMoneyLogsService;
 import com.fs.company.service.ICompanyService;
 import com.fs.company.service.ICompanyUserService;
+import com.fs.course.config.CourseConfig;
+import com.fs.course.domain.FsCoursePlaySourceConfig;
+import com.fs.course.service.IFsCoursePlaySourceConfigService;
 import com.fs.erp.service.IErpGoodsService;
 import com.fs.erp.service.IErpOrderService;
 import com.fs.erp.service.IErpShopService;
@@ -141,6 +144,9 @@ public class CommonScrmController extends AppBaseController {
     @Autowired
     IFsStorePaymentScrmService paymentService;
 
+    @Autowired
+    private IFsCoursePlaySourceConfigService fsCoursePlaySourceConfigService;
+
     @ApiOperation("支付手动通知")
     @GetMapping("payNotify")
     public R payNotify(String payCode) throws Exception {
@@ -413,8 +419,34 @@ public class CommonScrmController extends AppBaseController {
 
     @GetMapping(value = "/getConfigByKey")
     @ApiOperation("获取配置")
-    public R getConfigByKey(@RequestParam(value = "key", required = false) String key) {
+    public R getConfigByKey(
+            @RequestParam(value = "key", required = false) String key,
+            @ApiParam(value = "小程序appId,用于获取自定义授权配置") @RequestParam(value = "appId", required = false) String appId) {
+
         String config = configService.selectConfigByKey(key);
+
+        if ("course.config".equals(key) && appId != null && !appId.trim().isEmpty()) {
+            FsCoursePlaySourceConfig playSourceConfig = fsCoursePlaySourceConfigService.selectCoursePlaySourceConfigByAppId(appId);
+
+            if (playSourceConfig != null
+                    && playSourceConfig.getCustomAuthEnabled() != null
+                    && playSourceConfig.getCustomAuthEnabled() == 1) {
+                JSONObject result;
+                if (config != null && !config.trim().isEmpty()) {
+                    try {
+                        result = JSONObject.parseObject(config);
+                    } catch (Exception e) {
+                        result = new JSONObject();
+                    }
+                } else {
+                    result = new JSONObject();
+                }
+                result.put("miniAppAuthType", playSourceConfig.getMiniAppAuthType());
+                result.put("userCourseAuthDomain", playSourceConfig.getUserCourseAuthDomain());
+                return R.ok().put("data", result.toJSONString());
+            }
+        }
+
         return R.ok().put("data", config);
 
     }