Skip to content

Commit

Permalink
feat: add sign game YuanShen
Browse files Browse the repository at this point in the history
  • Loading branch information
starudream committed Dec 25, 2023
1 parent a8d61ba commit 930c65e
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 25 deletions.
2 changes: 2 additions & 0 deletions api/common/const.go
Original file line number Diff line number Diff line change
Expand Up @@ -34,4 +34,6 @@ const (
// https://github.com/UIGF-org/mihoyo-api-collect/blob/3a9116ea538941cfead749572df1f364cb9f9c8d/other/id.md#%E8%AE%BA%E5%9D%9Bid

ForumIdSR = "53"

XRpcSignGame = "x-rpc-signgame"
)
5 changes: 5 additions & 0 deletions api/miyoushe/home_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,11 @@ func TestGetHome(t *testing.T) {
testutil.LogNoErr(t, err, data)
})

t.Run(common.GameIdYS, func(t *testing.T) {
data, err := GetHome(common.GameIdYS)
testutil.LogNoErr(t, err, data, data.GetSignActId())
})

t.Run(common.GameIdSR, func(t *testing.T) {
data, err := GetHome(common.GameIdSR)
testutil.LogNoErr(t, err, data, data.GetSignActId())
Expand Down
16 changes: 8 additions & 8 deletions api/miyoushe/sign_game.go
Original file line number Diff line number Diff line change
Expand Up @@ -24,9 +24,9 @@ func (t *SignGameData) IsRisky() bool {
return t.IsRisk && t.RiskCode == 5001
}

func SignGame(actId, region, uid string, account config.Account, validate *common.Verification) (*SignGameData, error) {
func SignGame(gameName, actId, region, uid string, account config.Account, validate *common.Verification) (*SignGameData, error) {
body := gh.MS{"lang": "zh-cn", "act_id": actId, "region": region, "uid": uid}
req := common.R(account.Device, validate).SetCookies(common.SToken(account)).SetCookies(common.CToken(account)).SetBody(body)
req := common.R(account.Device, validate).SetHeader(common.XRpcSignGame, gameName).SetCookies(common.SToken(account)).SetCookies(common.CToken(account)).SetBody(body)
return common.Exec[*SignGameData](req, "POST", AddrTakumi+"/event/luna/sign")
}

Expand All @@ -40,9 +40,9 @@ type GetSignGameData struct {
ShortSignDay int `json:"short_sign_day"`
}

func GetSignGame(actId, region, uid string, account config.Account) (*GetSignGameData, error) {
func GetSignGame(gameName, actId, region, uid string, account config.Account) (*GetSignGameData, error) {
query := gh.MS{"lang": "zh-cn", "act_id": actId, "region": region, "uid": uid}
req := common.R(account.Device).SetCookies(common.SToken(account)).SetCookies(common.CToken(account)).SetQueryParams(query)
req := common.R(account.Device).SetHeader(common.XRpcSignGame, gameName).SetCookies(common.SToken(account)).SetCookies(common.CToken(account)).SetQueryParams(query)
return common.Exec[*GetSignGameData](req, "GET", AddrTakumi+"/event/luna/info")
}

Expand All @@ -69,9 +69,9 @@ type SignGameExtraAward struct {
EndTimestamp string `json:"end_timestamp"`
}

func ListSignGame(actId string, account config.Account) (*ListSignGameData, error) {
func ListSignGame(gameName, actId string, account config.Account) (*ListSignGameData, error) {
query := gh.MS{"lang": "zh-cn", "act_id": actId}
req := common.R(account.Device).SetCookies(common.SToken(account)).SetQueryParams(query)
req := common.R(account.Device).SetHeader(common.XRpcSignGame, gameName).SetCookies(common.SToken(account)).SetQueryParams(query)
return common.Exec[*ListSignGameData](req, "GET", AddrTakumi+"/event/luna/home")
}

Expand Down Expand Up @@ -100,10 +100,10 @@ func (v1 SignGameAwards) ShortString() string {
return strings.Join(v2, ", ")
}

func ListSignGameAward(actId, region, uid string, account config.Account) (list SignGameAwards, _ error) {
func ListSignGameAward(gameName, actId, region, uid string, account config.Account) (list SignGameAwards, _ error) {
for page, total := 1, -1; ; page++ {
query := gh.MS{"lang": "zh-cn", "act_id": actId, "region": region, "uid": uid, "current_page": strconv.Itoa(page), "page_size": "10"}
req := common.R(account.Device).SetCookies(common.SToken(account)).SetCookies(common.CToken(account)).SetQueryParams(query)
req := common.R(account.Device).SetHeader(common.XRpcSignGame, gameName).SetCookies(common.SToken(account)).SetCookies(common.CToken(account)).SetQueryParams(query)
data, err := common.Exec[*ListSignGameAwardData](req, "GET", AddrTakumi+"/event/luna/award")
if err != nil {
return nil, err
Expand Down
24 changes: 12 additions & 12 deletions api/miyoushe/sign_game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -9,23 +9,23 @@ import (
"github.com/starudream/miyoushe-task/config"
)

func GetSR(t *testing.T) (string, string, string) {
data1, err := GetHome(common.GameIdSR)
func GetSR(t *testing.T) (string, string, string, string) {
data1, err := GetHome(common.GameIdYS)
testutil.LogNoErr(t, err, data1)
actId := data1.GetSignActId()
testutil.NotEqual(t, "", actId)

data2, err := ListGameRole(common.GameBizSRCN, config.C().FirstAccount())
data2, err := ListGameRole(common.GameBizYSCN, config.C().FirstAccount())
testutil.LogNoErr(t, err, data2)
testutil.NotEqual(t, 0, len(data2.List))
region, uid := data2.List[0].Region, data2.List[0].GameUid

return actId, region, uid
return common.GameNameYS, actId, region, uid
}

func TestSignGame(t *testing.T) {
actId, region, uid := GetSR(t)
data, err := SignGame(actId, region, uid, config.C().FirstAccount(), nil)
gameName, actId, region, uid := GetSR(t)
data, err := SignGame(gameName, actId, region, uid, config.C().FirstAccount(), nil)
if common.IsRetCode(err, common.RetCodeGameHasSigned) {
t.Skip("game has signed")
}
Expand All @@ -34,19 +34,19 @@ func TestSignGame(t *testing.T) {
}

func TestGetSignGame(t *testing.T) {
actId, region, uid := GetSR(t)
data, err := GetSignGame(actId, region, uid, config.C().FirstAccount())
gameName, actId, region, uid := GetSR(t)
data, err := GetSignGame(gameName, actId, region, uid, config.C().FirstAccount())
testutil.LogNoErr(t, err, data)
}

func TestListSignGame(t *testing.T) {
actId, _, _ := GetSR(t)
data, err := ListSignGame(actId, config.C().FirstAccount())
gameName, actId, _, _ := GetSR(t)
data, err := ListSignGame(gameName, actId, config.C().FirstAccount())
testutil.LogNoErr(t, err, data)
}

func TestListSignGameAward(t *testing.T) {
actId, region, uid := GetSR(t)
data, err := ListSignGameAward(actId, region, uid, config.C().FirstAccount())
gameName, actId, region, uid := GetSR(t)
data, err := ListSignGameAward(gameName, actId, region, uid, config.C().FirstAccount())
testutil.LogNoErr(t, err, data, len(data), data.Today(), data.Today().ShortString())
}
9 changes: 6 additions & 3 deletions job/game.go
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@ import (
)

var SignGameIdByBiz = map[string]string{
common.GameBizYSCN: common.GameIdYS,
common.GameBizSRCN: common.GameIdSR,
}

Expand Down Expand Up @@ -91,6 +92,8 @@ func SignGameRole(role *miyoushe.GameRole, account config.Account) (record SignG
record.GameId = gameId
record.GameName = game.Name

gameName := strings.Split(role.GameBiz, "_")[0]

home, err := miyoushe.GetHome(gameId)
if err != nil {
err = fmt.Errorf("get home error: %w", err)
Expand All @@ -103,7 +106,7 @@ func SignGameRole(role *miyoushe.GameRole, account config.Account) (record SignG
return
}

today, err := miyoushe.GetSignGame(actId, role.Region, role.GameUid, account)
today, err := miyoushe.GetSignGame(gameName, actId, role.Region, role.GameUid, account)
if err != nil {
err = fmt.Errorf("get sign game error: %w", err)
return
Expand All @@ -121,7 +124,7 @@ func SignGameRole(role *miyoushe.GameRole, account config.Account) (record SignG

sign:

signGameData, err = miyoushe.SignGame(actId, role.Region, role.GameUid, account, verification)
signGameData, err = miyoushe.SignGame(gameName, actId, role.Region, role.GameUid, account, verification)
if err != nil {
if common.IsRetCode(err, common.RetCodeGameHasSigned) {
record.HasSigned = true
Expand All @@ -147,7 +150,7 @@ sign:

award:

award, err := miyoushe.ListSignGameAward(actId, role.Region, role.GameUid, account)
award, err := miyoushe.ListSignGameAward(gameName, actId, role.Region, role.GameUid, account)
if err != nil {
err = fmt.Errorf("list sign game award error: %w", err)
return
Expand Down
4 changes: 2 additions & 2 deletions job/game_test.go
Original file line number Diff line number Diff line change
Expand Up @@ -15,15 +15,15 @@ func TestSignGameRecords_Success(t *testing.T) {
GameId: common.GameIdYS,
RoleName: "游戏昵称1",
RoleUid: "123456789",
HasSigned: false,
HasSigned: true,
IsRisky: true,
Award: "A*5, B*5",
},
{
GameId: common.GameIdSR,
RoleName: "游戏昵称2",
RoleUid: "123456789",
HasSigned: false,
HasSigned: true,
IsRisky: false,
Award: "ABC*500",
},
Expand Down

0 comments on commit 930c65e

Please sign in to comment.