Some checks failed
Build docker and publish / linux (1.24.5) (push) Failing after 40s
feat(pay): 添加支付API基础结构 feat(miniapp): 创建支付测试小程序页面与配置 feat(wechatpay): 配置微信支付参数与证书 fix(guild): 修复成员列表查询条件 docs: 更新代码规范文档与需求文档 style: 统一前后端枚举显示与注释格式 refactor(admin): 重构用户奖励发放接口参数处理 test(title): 添加称号效果参数验证测试
49 lines
1.7 KiB
Go
49 lines
1.7 KiB
Go
package admin
|
|
|
|
import (
|
|
"encoding/base64"
|
|
"net/http"
|
|
"net/url"
|
|
|
|
"bindbox-game/configs"
|
|
"bindbox-game/internal/code"
|
|
"bindbox-game/internal/pkg/core"
|
|
"bindbox-game/internal/pkg/validation"
|
|
"bindbox-game/internal/pkg/wechat"
|
|
)
|
|
|
|
type miniappQRCodeRequest struct {
|
|
InviteCode string `json:"invite_code"`
|
|
DouyinID string `json:"douyin_id"`
|
|
Width *int `json:"width"`
|
|
}
|
|
|
|
type miniappQRCodeResponse struct {
|
|
ImageBase64 string `json:"image_base64"`
|
|
}
|
|
|
|
func (h *handler) GenerateMiniAppQRCode() core.HandlerFunc {
|
|
return func(ctx core.Context) {
|
|
req := new(miniappQRCodeRequest)
|
|
if err := ctx.ShouldBindJSON(req); err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, validation.Error(err)))
|
|
return
|
|
}
|
|
if req.InviteCode == "" || req.DouyinID == "" {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, code.ParamBindError, "invite_code 与 douyin_id 不能为空"))
|
|
return
|
|
}
|
|
path := "/pages/login/index?invite_code=" + url.QueryEscape(req.InviteCode) + "&douyin_id=" + url.QueryEscape(req.DouyinID)
|
|
cfg := configs.Get()
|
|
wxcfg := &wechat.WechatConfig{AppID: cfg.Wechat.AppID, AppSecret: cfg.Wechat.AppSecret}
|
|
q := &wechat.QRCodeRequest{Path: path}
|
|
if req.Width != nil { q.Width = *req.Width }
|
|
rsp, err := wechat.GetQRCodeWithConfig(ctx, wxcfg, q)
|
|
if err != nil {
|
|
ctx.AbortWithError(core.Error(http.StatusBadRequest, 12001, err.Error()))
|
|
return
|
|
}
|
|
out := &miniappQRCodeResponse{ImageBase64: base64.StdEncoding.EncodeToString(rsp.Buffer)}
|
|
ctx.Payload(out)
|
|
}
|
|
} |