后台,应用通知地址

This commit is contained in:
wolter 2024-08-08 18:16:53 +08:00
parent 5e0627a0f3
commit 8c05e8ff06
4 changed files with 51 additions and 25 deletions

View File

@ -34,7 +34,11 @@ func AppList(c *gin.Context) {
func AppCreate(c *gin.Context) { func AppCreate(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.AppCreateRequest) req, _ := controllers.GetRequest(c).(*backend.AppCreateRequest)
payChannel := req.RequestToDb() payChannel, err := req.RequestToDb()
if err != nil {
controllers.Error(c, errorcode.ParamError, err.Error())
return
}
code := services.AppCreate(&payChannel) code := services.AppCreate(&payChannel)
data := backend.AppResponse{} data := backend.AppResponse{}
@ -44,7 +48,11 @@ func AppCreate(c *gin.Context) {
func AppUpdate(c *gin.Context) { func AppUpdate(c *gin.Context) {
req, _ := controllers.GetRequest(c).(*backend.AppUpdateRequest) req, _ := controllers.GetRequest(c).(*backend.AppUpdateRequest)
payChannel := req.RequestToDb() payChannel, err := req.RequestToDb()
if err != nil {
controllers.Error(c, errorcode.ParamError, err.Error())
return
}
code := services.AppUpdate(&payChannel) code := services.AppUpdate(&payChannel)
data := backend.AppResponse{} data := backend.AppResponse{}

View File

@ -3,6 +3,8 @@ package backend
import ( import (
"PaymentCenter/app/http/entities" "PaymentCenter/app/http/entities"
"PaymentCenter/app/models/appmodel" "PaymentCenter/app/models/appmodel"
"errors"
"strings"
) )
type AppListRequest struct { type AppListRequest struct {
@ -54,7 +56,9 @@ type AppCreateRequest struct {
NotifyUrl string `json:"notify_url" validate:"required" label:"通知地址"` NotifyUrl string `json:"notify_url" validate:"required" label:"通知地址"`
} }
func (a *AppCreateRequest) RequestToDb() (db appmodel.App) { func (a *AppCreateRequest) RequestToDb() (db appmodel.App, err error) {
// 判断通知地址url是否合法
if a.NotifyUrl == "" || strings.HasPrefix(a.NotifyUrl, "http://") || strings.HasPrefix(a.NotifyUrl, "https://") {
db.MerchantId = a.MerchantId db.MerchantId = a.MerchantId
db.AppName = a.AppName db.AppName = a.AppName
db.AppRemark = a.AppRemark db.AppRemark = a.AppRemark
@ -65,6 +69,11 @@ func (a *AppCreateRequest) RequestToDb() (db appmodel.App) {
db.MerchantPublicKey = a.MerchantPublicKey db.MerchantPublicKey = a.MerchantPublicKey
db.WhiteIp = a.WhiteIp db.WhiteIp = a.WhiteIp
db.NotifyUrl = a.NotifyUrl db.NotifyUrl = a.NotifyUrl
} else {
err = errors.New("通知地址格式不正确")
return
}
return return
} }
@ -81,7 +90,9 @@ type AppUpdateRequest struct {
NotifyUrl string `json:"notify_url"` NotifyUrl string `json:"notify_url"`
} }
func (a *AppUpdateRequest) RequestToDb() (db appmodel.App) { func (a *AppUpdateRequest) RequestToDb() (db appmodel.App, err error) {
// 判断通知地址url是否合法
if a.NotifyUrl == "" || strings.HasPrefix(a.NotifyUrl, "http://") || strings.HasPrefix(a.NotifyUrl, "https://") {
db.Id = a.Id db.Id = a.Id
db.AppName = a.AppName db.AppName = a.AppName
db.AppRemark = a.AppRemark db.AppRemark = a.AppRemark
@ -92,6 +103,10 @@ func (a *AppUpdateRequest) RequestToDb() (db appmodel.App) {
db.MerchantPublicKey = a.MerchantPublicKey db.MerchantPublicKey = a.MerchantPublicKey
db.WhiteIp = a.WhiteIp db.WhiteIp = a.WhiteIp
db.NotifyUrl = a.NotifyUrl db.NotifyUrl = a.NotifyUrl
} else {
err = errors.New("通知地址格式不正确")
return
}
return return
} }

View File

@ -61,7 +61,7 @@ func AppUpdate(app *appmodel.App) (code int) {
conn = conn.And(builder.Eq{"Id": app.Id}) conn = conn.And(builder.Eq{"Id": app.Id})
if app.AppName != "" { if app.AppName != "" {
// 编辑页面更新备注和白名单IP可更新为空 // 编辑页面更新备注和白名单IP可更新为空
_, err = repo.AppUpdate(app, conn, "app_remark", "white_ip") _, err = repo.AppUpdate(app, conn, "app_remark", "white_ip", "notify_url")
} else { } else {
_, err = repo.AppUpdate(app, conn) _, err = repo.AppUpdate(app, conn)
} }

View File

@ -96,6 +96,9 @@ func (o *OrderNotify) Handle() (res *OrderNotifyResp) {
// 发送下游回调通知 // 发送下游回调通知
func (o *OrderNotify) sendNotify(body *OrderNotifySendContent) { func (o *OrderNotify) sendNotify(body *OrderNotifySendContent) {
if o.app.NotifyUrl == "" {
return
}
var callbackStatus = common.STATUS_ENABLE var callbackStatus = common.STATUS_ENABLE
var response string var response string