-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
8 changed files
with
295 additions
and
19 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,152 @@ | ||
package app | ||
|
||
import ( | ||
"encoding/base64" | ||
"fmt" | ||
"github.com/go-resty/resty/v2" | ||
"github.com/google/uuid" | ||
"log" | ||
"math" | ||
"strconv" | ||
"strings" | ||
"unicode" | ||
) | ||
|
||
// GenerateFakeBuvid | ||
// | ||
// @Description: 伪造设备标识码 | ||
// @return string buvid | ||
func (d *Device) GenerateFakeBuvid() { | ||
randomText := strings.ReplaceAll(uuid.New().String(), "-", "") | ||
for len(randomText) < 35 { | ||
randomText += strings.ReplaceAll(uuid.New().String(), "-", "") | ||
} | ||
fakeBuvid := "XY" + randomText[:35] | ||
d.BilibiliBuvid = fakeBuvid | ||
} | ||
|
||
// GetVersions | ||
// | ||
// @Description: 获取最新版本的 build 和 version | ||
// @param mod 传参, 若为空则传入 "android" | ||
// @return string build | ||
// @return string version | ||
// @return error 错误处理 | ||
func (d *Device) GetVersions(mod string) error { | ||
if mod == "" { | ||
mod = MobiApp | ||
} | ||
client := resty.New() | ||
resp, err := client.R(). | ||
SetResult(&AppVersionResponse{}). | ||
SetQueryParam("mobi_app", mod). | ||
Get("https://app.bilibili.com/x/v2/version") | ||
if err != nil { | ||
return err | ||
} | ||
result := resp.Result().(*AppVersionResponse) | ||
if len(result.Data) > 0 { | ||
d.VersionCode = fmt.Sprintf("%d", result.Data[0].Build) | ||
d.VersionName = result.Data[0].Version | ||
return nil | ||
} | ||
|
||
return fmt.Errorf("no data found") | ||
} | ||
|
||
// GetSdkInt | ||
// | ||
// @Description: 根据安卓系统版本获取 SDK 版本 | ||
// @param AndroidVersion 安卓系统版本 | ||
// @return string sdk版本 | ||
// @return error 错误处理 | ||
func (d *Device) GetSdkInt() string { | ||
AndroidVersion := d.AndroidBuild | ||
buildList := strings.Split(AndroidVersion, ".") | ||
var sdkInt string | ||
data := SystemSdkIntMap | ||
for _, li := range buildList { | ||
value, ok := data[li] | ||
if !ok { | ||
if sdkInt != "" { | ||
return sdkInt | ||
} | ||
log.Println("未找到" + AndroidVersion + "的sdk_int") | ||
return "" | ||
} | ||
sdkInt = value["value"].(string) | ||
data = map[string]map[string]interface{}{ | ||
li: value, | ||
} | ||
} | ||
return sdkInt | ||
} | ||
|
||
// BuildXBiliAuroraEID | ||
// | ||
// @Description: 生成 x-bili-aurora-eid | ||
// @param mid 用户 uid | ||
// @return string x-bili-aurora-eid | ||
func BuildXBiliAuroraEID(mid string) string { | ||
length := len(mid) | ||
byteArr := make([]byte, length) | ||
|
||
if length-1 < 0 { | ||
return "" | ||
} | ||
|
||
for i := 0; i < length; i++ { | ||
s := unicode.ToLower(rune("ad1va46a7lza"[i%12])) | ||
byteArr[i] = byte(mid[i]) ^ byte(s) | ||
} | ||
|
||
return base64.StdEncoding.EncodeToString(byteArr) | ||
} | ||
|
||
// BuildXBiliTraceID | ||
// | ||
// @Description: 生成 x-bili-trace-id | ||
// @param timeStamp | ||
// @return string | ||
func BuildXBiliTraceID(timeStamp int64) string { | ||
back6 := strconv.FormatInt(int64(math.Round(float64(timeStamp)/256)), 16) | ||
front := strings.ReplaceAll(uuid.New().String(), "-", "") | ||
_data1 := front[6:] + back6[2:] | ||
_data2 := front[22:] + back6[2:] | ||
|
||
return fmt.Sprintf("%v:%v:0:0", _data1, _data2) | ||
} | ||
|
||
// BuildSessionID | ||
// | ||
// @Description: 构造随机 Session ID | ||
// @return string SessionID | ||
func BuildSessionID() string { | ||
return strings.ReplaceAll(uuid.New().String(), "-", "")[:8] | ||
} | ||
|
||
// BuildUserAgent | ||
// | ||
// @Description: 构造User-Agent | ||
// @param device 设备信息 | ||
func (d *Device) BuildUserAgent() string { | ||
varMap := map[string]string{ | ||
"ANDROID_BUILD": d.AndroidBuild, | ||
"ANDROID_MODEL": d.AndroidModel, | ||
"ANDROID_BUILD_M": BuildM, | ||
"BUVID": d.BilibiliBuvid, | ||
"SDK_INT": d.GetSdkInt(), | ||
"VERSION_CODE": d.VersionCode, | ||
"CHANNEL": Channel, | ||
"SESSION_ID": BuildSessionID(), | ||
"VERSION_NAME": d.VersionName, | ||
} | ||
// 定义待替换的字符串模板 | ||
strTemplate := UserAgentFormat | ||
// 执行替换 | ||
for k, v := range varMap { | ||
strTemplate = strings.ReplaceAll(strTemplate, "{"+k+"}", v) | ||
} | ||
|
||
return strTemplate | ||
} |
This file was deleted.
Oops, something went wrong.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,18 @@ | ||
package app | ||
|
||
type AppVersionResponse struct { | ||
Data []AppVersionData `json:"data"` | ||
} | ||
|
||
type AppVersionData struct { | ||
Build int `json:"build"` | ||
Version string `json:"version"` | ||
} | ||
|
||
type Device struct { | ||
BilibiliBuvid string `json:"BilibiliBuvid"` | ||
AndroidModel string `json:"AndroidModel"` | ||
AndroidBuild string `json:"AndroidBuild"` | ||
VersionName string `json:"VersionName"` | ||
VersionCode string `json:"VersionCode"` | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,60 @@ | ||
package app | ||
|
||
var SystemSdkIntMap = map[string]map[string]interface{}{ | ||
"13": { | ||
"value": "33", | ||
}, | ||
"12": { | ||
"value": "32", | ||
}, | ||
"11": { | ||
"value": "30", | ||
}, | ||
"10": { | ||
"value": "29", | ||
}, | ||
"9": { | ||
"value": "28", | ||
}, | ||
"8": { | ||
"value": "26", | ||
"1": map[string]string{ | ||
"value": "27", | ||
}, | ||
}, | ||
"7": { | ||
"value": "24", | ||
"1": map[string]string{ | ||
"value": "25", | ||
}, | ||
}, | ||
"6": { | ||
"value": "23", | ||
}, | ||
"5": { | ||
"value": "21", | ||
"1": map[string]string{ | ||
"value": "22", | ||
}, | ||
}, | ||
"4": { | ||
"value": "14", | ||
"1": map[string]string{ | ||
"value": "16", | ||
}, | ||
"2": map[string]string{ | ||
"value": "17", | ||
}, | ||
"3": map[string]string{ | ||
"value": "18", | ||
}, | ||
"4": map[string]string{ | ||
"value": "19", | ||
}, | ||
}, | ||
} | ||
var ( | ||
UserAgentFormat = "Mozilla/5.0 (Linux; Android {ANDROID_BUILD}; {ANDROID_MODEL} Build/{ANDROID_BUILD_M}; wv) AppleWebKit/537.36 (KHTML, like Gecko) Version/4.0 Chrome/92.0.4515.131 Mobile Safari/537.36 os/android model/{ANDROID_MODEL} build/{VERSION_CODE} osVer/{ANDROID_BUILD} sdkInt/{SDK_INT} network/2 BiliApp/{VERSION_CODE} mobi_app/android channel/{CHANNEL} Buvid/{BUVID} sessionID/{SESSION_ID} innerVer/{VERSION_CODE} c_locale/zh_CN s_locale/zh_CN disable_rcmd/0 {VERSION_NAME} os/android model/{ANDROID_MODEL} mobi_app/android build/{VERSION_CODE} channel/{CHANNEL} innerVer/{VERSION_CODE} osVer/{ANDROID_BUILD} network/2" | ||
BuildM = "NRD90M.G955NKSU1AQDC" | ||
Channel = "yingyongbao" | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -1,3 +1,9 @@ | ||
module github.com/boxie123/BilibiliAuthorize | ||
|
||
go 1.20 | ||
|
||
require ( | ||
github.com/go-resty/resty/v2 v2.11.0 // indirect | ||
github.com/google/uuid v1.5.0 // indirect | ||
golang.org/x/net v0.17.0 // indirect | ||
) |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,45 @@ | ||
github.com/go-resty/resty/v2 v2.11.0 h1:i7jMfNOJYMp69lq7qozJP+bjgzfAzeOhuGlyDrqxT/8= | ||
github.com/go-resty/resty/v2 v2.11.0/go.mod h1:iiP/OpA0CkcL3IGt1O0+/SIItFUbkkyw5BGXiVdTu+A= | ||
github.com/google/uuid v1.5.0 h1:1p67kYwdtXjb0gL0BPiP1Av9wiZPo5A8z2cWkTZ+eyU= | ||
github.com/google/uuid v1.5.0/go.mod h1:TIyPZe4MgqvfeYDBFedMoGGpEw/LqOeaOT+nhxU+yHo= | ||
github.com/yuin/goldmark v1.4.13/go.mod h1:6yULJ656Px+3vBD8DxQVa3kxgyrAnzto9xy5taEt/CY= | ||
golang.org/x/crypto v0.0.0-20190308221718-c2843e01d9a2/go.mod h1:djNgcEr1/C05ACkg1iLfiJU5Ep61QUkGW8qpdssI0+w= | ||
golang.org/x/crypto v0.0.0-20210921155107-089bfa567519/go.mod h1:GvvjBRRGRdwPK5ydBHafDWAxML/pGHZbMvKqRZ5+Abc= | ||
golang.org/x/crypto v0.14.0/go.mod h1:MVFd36DqK4CsrnJYDkBA3VC4m2GkXAM0PvzMCn4JQf4= | ||
golang.org/x/mod v0.6.0-dev.0.20220419223038-86c51ed26bb4/go.mod h1:jJ57K6gSWd91VN4djpZkiMVwK6gcyfeH4XE8wZrZaV4= | ||
golang.org/x/mod v0.8.0/go.mod h1:iBbtSCu2XBx23ZKBPSOrRkjjQPZFPuis4dIYUhu/chs= | ||
golang.org/x/net v0.0.0-20190620200207-3b0461eec859/go.mod h1:z5CRVTTTmAJ677TzLLGU+0bjPO0LkuOLi4/5GtJWs/s= | ||
golang.org/x/net v0.0.0-20210226172049-e18ecbb05110/go.mod h1:m0MpNAwzfU5UDzcl9v0D8zg8gWTRqZa9RBIspLL5mdg= | ||
golang.org/x/net v0.0.0-20220722155237-a158d28d115b/go.mod h1:XRhObCWvk6IyKnWLug+ECip1KBveYUHfp+8e9klMJ9c= | ||
golang.org/x/net v0.6.0/go.mod h1:2Tu9+aMcznHK/AK1HMvgo6xiTLG5rD5rZLDS+rp2Bjs= | ||
golang.org/x/net v0.10.0/go.mod h1:0qNGK6F8kojg2nk9dLZ2mShWaEBan6FAoqfSigmmuDg= | ||
golang.org/x/net v0.17.0 h1:pVaXccu2ozPjCXewfr1S7xza/zcXTity9cCdXQYSjIM= | ||
golang.org/x/net v0.17.0/go.mod h1:NxSsAGuq816PNPmqtQdLE42eU2Fs7NoRIZrHJAlaCOE= | ||
golang.org/x/sync v0.0.0-20190423024810-112230192c58/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sync v0.0.0-20220722155255-886fb9371eb4/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sync v0.1.0/go.mod h1:RxMgew5VJxzue5/jJTE5uejpjVlOe/izrB70Jof72aM= | ||
golang.org/x/sys v0.0.0-20190215142949-d0b11bdaac8a/go.mod h1:STP8DvDyc/dI5b8T5hshtkjS+E42TnysNCUPdjciGhY= | ||
golang.org/x/sys v0.0.0-20201119102817-f84b799fce68/go.mod h1:h1NjWce9XRLGQEsW7wpKNCjG9DtNlClVuFLEZdDNbEs= | ||
golang.org/x/sys v0.0.0-20210615035016-665e8c7367d1/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220520151302-bc2c85ada10a/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.0.0-20220722155257-8c9f86f7a55f/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.5.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.8.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/sys v0.13.0/go.mod h1:oPkhp1MJrh7nUepCBck5+mAzfO9JrbApNNgaTdGDITg= | ||
golang.org/x/term v0.0.0-20201126162022-7de9c90e9dd1/go.mod h1:bj7SfCRtBDWHUb9snDiAeCFNEtKQo2Wmx5Cou7ajbmo= | ||
golang.org/x/term v0.0.0-20210927222741-03fcf44c2211/go.mod h1:jbD1KX2456YbFQfuXm/mYQcufACuNUgVhRMnK/tPxf8= | ||
golang.org/x/term v0.5.0/go.mod h1:jMB1sMXY+tzblOD4FWmEbocvup2/aLOaQEp7JmGp78k= | ||
golang.org/x/term v0.8.0/go.mod h1:xPskH00ivmX89bAKVGSKKtLOWNx2+17Eiy94tnKShWo= | ||
golang.org/x/term v0.13.0/go.mod h1:LTmsnFJwVN6bCy1rVCoS+qHT1HhALEFxKncY3WNNh4U= | ||
golang.org/x/text v0.3.0/go.mod h1:NqM8EUOU14njkJ3fqMW+pc6Ldnwhi/IjpwHt7yyuwOQ= | ||
golang.org/x/text v0.3.3/go.mod h1:5Zoc/QRtKVWzQhOtBMvqHzDpF6irO9z98xDceosuGiQ= | ||
golang.org/x/text v0.3.7/go.mod h1:u+2+/6zg+i71rQMx5EYifcz6MCKuco9NR6JIITiCfzQ= | ||
golang.org/x/text v0.7.0/go.mod h1:mrYo+phRRbMaCq/xk9113O4dZlRixOauAjOtrjsXDZ8= | ||
golang.org/x/text v0.9.0/go.mod h1:e1OnstbJyHTd6l/uOt8jFFHp6TRDWZR/bV3emEE/zU8= | ||
golang.org/x/text v0.13.0/go.mod h1:TvPlkZtksWOMsz7fbANvkp4WM8x/WCo/om8BMLbz+aE= | ||
golang.org/x/time v0.3.0/go.mod h1:tRJNPiyCQ0inRvYxbN9jk5I+vvW/OXSQhTDSoE431IQ= | ||
golang.org/x/tools v0.0.0-20180917221912-90fa682c2a6e/go.mod h1:n7NCudcB/nEzxVGmLbDWY5pfWTLqBcC2KZ6jyYvM4mQ= | ||
golang.org/x/tools v0.0.0-20191119224855-298f0cb1881e/go.mod h1:b+2E5dAYhXwXZwtnZ6UAqBI28+e2cm9otk0dWdXHAEo= | ||
golang.org/x/tools v0.1.12/go.mod h1:hNGJHUnrk76NpqgfD5Aqm5Crs+Hm0VOH/i9J2+nxYbc= | ||
golang.org/x/tools v0.6.0/go.mod h1:Xwgl3UAJ/d3gWutnCtw505GrjyAbvKui8lOU390QaIU= | ||
golang.org/x/xerrors v0.0.0-20190717185122-a985d3407aa7/go.mod h1:I/5z698sn9Ka8TeJc9MKroUUfqBBauWjQqLJ2OPfmY0= |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters