From 9c978352a49d8575a6266d5706ddccc0f5887ec5 Mon Sep 17 00:00:00 2001 From: qydysky Date: Wed, 10 May 2023 02:52:58 +0800 Subject: [PATCH] =?utf8?q?Improve=20=E9=80=81=E7=A4=BCapi=E6=9B=B4?= =?utf8?q?=E6=96=B0?= MIME-Version: 1.0 Content-Type: text/plain; charset=utf8 Content-Transfer-Encoding: 8bit --- Json/sendBag.go | 82 +++++++++++++++++++++++++++++++++++++++++++++++ Send/Send_gift.go | 16 ++++----- 2 files changed, 88 insertions(+), 10 deletions(-) create mode 100644 Json/sendBag.go diff --git a/Json/sendBag.go b/Json/sendBag.go new file mode 100644 index 0000000..c09f8c4 --- /dev/null +++ b/Json/sendBag.go @@ -0,0 +1,82 @@ +package part + +type SendBag struct { + Code int `json:"code"` + Message string `json:"message"` + TTL int `json:"ttl"` + Data struct { + UID int `json:"uid"` + Uname string `json:"uname"` + Face string `json:"face"` + GuardLevel int `json:"guard_level"` + Ruid int `json:"ruid"` + RoomID int `json:"room_id"` + Rcost int `json:"rcost"` + TotalCoin int `json:"total_coin"` + PayCoin int `json:"pay_coin"` + BlowSwitch int `json:"blow_switch"` + SendTips string `json:"send_tips"` + DiscountID int `json:"discount_id"` + SendMaster any `json:"send_master"` + ButtonComboType int `json:"button_combo_type"` + SendGiftCountdown int `json:"send_gift_countdown"` + BlindGift any `json:"blind_gift"` + Fulltext string `json:"fulltext"` + CritProb int `json:"crit_prob"` + Price int `json:"price"` + LeftNum int `json:"left_num"` + NeedNum int `json:"need_num"` + AvailableNum int `json:"available_num"` + BpCentBalance int `json:"bp_cent_balance"` + GiftList []struct { + Tid string `json:"tid"` + GiftID int `json:"gift_id"` + GiftType int `json:"gift_type"` + GiftName string `json:"gift_name"` + GiftNum int `json:"gift_num"` + GiftAction string `json:"gift_action"` + GiftPrice int `json:"gift_price"` + CoinType string `json:"coin_type"` + TagImage string `json:"tag_image"` + EffectBlock int `json:"effect_block"` + Extra struct { + Wallet any `json:"wallet"` + GiftBag struct { + BagID int `json:"bag_id"` + GiftNum int `json:"gift_num"` + } `json:"gift_bag"` + Pk struct { + PkGiftTips string `json:"pk_gift_tips"` + } `json:"pk"` + LotteryID string `json:"lottery_id"` + Medal struct { + New int `json:"new"` + MedalID int `json:"medal_id"` + MedalName string `json:"medal_name"` + Level int `json:"level"` + } `json:"medal"` + } `json:"extra"` + GiftEffect struct { + ComboTimeout int `json:"combo_timeout"` + SuperGiftNum int `json:"super_gift_num"` + SuperBatchGiftNum int `json:"super_batch_gift_num"` + BatchComboID string `json:"batch_combo_id"` + ComboID string `json:"combo_id"` + } `json:"gift_effect"` + IsSpecialBatch int `json:"is_special_batch"` + ComboStayTime int `json:"combo_stay_time"` + ComboTotalCoin int `json:"combo_total_coin"` + Demarcation int `json:"demarcation"` + Magnification int `json:"magnification"` + ComboResourcesID int `json:"combo_resources_id"` + FloatScResourceID int `json:"float_sc_resource_id"` + IsNaming bool `json:"is_naming"` + ReceiveUserInfo struct { + Uname string `json:"uname"` + UID int `json:"uid"` + } `json:"receive_user_info"` + IsJoinReceiver bool `json:"is_join_receiver"` + } `json:"gift_list"` + SendID string `json:"send_id"` + } `json:"data"` +} diff --git a/Send/Send_gift.go b/Send/Send_gift.go index ec9d16a..8e18274 100644 --- a/Send/Send_gift.go +++ b/Send/Send_gift.go @@ -7,6 +7,7 @@ import ( "time" c "github.com/qydysky/bili_danmu/CV" + J "github.com/qydysky/bili_danmu/Json" limit "github.com/qydysky/part/limit" reqf "github.com/qydysky/part/reqf" @@ -61,7 +62,7 @@ func Send_gift(gift_id, bag_id, gift_num int) { req := c.C.ReqPool.Get() defer c.C.ReqPool.Put(req) if e := req.Reqf(reqf.Rval{ - Url: `https://api.live.bilibili.com/gift/v2/live/bag_send`, + Url: `https://api.live.bilibili.com/xlive/revenue/v2/gift/sendBag`, PostStr: url.PathEscape(sendStr), Timeout: 10 * 1000, Proxy: c.C.Proxy, @@ -84,14 +85,7 @@ func Send_gift(gift_id, bag_id, gift_num int) { return } - var res struct { - Code int `json:"code"` - Message string `json:"message"` - Data struct { - Gift_name string `json:"gift_name"` - Gift_num int `json:"gift_num"` - } `json:"data"` - } + var res J.SendBag if e := json.Unmarshal(req.Respon, &res); e != nil { log.L(`E: `, e) @@ -102,6 +96,8 @@ func Send_gift(gift_id, bag_id, gift_num int) { log.L(`W: `, res.Message) return } - log.L(`I: `, `给`, c.C.Roomid, `赠送了`, res.Data.Gift_num, `个`, res.Data.Gift_name) + for i := 0; i < len(res.Data.GiftList); i++ { + log.L(`I: `, `给`, c.C.Roomid, `赠送了`, res.Data.GiftList[i].GiftNum, `个`, res.Data.GiftList[i].GiftName) + } } } -- 2.39.2