|
@@ -27,6 +27,7 @@ import com.fs.course.param.newfs.FsCourseWatchAppParam;
|
|
|
import com.fs.course.param.newfs.FsUserCourseListParam;
|
|
import com.fs.course.param.newfs.FsUserCourseListParam;
|
|
|
import com.fs.course.param.newfs.UserCourseVideoPageParam;
|
|
import com.fs.course.param.newfs.UserCourseVideoPageParam;
|
|
|
import com.fs.course.service.*;
|
|
import com.fs.course.service.*;
|
|
|
|
|
+import com.fs.course.utils.WechatErrorUtil;
|
|
|
import com.fs.course.vo.FsCourseWatchLogListVO;
|
|
import com.fs.course.vo.FsCourseWatchLogListVO;
|
|
|
import com.fs.course.vo.FsUserCourseParticipationRecordVO;
|
|
import com.fs.course.vo.FsUserCourseParticipationRecordVO;
|
|
|
import com.fs.course.vo.newfs.*;
|
|
import com.fs.course.vo.newfs.*;
|
|
@@ -42,6 +43,7 @@ import com.github.pagehelper.PageInfo;
|
|
|
import io.swagger.annotations.Api;
|
|
import io.swagger.annotations.Api;
|
|
|
import io.swagger.annotations.ApiOperation;
|
|
import io.swagger.annotations.ApiOperation;
|
|
|
import lombok.extern.slf4j.Slf4j;
|
|
import lombok.extern.slf4j.Slf4j;
|
|
|
|
|
+import me.chanjar.weixin.common.error.WxErrorException;
|
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
import org.apache.commons.collections.CollectionUtils;
|
|
|
import org.springframework.beans.BeanUtils;
|
|
import org.springframework.beans.BeanUtils;
|
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
import org.springframework.beans.factory.annotation.Autowired;
|
|
@@ -309,7 +311,64 @@ public class FsUserCourseVideoController extends AppBaseController {
|
|
|
@GetMapping("/getGotoWxAppLink")
|
|
@GetMapping("/getGotoWxAppLink")
|
|
|
@ApiOperation("获取跳转微信小程序的链接地址")
|
|
@ApiOperation("获取跳转微信小程序的链接地址")
|
|
|
public ResponseResult<String> getGotoWxAppLink(String linkStr,String appid) {
|
|
public ResponseResult<String> getGotoWxAppLink(String linkStr,String appid) {
|
|
|
- return ResponseResult.ok(courseLinkService.getGotoWxAppLink(linkStr,appid));
|
|
|
|
|
|
|
+ try {
|
|
|
|
|
+ String result = courseLinkService.getGotoWxAppLink(linkStr,appid);
|
|
|
|
|
+ // 检查返回结果是否为空或空白
|
|
|
|
|
+ if (result == null || result.trim().isEmpty()) {
|
|
|
|
|
+ return ResponseResult.fail(500, "生成微信小程序链接失败");
|
|
|
|
|
+ }
|
|
|
|
|
+ // 检查返回结果是否包含错误信息
|
|
|
|
|
+ if (result.contains("错误") || result.contains("失败")) {
|
|
|
|
|
+ return ResponseResult.fail(500, result);
|
|
|
|
|
+ }
|
|
|
|
|
+ return ResponseResult.ok(result);
|
|
|
|
|
+ } catch (Exception e) {
|
|
|
|
|
+ log.error("获取跳转微信小程序链接失败", e);
|
|
|
|
|
+ return handleWechatError(e);
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ /**
|
|
|
|
|
+ * 统一处理微信错误
|
|
|
|
|
+ */
|
|
|
|
|
+ private ResponseResult<String> handleWechatError(Exception e) {
|
|
|
|
|
+ // 1. 检查是否是WxErrorException(可能在cause中)
|
|
|
|
|
+ Throwable cause = e.getCause();
|
|
|
|
|
+ if (cause instanceof WxErrorException) {
|
|
|
|
|
+ WxErrorException wxError = (WxErrorException) cause;
|
|
|
|
|
+ Integer errcode = wxError.getError().getErrorCode();
|
|
|
|
|
+ String errmsg = wxError.getError().getErrorMsg();
|
|
|
|
|
+ log.error("微信API异常,错误码:{},错误信息:{}", errcode, errmsg);
|
|
|
|
|
+
|
|
|
|
|
+ String friendlyMsg = WechatErrorUtil.getFriendlyMessage(errcode);
|
|
|
|
|
+ Map<String, Object> extData = new HashMap<>();
|
|
|
|
|
+ extData.put("wechatErrorCode", errcode);
|
|
|
|
|
+ return new ResponseResult<>(500, friendlyMsg, null, extData);
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 2. 检查是否是微信错误(格式:微信错误:errcode|errmsg)
|
|
|
|
|
+ String errorMsg = e.getMessage();
|
|
|
|
|
+ if (errorMsg != null && errorMsg.startsWith("微信错误:")) {
|
|
|
|
|
+ String errorInfo = errorMsg.substring("微信错误:".length());
|
|
|
|
|
+ String[] parts = errorInfo.split("\\|", 2);
|
|
|
|
|
+ if (parts.length == 2) {
|
|
|
|
|
+ try {
|
|
|
|
|
+ Integer errcode = Integer.parseInt(parts[0]);
|
|
|
|
|
+ String errmsg = parts[1];
|
|
|
|
|
+ log.error("微信返回错误,错误码:{},错误信息:{}", errcode, errmsg);
|
|
|
|
|
+
|
|
|
|
|
+ String friendlyMsg = WechatErrorUtil.getFriendlyMessage(errcode);
|
|
|
|
|
+ Map<String, Object> extData = new HashMap<>();
|
|
|
|
|
+ extData.put("wechatErrorCode", errcode);
|
|
|
|
|
+ return new ResponseResult<>(500, friendlyMsg, null, extData);
|
|
|
|
|
+ } catch (NumberFormatException ex) {
|
|
|
|
|
+ // 格式错误,返回原始错误
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+ }
|
|
|
|
|
+
|
|
|
|
|
+ // 3. 其他错误,返回通用错误信息
|
|
|
|
|
+ return ResponseResult.fail(500, "获取微信小程序链接失败:" + errorMsg);
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
@GetMapping("/getGotoAppLink")
|
|
@GetMapping("/getGotoAppLink")
|