更新
This commit is contained in:
1 parent
5718a00e31
commit
1850ac640e
226 files changed
+37772
-12071
No files matched your search
@@ -10,6 +10,7 @@ import (
|
||||
"time"
|
||||
|
||||
"server/models"
|
||||
"server/pkg/identity"
|
||||
"server/pkg/jwtutil"
|
||||
"server/services/wechatmp"
|
||||
|
||||
@@ -30,22 +31,7 @@ type PlatformWechatMpController struct {
|
||||
}
|
||||
|
||||
func (c *PlatformWechatMpController) claims() (*jwtutil.Claims, error) {
|
||||
auth := c.Ctx.Request.Header.Get("Authorization")
|
||||
if auth == "" {
|
||||
return nil, fmt.Errorf("未登录")
|
||||
}
|
||||
parts := strings.SplitN(auth, " ", 2)
|
||||
if len(parts) != 2 || parts[0] != "Bearer" {
|
||||
return nil, fmt.Errorf("认证信息格式错误")
|
||||
}
|
||||
claims, err := jwtutil.ParseToken(parts[1])
|
||||
if err != nil {
|
||||
return nil, fmt.Errorf("无效的token")
|
||||
}
|
||||
if claims.UserType != "platform" {
|
||||
return nil, fmt.Errorf("无权访问")
|
||||
}
|
||||
return claims, nil
|
||||
return identity.Claims(c.Ctx.Request.Header.Get("Authorization"), identity.EndPlatform)
|
||||
}
|
||||
|
||||
func (c *PlatformWechatMpController) jsonErr(httpStatus, bizCode int, msg string) {
|
||||
@@ -84,7 +70,8 @@ func (c *PlatformWechatMpController) readBody(out interface{}) bool {
|
||||
// GetConfig GET /platform/wechatMp/config
|
||||
func (c *PlatformWechatMpController) GetConfig() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
data := map[string]interface{}{
|
||||
@@ -123,7 +110,8 @@ func (c *PlatformWechatMpController) GetConfig() {
|
||||
// SaveConfig POST /platform/wechatMp/config
|
||||
func (c *PlatformWechatMpController) SaveConfig() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
@@ -166,7 +154,8 @@ func (c *PlatformWechatMpController) SaveConfig() {
|
||||
// 使用当前配置获取 access_token,验证 AppID/AppSecret 是否正确
|
||||
func (c *PlatformWechatMpController) TestConnection() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
cfg, err := wechatmp.LoadConfig()
|
||||
@@ -198,7 +187,8 @@ func (c *PlatformWechatMpController) TestConnection() {
|
||||
func (c *PlatformWechatMpController) BindStart() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
uid := uint64(claims.UserID)
|
||||
@@ -226,7 +216,8 @@ func (c *PlatformWechatMpController) BindStart() {
|
||||
// 需认证公众号;未认证(48001)时提示改用「公众号内发送登录」路径。
|
||||
func (c *PlatformWechatMpController) PublishMenu() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
cfg, err := wechatmp.LoadEnabledConfig()
|
||||
@@ -311,7 +302,8 @@ func (c *PlatformWechatMpController) saveFollowQrcode() (string, error) {
|
||||
// 上传公众号「关注二维码」图片(普通二维码,用户扫码进入公众号会话)
|
||||
func (c *PlatformWechatMpController) UploadFollowQrcode() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
dataURL, err := c.saveFollowQrcode()
|
||||
@@ -329,7 +321,8 @@ func (c *PlatformWechatMpController) UploadFollowQrcode() {
|
||||
// DeleteFollowQrcode POST /platform/wechatMp/followQrcode/delete
|
||||
func (c *PlatformWechatMpController) DeleteFollowQrcode() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
if err := wechatmp.SaveFollowQrcode(""); err != nil {
|
||||
@@ -343,7 +336,8 @@ func (c *PlatformWechatMpController) DeleteFollowQrcode() {
|
||||
func (c *PlatformWechatMpController) BindStatus() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
scene := strings.TrimSpace(c.GetString("scene"))
|
||||
@@ -366,7 +360,8 @@ func (c *PlatformWechatMpController) BindStatus() {
|
||||
func (c *PlatformWechatMpController) BindConfirm() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
@@ -402,7 +397,8 @@ func (c *PlatformWechatMpController) BindConfirm() {
|
||||
func (c *PlatformWechatMpController) MyBinding() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
follower, err := wechatmp.GetFollowerByUser(models.WechatBindTypePlatformUser, uint64(claims.UserID))
|
||||
@@ -429,7 +425,8 @@ func (c *PlatformWechatMpController) MyBinding() {
|
||||
func (c *PlatformWechatMpController) Unbind() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
if err := wechatmp.UnbindByUser(models.WechatBindTypePlatformUser, uint64(claims.UserID)); err != nil {
|
||||
@@ -444,7 +441,8 @@ func (c *PlatformWechatMpController) Unbind() {
|
||||
// ListFollowers GET /platform/wechatMp/followers?page=&pageSize=&keyword=&bind_type=&subscribe=
|
||||
func (c *PlatformWechatMpController) ListFollowers() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
page, _ := c.GetInt("page", 1)
|
||||
@@ -517,7 +515,8 @@ func (c *PlatformWechatMpController) ListFollowers() {
|
||||
// SetFollowerRemark POST /platform/wechatMp/follower/remark {id, remark}
|
||||
func (c *PlatformWechatMpController) SetFollowerRemark() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
@@ -545,7 +544,8 @@ func (c *PlatformWechatMpController) SetFollowerRemark() {
|
||||
// 仅清除绑定关系(保留粉丝记录)
|
||||
func (c *PlatformWechatMpController) UnbindFollower() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
@@ -576,7 +576,8 @@ func (c *PlatformWechatMpController) UnbindFollower() {
|
||||
// {title, content, remark, url, bind_type, bind_id, tid}
|
||||
func (c *PlatformWechatMpController) Push() {
|
||||
if _, err := c.claims(); err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
@@ -623,7 +624,8 @@ func (c *PlatformWechatMpController) Push() {
|
||||
func (c *PlatformWechatMpController) PushTest() {
|
||||
claims, err := c.claims()
|
||||
if err != nil {
|
||||
c.jsonErr(401, 401, err.Error())
|
||||
code := identity.Status(err)
|
||||
c.jsonErr(code, code, err.Error())
|
||||
return
|
||||
}
|
||||
var p struct {
|
||||
|
||||
Reference in new issue
Block a user