This commit is contained in:
jiangyong 2025-03-16 19:05:33 +08:00
parent 6c9594dd05
commit 86955148c1
4 changed files with 26 additions and 4 deletions

View File

@ -1,7 +1,9 @@
package util
import (
"encoding/base64"
"fmt"
qrcode "github.com/skip2/go-qrcode"
"github.com/spf13/cast"
"math/rand"
"time"
@ -29,3 +31,14 @@ func CutTail(str string, length int) string {
func FloatCut(f float64) float64 {
return cast.ToFloat64(fmt.Sprintf("%.2f", f))
}
func CreateQrcodeBase64V2(content string, level qrcode.RecoveryLevel, size int) (string, error) {
var png []byte
//固定方法
png, err := qrcode.Encode(content, level, size)
if err != nil {
return "", err
}
//文件流需要使用base64编码后才可使用
return base64.StdEncoding.EncodeToString(png), nil
}

1
go.mod
View File

@ -18,6 +18,7 @@ require (
github.com/rifflock/lfshook v0.0.0-20180920164130-b9218ef580f5
github.com/robertkrimen/otto v0.5.1
github.com/sirupsen/logrus v1.9.3
github.com/skip2/go-qrcode v0.0.0-20200617195104-da1b6568686e
github.com/smartwalle/alipay/v3 v3.2.23
github.com/smbrave/goutil v0.0.0-20250312151244-845a8a40e8aa
github.com/spf13/cast v1.7.0

View File

@ -1,7 +1,10 @@
package api
import (
butil "enterprise/base/util"
"enterprise/common/model"
"fmt"
"github.com/skip2/go-qrcode"
"github.com/smbrave/goutil"
"github.com/spf13/cast"
)
@ -30,6 +33,8 @@ type StaffUser struct {
PayeeBankName string `json:"payee_bank_name"`
PayeeBankCard string `json:"payee_bank_card"`
PayeeAlipayUid string `json:"payee_alipay_uid"`
PayeeAlipayAuthUrl string `json:"payee_alipay_auth_url"`
PayeeAlipayAuthQrcode string `json:"payee_alipay_auth_qrcode"`
Config interface{} `json:"config"`
}
@ -81,4 +86,7 @@ func (s *StaffUser) From(m *model.StaffUser) {
s.PayeeBankName = payee.BankName
s.PayeeBankCard = payee.BankCard
s.PayeeAlipayUid = payee.AlipayUid
s.PayeeAlipayAuthUrl = fmt.Sprintf("https://openauth.alipay.com/oauth2/publicAppAuthorize.htm?app_id=2021004108682468&scope=auth_base&state=%d&redirect_uri=https://e.batiao8.com/api/payment/auth/alipay", m.Id)
s.PayeeAlipayAuthQrcode, _ = butil.CreateQrcodeBase64V2(s.PayeeAlipayAuthUrl, qrcode.Low, 300)
}

View File

@ -30,7 +30,7 @@ func (p *Pay) AlipayAuth(sess *session.AdminSession, authCode, state string) (st
corp, err := dao.NewCorpDao().GetByHost(sess.GetHeader().Host)
session.CheckDBError(err)
session.CheckNilError(corp)
cli := config.GetAliPayClient(corp.GetConfig().PayChannel)
cli := config.GetAliPayClient("batiao")
var req alipay.SystemOauthToken
req.Code = authCode