更新密码找回uniapp
This commit is contained in:
1 parent
7f9a66da0f
commit
3fdda89833
1304 files changed
+3503
-26132
No files matched your search
@@ -18,14 +18,6 @@ import (
|
||||
beego "github.com/beego/beego/v2/server/web"
|
||||
)
|
||||
|
||||
// =============================================================
|
||||
// 平台端「微信公众号(服务号)」:
|
||||
// 配置(AppID/Secret/Token/AESKey)、绑定(扫码关注取验证码)、粉丝管理、消息推送
|
||||
// 未认证阶段可完整跑通「扫码关注 → 公众号回复验证码 → 平台核销绑定」;
|
||||
// 认证后开启模板消息推送(提醒/公告)。
|
||||
// =============================================================
|
||||
|
||||
// PlatformWechatMpController 平台端微信公众号管理
|
||||
type PlatformWechatMpController struct {
|
||||
beego.Controller
|
||||
}
|
||||
@@ -65,9 +57,6 @@ func (c *PlatformWechatMpController) readBody(out interface{}) bool {
|
||||
return true
|
||||
}
|
||||
|
||||
// ============================ 配置 ============================
|
||||
|
||||
// GetConfig GET /platform/wechatMp/config
|
||||
func (c *PlatformWechatMpController) GetConfig() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -107,7 +96,6 @@ func (c *PlatformWechatMpController) GetConfig() {
|
||||
c.ok(data, "获取成功")
|
||||
}
|
||||
|
||||
// SaveConfig POST /platform/wechatMp/config
|
||||
func (c *PlatformWechatMpController) SaveConfig() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -150,8 +138,6 @@ func (c *PlatformWechatMpController) SaveConfig() {
|
||||
c.ok(nil, "保存成功")
|
||||
}
|
||||
|
||||
// TestConnection POST /platform/wechatMp/test
|
||||
// 使用当前配置获取 access_token,验证 AppID/AppSecret 是否正确
|
||||
func (c *PlatformWechatMpController) TestConnection() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -163,7 +149,6 @@ func (c *PlatformWechatMpController) TestConnection() {
|
||||
c.jsonErr(400, 400, "请先保存 AppID 与 AppSecret")
|
||||
return
|
||||
}
|
||||
// 出口 IP 一并返回:40164(IP 不在白名单)时管理员可直接复制去微信后台配置
|
||||
outboundIP := wechatmp.OutboundIP()
|
||||
token, err := wechatmp.GetAccessToken(cfg)
|
||||
if err != nil {
|
||||
@@ -189,11 +174,6 @@ func (c *PlatformWechatMpController) TestConnection() {
|
||||
}, msg)
|
||||
}
|
||||
|
||||
// ============================ 绑定(当前平台用户) ============================
|
||||
|
||||
// BindStart POST /platform/wechatMp/bind/start
|
||||
// 未认证公众号无法生成带参二维码(48001):不再下发二维码,
|
||||
// 返回绑定指引(公众号内发送「验证码」取码 → 页面填码 → bind/confirm 核销)。
|
||||
func (c *PlatformWechatMpController) BindStart() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
@@ -219,11 +199,6 @@ func (c *PlatformWechatMpController) BindStart() {
|
||||
}, "请按指引完成绑定")
|
||||
}
|
||||
|
||||
// ============================ 自定义菜单 ============================
|
||||
|
||||
// PublishMenu POST /platform/wechatMp/menu/publish
|
||||
// 通过接口在公众号底部发布「扫码登录」菜单(点击 → 自动回复确认登录链接)。
|
||||
// 需认证公众号;未认证(48001)时提示改用「公众号内发送登录」路径。
|
||||
func (c *PlatformWechatMpController) PublishMenu() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -245,7 +220,6 @@ func (c *PlatformWechatMpController) PublishMenu() {
|
||||
return
|
||||
}
|
||||
|
||||
// 微信客户端有菜单缓存:发布后需重新关注或等待(最长 24 小时)才可见
|
||||
msg := "菜单已发布:微信客户端有缓存,请重新关注公众号或等待刷新(最长 24 小时)后可见「扫码登录」"
|
||||
if res.AlreadyExists {
|
||||
msg = "菜单中已存在「扫码登录」入口,未重复发布;若底部未显示,请等待客户端刷新或重新关注"
|
||||
@@ -261,16 +235,12 @@ func (c *PlatformWechatMpController) PublishMenu() {
|
||||
}, msg)
|
||||
}
|
||||
|
||||
// ============================ 关注二维码 ============================
|
||||
|
||||
// 二维码图片限制:2MB,常见图片格式
|
||||
const followQrcodeMaxBytes = 2 * 1024 * 1024
|
||||
|
||||
var followQrcodeAllowedExts = map[string]bool{
|
||||
"jpg": true, "jpeg": true, "png": true, "gif": true, "webp": true, "bmp": true,
|
||||
}
|
||||
|
||||
// saveFollowQrcode 校验图片并写入配置表(data URL 存储),返回 data URL
|
||||
func (c *PlatformWechatMpController) saveFollowQrcode() (string, error) {
|
||||
if err := c.Ctx.Request.ParseMultipartForm(followQrcodeMaxBytes); err != nil {
|
||||
return "", fmt.Errorf("解析上传失败: %w", err)
|
||||
@@ -308,8 +278,6 @@ func (c *PlatformWechatMpController) saveFollowQrcode() (string, error) {
|
||||
return "data:" + mime + ";base64," + base64.StdEncoding.EncodeToString(raw), nil
|
||||
}
|
||||
|
||||
// UploadFollowQrcode POST /platform/wechatMp/followQrcode
|
||||
// 上传公众号「关注二维码」图片(普通二维码,用户扫码进入公众号会话)
|
||||
func (c *PlatformWechatMpController) UploadFollowQrcode() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -328,7 +296,6 @@ func (c *PlatformWechatMpController) UploadFollowQrcode() {
|
||||
c.ok(map[string]interface{}{"follow_qrcode": dataURL}, "上传成功")
|
||||
}
|
||||
|
||||
// DeleteFollowQrcode POST /platform/wechatMp/followQrcode/delete
|
||||
func (c *PlatformWechatMpController) DeleteFollowQrcode() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -342,7 +309,6 @@ func (c *PlatformWechatMpController) DeleteFollowQrcode() {
|
||||
c.ok(nil, "已删除")
|
||||
}
|
||||
|
||||
// BindStatus GET /platform/wechatMp/bind/status?scene=xxx
|
||||
func (c *PlatformWechatMpController) BindStatus() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
@@ -366,7 +332,6 @@ func (c *PlatformWechatMpController) BindStatus() {
|
||||
}, "获取成功")
|
||||
}
|
||||
|
||||
// BindConfirm POST /platform/wechatMp/bind/confirm {scene, code}
|
||||
func (c *PlatformWechatMpController) BindConfirm() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
@@ -387,7 +352,6 @@ func (c *PlatformWechatMpController) BindConfirm() {
|
||||
}
|
||||
var follower *models.WechatMpFollower
|
||||
if strings.TrimSpace(p.Scene) == "" {
|
||||
// 未展示二维码(在公众号内发送「验证码」获取):按验证码认领待认领会话
|
||||
follower, err = wechatmp.ConfirmVerifyCodeByCode(models.WechatBindTypePlatformUser, uint64(claims.UserID), 0, p.Code)
|
||||
} else {
|
||||
follower, err = wechatmp.ConfirmVerifyCode(models.WechatBindTypePlatformUser, uint64(claims.UserID), 0, p.Scene, p.Code)
|
||||
@@ -403,7 +367,6 @@ func (c *PlatformWechatMpController) BindConfirm() {
|
||||
}, "绑定成功")
|
||||
}
|
||||
|
||||
// MyBinding GET /platform/wechatMp/my
|
||||
func (c *PlatformWechatMpController) MyBinding() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
@@ -431,7 +394,6 @@ func (c *PlatformWechatMpController) MyBinding() {
|
||||
}, "获取成功")
|
||||
}
|
||||
|
||||
// Unbind POST /platform/wechatMp/unbind
|
||||
func (c *PlatformWechatMpController) Unbind() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
@@ -446,9 +408,6 @@ func (c *PlatformWechatMpController) Unbind() {
|
||||
c.ok(nil, "已解绑")
|
||||
}
|
||||
|
||||
// ============================ 粉丝管理 ============================
|
||||
|
||||
// ListFollowers GET /platform/wechatMp/followers?page=&pageSize=&keyword=&bind_type=&subscribe=
|
||||
func (c *PlatformWechatMpController) ListFollowers() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -490,7 +449,6 @@ func (c *PlatformWechatMpController) ListFollowers() {
|
||||
return
|
||||
}
|
||||
|
||||
// 绑定对象名称(平台用户 / 租户用户)
|
||||
nameMap := loadWechatBindNames(rows)
|
||||
|
||||
list := make([]map[string]interface{}, 0, len(rows))
|
||||
@@ -522,7 +480,6 @@ func (c *PlatformWechatMpController) ListFollowers() {
|
||||
c.ok(map[string]interface{}{"list": list, "total": total, "page": page, "pageSize": pageSize}, "获取成功")
|
||||
}
|
||||
|
||||
// SetFollowerRemark POST /platform/wechatMp/follower/remark {id, remark}
|
||||
func (c *PlatformWechatMpController) SetFollowerRemark() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -550,8 +507,6 @@ func (c *PlatformWechatMpController) SetFollowerRemark() {
|
||||
c.ok(nil, "保存成功")
|
||||
}
|
||||
|
||||
// UnbindFollower POST /platform/wechatMp/follower/unbind {id}
|
||||
// 仅清除绑定关系(保留粉丝记录)
|
||||
func (c *PlatformWechatMpController) UnbindFollower() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -580,10 +535,6 @@ func (c *PlatformWechatMpController) UnbindFollower() {
|
||||
c.ok(nil, "已解绑")
|
||||
}
|
||||
|
||||
// ============================ 推送 ============================
|
||||
|
||||
// Push POST /platform/wechatMp/push
|
||||
// {title, content, remark, url, bind_type, bind_id, tid}
|
||||
func (c *PlatformWechatMpController) Push() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
code := identity.Status(err)
|
||||
@@ -629,8 +580,6 @@ func (c *PlatformWechatMpController) Push() {
|
||||
fmt.Sprintf("推送完成:成功 %d 条,失败 %d 条", sent, failed))
|
||||
}
|
||||
|
||||
// PushTest POST /platform/wechatMp/push/test {title, content, remark}
|
||||
// 推送给当前登录平台用户绑定的微信
|
||||
func (c *PlatformWechatMpController) PushTest() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
@@ -677,8 +626,6 @@ func (c *PlatformWechatMpController) PushTest() {
|
||||
c.ok(nil, "测试消息已发送")
|
||||
}
|
||||
|
||||
// ============================ 辅助 ============================
|
||||
|
||||
func boolToInt8(b bool) int8 {
|
||||
if b {
|
||||
return 1
|
||||
@@ -693,7 +640,6 @@ func maskOpenID(openid string) string {
|
||||
return openid[:4] + "****" + openid[len(openid)-4:]
|
||||
}
|
||||
|
||||
// loadWechatBindNames 批量加载粉丝绑定对象名称:key = bindType#bindID#bindTid
|
||||
func loadWechatBindNames(rows []models.WechatMpFollower) map[string]string {
|
||||
names := map[string]string{}
|
||||
if len(rows) == 0 {
|
||||
|
||||
Reference in new issue
Block a user