liu
9 小时以前 5d34bdd3c426bb2ca5f6627424ae67984f745603
yudao-module-wxcp/src/main/java/cn/iocoder/yudao/module/wxcp/service/member/WxCpMemberServiceImpl.java
@@ -4,6 +4,7 @@
import cn.iocoder.yudao.module.wxcp.controller.admin.member.vo.WxCpMemberRespVO;
import jakarta.annotation.Resource;
import lombok.extern.slf4j.Slf4j;
import me.chanjar.weixin.common.error.WxErrorException;
import me.chanjar.weixin.cp.api.WxCpService;
import me.chanjar.weixin.cp.bean.WxCpDepart;
import me.chanjar.weixin.cp.bean.WxCpUser;
@@ -73,7 +74,8 @@
            users = wxCpService.getUserService().listSimpleByDepartment(deptId, child, null);
        } catch (Exception e) {
            log.error("[getMemberList][获取企业微信成员失败 deptId={} fetchChild={}]", deptId, child, e);
            throw exception(WXCP_API_ERROR);
            throwWxCpApiError(e);
            return List.of();
        }
        // 部门名映射,用于把成员的部门ID翻译成可读名称
@@ -94,10 +96,22 @@
            return departs != null ? departs : List.of();
        } catch (Exception e) {
            log.error("[listDeparts][获取企业微信部门失败]", e);
            throw exception(WXCP_API_ERROR);
            throwWxCpApiError(e);
            return List.of();
        }
    }
    /**
     * 把企业微信接口异常转成带 errcode/errmsg 的可读提示,便于定位 IP 白名单、Secret 等问题
     */
    private void throwWxCpApiError(Exception e) {
        if (e instanceof WxErrorException wxError && wxError.getError() != null) {
            throw exception(WXCP_API_ERROR,
                    wxError.getError().getErrorCode(), wxError.getError().getErrorMsg());
        }
        throw exception(WXCP_API_ERROR, "unknown", e.getMessage());
    }
    private WxCpDepartmentRespVO toDeptVO(WxCpDepart depart) {
        WxCpDepartmentRespVO vo = new WxCpDepartmentRespVO();
        vo.setId(depart.getId());