统一三方游戏重复订单返回10003

This commit is contained in:
hy001 2026-04-23 18:00:34 +08:00
parent 1d2bc6eafd
commit 5e81478c8b
3 changed files with 60 additions and 17 deletions

View File

@ -101,23 +101,26 @@ func (s *GameOpenService) HandleUpdateCoin(ctx context.Context, req UpdateCoinRe
s.saveCallbackLog(ctx, "update-coin", rawJSON, resp, credential.SysOrigin, req, &userID, gameOpenLogStatusFailed) s.saveCallbackLog(ctx, "update-coin", rawJSON, resp, credential.SysOrigin, req, &userID, gameOpenLogStatusFailed)
return resp return resp
} }
if !exists { if exists {
if err := s.java.ChangeGoldBalance(ctx, integration.GoldReceiptCommand{ resp := failResponse(gameOpenCodeDuplicateOrder, "duplicate orderId")
ReceiptType: receiptTypeFromType(req.Type), s.saveCallbackLog(ctx, "update-coin", rawJSON, resp, credential.SysOrigin, req, &userID, gameOpenLogStatusFailed)
UserID: userID, return resp
SysOrigin: credential.SysOrigin, }
EventID: eventID, if err := s.java.ChangeGoldBalance(ctx, integration.GoldReceiptCommand{
Remark: fmt.Sprintf("game=%s rewardType=%d round=%s", req.GameID, req.RewardType, req.RoundID), ReceiptType: receiptTypeFromType(req.Type),
Amount: integration.NewPennyAmountPayloadFromDollar(req.Coin), UserID: userID,
CloseDelayAsset: false, SysOrigin: credential.SysOrigin,
OpUserType: "APP", EventID: eventID,
CustomizeOrigin: "GAME_OPEN_" + strings.TrimSpace(req.GameID), Remark: fmt.Sprintf("game=%s rewardType=%d round=%s", req.GameID, req.RewardType, req.RoundID),
CustomizeOriginDesc: "GAME OPEN[" + strings.TrimSpace(req.GameID) + "]", Amount: integration.NewPennyAmountPayloadFromDollar(req.Coin),
}); err != nil { CloseDelayAsset: false,
resp := failResponse(gameOpenCodeServerError, err.Error()) OpUserType: "APP",
s.saveCallbackLog(ctx, "update-coin", rawJSON, resp, credential.SysOrigin, req, &userID, gameOpenLogStatusFailed) CustomizeOrigin: "GAME_OPEN_" + strings.TrimSpace(req.GameID),
return resp CustomizeOriginDesc: "GAME OPEN[" + strings.TrimSpace(req.GameID) + "]",
} }); err != nil {
resp := failResponse(gameOpenCodeServerError, err.Error())
s.saveCallbackLog(ctx, "update-coin", rawJSON, resp, credential.SysOrigin, req, &userID, gameOpenLogStatusFailed)
return resp
} }
balance, err := s.readUserBalance(ctx, userID) balance, err := s.readUserBalance(ctx, userID)

View File

@ -141,6 +141,45 @@ func TestHandleUpdateCoin(t *testing.T) {
} }
} }
func TestHandleUpdateCoinDuplicateOrderReturns10003(t *testing.T) {
gateway := &stubGateway{
credential: integration.UserCredential{UserID: 1234567, SysOrigin: "LIKEI"},
profile: integration.UserProfile{
ID: 1234567,
Account: "1234567",
},
balance: 99,
exists: true,
}
service := NewGameOpenService(config.Config{
GameOpen: config.GameOpenConfig{AppKey: "game-open-test-key"},
}, nil, gateway)
req := UpdateCoinRequest{
OrderID: "27822d8ba4a34d0e8db3e049716d427d",
GameID: "101",
RoundID: "round-1",
UID: "1234567",
Coin: 15,
Type: 2,
RewardType: 2,
Token: "token",
WinID: "win-1",
RoomID: "room-1",
}
req.Sign = buildUpdateCoinSign(req, "game-open-test-key")
resp := service.HandleUpdateCoin(context.Background(), req, "{}")
if resp.ErrorCode != gameOpenCodeDuplicateOrder {
t.Fatalf("HandleUpdateCoin() errorCode = %d, want %d", resp.ErrorCode, gameOpenCodeDuplicateOrder)
}
if resp.ErrorMsg != "duplicate orderId" {
t.Fatalf("HandleUpdateCoin() errorMsg = %q", resp.ErrorMsg)
}
if gateway.cmd.EventID != "" {
t.Fatalf("HandleUpdateCoin() should not change balance for duplicate order, got event id %q", gateway.cmd.EventID)
}
}
func TestHandleQueryUserAcceptsAccountUID(t *testing.T) { func TestHandleQueryUserAcceptsAccountUID(t *testing.T) {
gateway := &stubGateway{ gateway := &stubGateway{
credential: integration.UserCredential{UserID: 4569421795454615552, SysOrigin: "LIKEI"}, credential: integration.UserCredential{UserID: 4569421795454615552, SysOrigin: "LIKEI"},

View File

@ -11,6 +11,7 @@ import (
const ( const (
gameOpenCodeSuccess = 0 gameOpenCodeSuccess = 0
gameOpenCodeDuplicateOrder = 10003
gameOpenCodeBadRequest = 4001 gameOpenCodeBadRequest = 4001
gameOpenCodeSignatureError = 4002 gameOpenCodeSignatureError = 4002
gameOpenCodeTokenInvalid = 4003 gameOpenCodeTokenInvalid = 4003