Fix baishun wallet payload and callback log sizing
This commit is contained in:
parent
39e70ad0a3
commit
46ddaca893
@ -41,13 +41,18 @@ type GoldReceiptCommand struct {
|
||||
SysOrigin string `json:"sysOrigin"`
|
||||
EventID string `json:"eventId"`
|
||||
Remark string `json:"remark,omitempty"`
|
||||
Amount int64 `json:"amount"`
|
||||
Amount PennyAmountPayload `json:"amount"`
|
||||
CloseDelayAsset bool `json:"closeDelayAsset"`
|
||||
OpUserType string `json:"opUserType"`
|
||||
CustomizeOrigin string `json:"customizeOrigin,omitempty"`
|
||||
CustomizeOriginDesc string `json:"customizeOriginDesc,omitempty"`
|
||||
}
|
||||
|
||||
type PennyAmountPayload struct {
|
||||
PennyAmount int64 `json:"pennyAmount,string"`
|
||||
DollarAmount int64 `json:"dollarAmount"`
|
||||
}
|
||||
|
||||
type TestGoldReceiptCommand struct {
|
||||
ReceiptType string `json:"receiptType"`
|
||||
UserID int64 `json:"userId"`
|
||||
@ -299,12 +304,19 @@ func (c *Client) ChangeGoldBalance(ctx context.Context, cmd GoldReceiptCommand)
|
||||
EventID: cmd.EventID,
|
||||
SysOrigin: cmd.SysOrigin,
|
||||
Remark: cmd.Remark,
|
||||
Amount: cmd.Amount,
|
||||
Amount: cmd.Amount.DollarAmount,
|
||||
CloseDelayAsset: cmd.CloseDelayAsset,
|
||||
}
|
||||
return c.postJSON(ctx, c.cfg.JavaWalletBaseURL+"/wallet/gold/client/balance/change/test", testCmd, nil, nil)
|
||||
}
|
||||
|
||||
func NewPennyAmountPayloadFromDollar(amount int64) PennyAmountPayload {
|
||||
return PennyAmountPayload{
|
||||
PennyAmount: amount * 100,
|
||||
DollarAmount: amount,
|
||||
}
|
||||
}
|
||||
|
||||
func shouldFallbackToGoldTestEndpoint(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
|
||||
@ -132,7 +132,7 @@ type BaishunCallbackLog struct {
|
||||
RequestJSON string `gorm:"column:request_json;type:longtext"`
|
||||
ResponseJSON string `gorm:"column:response_json;type:longtext"`
|
||||
BizCode string `gorm:"column:biz_code;size:32"`
|
||||
BizMessage string `gorm:"column:biz_message;size:255"`
|
||||
BizMessage string `gorm:"column:biz_message;type:text"`
|
||||
Status string `gorm:"column:status;size:32"`
|
||||
CreateTime time.Time `gorm:"column:create_time;index:idx_baishun_log_type_time,priority:2"`
|
||||
UpdateTime time.Time `gorm:"column:update_time"`
|
||||
|
||||
@ -43,7 +43,7 @@ func (r *Repository) Ping(ctx context.Context) error {
|
||||
}
|
||||
|
||||
func (r *Repository) AutoMigrate() error {
|
||||
return r.DB.AutoMigrate(
|
||||
if err := r.DB.AutoMigrate(
|
||||
&model.InviteCampaignConfig{},
|
||||
&model.InviteCampaignRewardRule{},
|
||||
&model.InviteCampaignRelation{},
|
||||
@ -58,5 +58,10 @@ func (r *Repository) AutoMigrate() error {
|
||||
&model.BaishunOrderIdempotency{},
|
||||
&model.BaishunCallbackLog{},
|
||||
&model.BaishunRoomState{},
|
||||
)
|
||||
); err != nil {
|
||||
return err
|
||||
}
|
||||
|
||||
// Keep callback error details queryable even when downstream returns a long body.
|
||||
return r.DB.Exec("ALTER TABLE baishun_callback_log MODIFY COLUMN biz_message TEXT NULL").Error
|
||||
}
|
||||
|
||||
@ -48,6 +48,7 @@ const (
|
||||
baishunCodeSignatureError = 1010
|
||||
baishunCodeRepeatUnknown = 1011
|
||||
baishunCodeServerError = 1999
|
||||
legacyBizMessageRuneLimit = 255
|
||||
)
|
||||
|
||||
type BaishunService struct {
|
||||
@ -789,7 +790,7 @@ func (s *BaishunService) HandleChangeBalance(ctx context.Context, req BaishunCha
|
||||
SysOrigin: session.SysOrigin,
|
||||
EventID: walletEventID,
|
||||
Remark: defaultIfBlank(req.DiffMsg, req.MsgType),
|
||||
Amount: abs64(req.CurrencyDiff),
|
||||
Amount: integration.NewPennyAmountPayloadFromDollar(abs64(req.CurrencyDiff)),
|
||||
CloseDelayAsset: false,
|
||||
OpUserType: "APP",
|
||||
CustomizeOrigin: fmt.Sprintf("BAISHUN_GAME_%d", req.GameID),
|
||||
@ -1204,8 +1205,12 @@ func (s *BaishunService) saveCallbackLog(ctx context.Context, requestType, reque
|
||||
parsed := parseInt64Default(userID)
|
||||
logRecord.UserID = &parsed
|
||||
}
|
||||
err = s.repo.DB.WithContext(ctx).Create(&logRecord).Error
|
||||
if err != nil && isBizMessageTooLongError(err) {
|
||||
logRecord.BizMessage = truncateRunes(logRecord.BizMessage, legacyBizMessageRuneLimit)
|
||||
_ = s.repo.DB.WithContext(ctx).Create(&logRecord).Error
|
||||
}
|
||||
}
|
||||
|
||||
func (s *BaishunService) failStandard(code int, message string) baishunStandardResponse {
|
||||
return baishunStandardResponse{
|
||||
@ -1357,6 +1362,25 @@ func abs64(value int64) int64 {
|
||||
return value
|
||||
}
|
||||
|
||||
func isBizMessageTooLongError(err error) bool {
|
||||
if err == nil {
|
||||
return false
|
||||
}
|
||||
message := strings.ToLower(err.Error())
|
||||
return strings.Contains(message, "data too long") && strings.Contains(message, "biz_message")
|
||||
}
|
||||
|
||||
func truncateRunes(value string, limit int) string {
|
||||
if limit <= 0 || value == "" {
|
||||
return ""
|
||||
}
|
||||
runes := []rune(value)
|
||||
if len(runes) <= limit {
|
||||
return value
|
||||
}
|
||||
return string(runes[:limit])
|
||||
}
|
||||
|
||||
func parseInt64Default(value string) int64 {
|
||||
parsed, _ := strconv.ParseInt(strings.TrimSpace(value), 10, 64)
|
||||
return parsed
|
||||
|
||||
@ -114,7 +114,7 @@ CREATE TABLE IF NOT EXISTS baishun_callback_log (
|
||||
request_json LONGTEXT DEFAULT NULL,
|
||||
response_json LONGTEXT DEFAULT NULL,
|
||||
biz_code VARCHAR(32) DEFAULT NULL,
|
||||
biz_message VARCHAR(255) DEFAULT NULL,
|
||||
biz_message TEXT DEFAULT NULL,
|
||||
status VARCHAR(32) NOT NULL DEFAULT 'SUCCESS',
|
||||
create_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP,
|
||||
update_time DATETIME NOT NULL DEFAULT CURRENT_TIMESTAMP ON UPDATE CURRENT_TIMESTAMP,
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user