优化小程序

This commit is contained in:
hero920103 committed 2026-10-31 01:21:55 +08:00
1 parent 2e2b837a20
commit 727319a6eb
24 files changed
+1509 -200

No files matched your search

+39
View File
@@ -187,6 +187,45 @@ func (c *AuthWechatMiniController) Login() {
c.serveJSON(resp)
}
// RegisterConfirm 小程序端确认注册(网页注册页展示的小程序码扫码进入)
// POST /auth/register/mini/confirm
//
// { "scene": "小程序码携带的会话标识", "code": "wx.login的code", "phone_code": "可选", "appid": "可选,多小程序" }
//
// 无登录态:scene + code 即凭证,服务端用 code 换 openid 后标记该会话已确认,
// 网页端轮询到确认后继续填写账号密码;手机号快速验证为可选项(失败不阻断)。
func (c *AuthWechatMiniController) RegisterConfirm() {
var req struct {
Scene string `json:"scene"`
Code string `json:"code"`
PhoneCode string `json:"phone_code"`
AppID string `json:"appid"`
}
body := c.Ctx.Input.RequestBody
if len(body) == 0 {
body, _ = io.ReadAll(c.Ctx.Request.Body)
}
if err := json.Unmarshal(body, &req); err != nil {
c.fail("", 400, "参数错误")
return
}
req.Scene = strings.TrimSpace(req.Scene)
if req.Scene == "" {
c.fail("", 400, "缺少会话标识,请重新扫码")
return
}
if err := wechatmini.ConfirmRegister(req.Scene, req.Code, req.PhoneCode, req.AppID); err != nil {
msg := err.Error()
if hint, ok := wechatmini.ExplainError(err); ok {
msg = hint
}
logs.Warn("[wechat-mini] 注册确认失败 scene=%s: %v", req.Scene, err)
c.fail(MiniReasonWechatAPI, 400, msg)
return
}
c.serveJSON(map[string]interface{}{"code": 200, "msg": "确认成功,请回到电脑继续完成注册"})
}
// Bind 把当前小程序 openid 绑定到已登录身份
// POST /auth/wechat/miniapp/bind { "code": "wx.login的code" } Header: Bearer 令牌
//