feat(企微签到):逻辑:员工使用企微扫码后直接跳出签到页面,在签到页面对该课程进行点击签到!
deploy-hxtesting / build-and-deploy (push) Successful in 1m14s

规则:1.签到要校验是否为培训当天签到,如果不是当天扫码签到则进行友好提示;2. 签到需提供员工工号及随机时间戳(超过签到二维码有效期后需重新扫码签到);3.签到二维码每5分钟自动更新一次(更新后之前扫码签到自动作废需重新扫码);
补充说明:1.签到页面需展示该签到课程相关信息;2.展示签到倒计时还有多久过期,过期后需重新扫码进行优化提示;3.签到后提示签到成功!自动登录进入平台系统并进入该课程详情页面
This commit is contained in:
runny committed 2026-11-25 11:02:48 +08:00
1 parent 9950a28346
commit f43fbef5db
24 files changed
+1336 -67

No files matched your search

+100 -1
View File
@@ -1788,6 +1788,12 @@ type CheckinRequest struct {
Channel string `json:"channel"`
// MemberID 可选:讲师/课长/人事现场代扫码/补录。
MemberID string `json:"member_id"`
// EmployeeNo 录入工号(2026-11 扫码签到页必带):非空时启用严格校验
// (工号与档案一致 + 必须在「参加人员」名单 + 当天性 + nonce 防重放)。
EmployeeNo string `json:"employee_no"`
// Nonce 随机时间戳防重放;ClientTS 客户端提交时刻毫秒(时钟偏差校验)。
Nonce string `json:"nonce"`
ClientTS int64 `json:"client_ts"`
}
// Checkin POST /training/sign-records/checkin — 学员扫码签到(带定位校验);
@@ -1811,7 +1817,15 @@ func (h *Handler) Checkin(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": true, "data": record})
return
}
record, err := h.svc.Checkin(ctx, callerTenantID(c), callerUserID(c), req.Token, req.Lat, req.Lng, req.Channel)
record, err := h.svc.Checkin(ctx, callerTenantID(c), callerUserID(c), &types.CheckinInput{
Token: req.Token,
Lat: req.Lat,
Lng: req.Lng,
Channel: req.Channel,
EmployeeNo: req.EmployeeNo,
Nonce: req.Nonce,
ClientTS: req.ClientTS,
})
if err != nil {
_ = c.Error(err)
return
@@ -1819,6 +1833,91 @@ func (h *Handler) Checkin(c *gin.Context) {
c.JSON(http.StatusOK, gin.H{"success": true, "data": record})
}
// ---------------------------------------------------------------------------
// 企微扫码签到免登(2026-11 需求):匿名入口,路由直挂 v1 组外 +
// noAuthAPI 白名单 + PublicAuthRateLimit,身份由签到码 token / OAuth code 承载。
// ---------------------------------------------------------------------------
// WecomCheckinAuthRequest is the query of GET /training/wecom/checkin-auth.
// redirect_uri 由落地页按当前域名拼出(测试 kbt / 正式 kb 跟随二维码环境)。
type WecomCheckinAuthRequest struct {
Token string `form:"token" binding:"required"`
RedirectURI string `form:"redirect_uri"`
}
// WecomCheckinAuth GET /training/wecom/checkin-auth — 返回企微 snsapi_base
// 静默授权链接,前端 location.replace 跳转(学员无感)。
func (h *Handler) WecomCheckinAuth(c *gin.Context) {
var q WecomCheckinAuthRequest
if err := c.ShouldBindQuery(&q); err != nil {
_ = c.Error(errors.NewBadRequestError("缺少签到码").WithDetails(err.Error()))
return
}
redirectURI := strings.TrimSpace(q.RedirectURI)
if redirectURI == "" {
// 兜底:按请求 Host 还原落地页地址(反代透传 X-Forwarded-Proto)。
scheme := "https"
if c.Request.TLS == nil {
if proto := strings.TrimSpace(c.GetHeader("X-Forwarded-Proto")); proto != "" {
scheme = proto
} else {
scheme = "http"
}
}
redirectURI = fmt.Sprintf("%s://%s/platform/training/checkin/%s", scheme, c.Request.Host, q.Token)
}
url, err := h.svc.WecomCheckinAuthURL(c.Request.Context(), q.Token, redirectURI)
if err != nil {
_ = c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "data": gin.H{"authorize_url": url}})
}
// WecomCheckinSessionRequest is the body of POST /training/wecom/checkin-session.
type WecomCheckinSessionRequest struct {
Code string `json:"code" binding:"required"`
State string `json:"state" binding:"required"`
}
// WecomCheckinSession POST /training/wecom/checkin-session — OAuth code 换
// 平台会话(token/refresh_token/user/active_tenant/memberships,与 /auth/login
// 同构,前端复用登录持久化路径即"签到即自动登录")+ 落地页数据。
func (h *Handler) WecomCheckinSession(c *gin.Context) {
var req WecomCheckinSessionRequest
if err := c.ShouldBindJSON(&req); err != nil {
_ = c.Error(errors.NewBadRequestError("授权参数不完整").WithDetails(err.Error()))
return
}
session, err := h.svc.WecomCheckinSession(c.Request.Context(), req.Code, req.State)
if err != nil {
_ = c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "data": session})
}
// WecomCheckinPageRequest is the body of POST /training/wecom/checkin-page.
type WecomCheckinPageRequest struct {
Token string `json:"token" binding:"required"`
}
// WecomCheckinPage POST /training/wecom/checkin-page — 已登录用户(PC 讲师
// 自测/企微内已有会话)取落地页数据;认证守卫 + 培训空间解析之后。
func (h *Handler) WecomCheckinPage(c *gin.Context) {
var req WecomCheckinPageRequest
if err := c.ShouldBindJSON(&req); err != nil {
_ = c.Error(errors.NewBadRequestError("缺少签到码").WithDetails(err.Error()))
return
}
page, err := h.svc.WecomCheckinPage(c.Request.Context(), callerTenantID(c), callerUserID(c), req.Token)
if err != nil {
_ = c.Error(err)
return
}
c.JSON(http.StatusOK, gin.H{"success": true, "data": page})
}
// ListSignRecords GET /training/sessions/:id/sign-records — 签到明细。
func (h *Handler) ListSignRecords(c *gin.Context) {
items, err := h.svc.ListSignRecords(c.Request.Context(), callerTenantID(c), c.Param("id"))