fix(123): Use APP-side API (close #4834 in #4856)

pull/4860/head
Bnq Dzj 2023-07-27 15:51:59 +08:00 committed by GitHub
parent f2ca9b40db
commit 4afa822bec
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 29 additions and 30 deletions

View File

@ -1,14 +1,10 @@
package _123 package _123
import ( import (
"crypto/md5"
"errors" "errors"
"fmt" "fmt"
"math/rand"
"net/http" "net/http"
"net/url"
"strconv" "strconv"
"time"
"github.com/alist-org/alist/v3/drivers/base" "github.com/alist-org/alist/v3/drivers/base"
"github.com/alist-org/alist/v3/pkg/utils" "github.com/alist-org/alist/v3/pkg/utils"
@ -19,9 +15,10 @@ import (
// do others that not defined in Driver interface // do others that not defined in Driver interface
const ( const (
Api = "https://www.123pan.com/api"
AApi = "https://www.123pan.com/a/api" AApi = "https://www.123pan.com/a/api"
BApi = "https://www.123pan.com/b/api" BApi = "https://www.123pan.com/b/api"
MainApi = BApi MainApi = Api
SignIn = MainApi + "/user/sign_in" SignIn = MainApi + "/user/sign_in"
Logout = MainApi + "/user/logout" Logout = MainApi + "/user/logout"
UserInfo = MainApi + "/user/info" UserInfo = MainApi + "/user/info"
@ -37,7 +34,7 @@ const (
S3Auth = MainApi + "/file/s3_upload_object/auth" S3Auth = MainApi + "/file/s3_upload_object/auth"
UploadCompleteV2 = MainApi + "/file/upload_complete/v2" UploadCompleteV2 = MainApi + "/file/upload_complete/v2"
S3Complete = MainApi + "/file/s3_complete_multipart_upload" S3Complete = MainApi + "/file/s3_complete_multipart_upload"
AuthKeySalt = "8-8D$sL8gPjom7bk#cY" //AuthKeySalt = "8-8D$sL8gPjom7bk#cY"
) )
func (d *Pan123) login() error { func (d *Pan123) login() error {
@ -59,9 +56,10 @@ func (d *Pan123) login() error {
SetHeaders(map[string]string{ SetHeaders(map[string]string{
"origin": "https://www.123pan.com", "origin": "https://www.123pan.com",
"referer": "https://www.123pan.com/", "referer": "https://www.123pan.com/",
"platform": "web", "user-agent": "Dart/2.19(dart:io)",
"app-version": "3", "platform": "android",
"user-agent": base.UserAgent, "app-version": "36",
//"user-agent": base.UserAgent,
}). }).
SetBody(body).Post(SignIn) SetBody(body).Post(SignIn)
if err != nil { if err != nil {
@ -75,19 +73,19 @@ func (d *Pan123) login() error {
return err return err
} }
func authKey(reqUrl string) (*string, error) { //func authKey(reqUrl string) (*string, error) {
reqURL, err := url.Parse(reqUrl) // reqURL, err := url.Parse(reqUrl)
if err != nil { // if err != nil {
return nil, err // return nil, err
} // }
//
nowUnix := time.Now().Unix() // nowUnix := time.Now().Unix()
random := rand.Intn(0x989680) // random := rand.Intn(0x989680)
//
p4 := fmt.Sprintf("%d|%d|%s|%s|%s|%s", nowUnix, random, reqURL.Path, "web", "3", AuthKeySalt) // p4 := fmt.Sprintf("%d|%d|%s|%s|%s|%s", nowUnix, random, reqURL.Path, "web", "3", AuthKeySalt)
authKey := fmt.Sprintf("%d-%d-%x", nowUnix, random, md5.Sum([]byte(p4))) // authKey := fmt.Sprintf("%d-%d-%x", nowUnix, random, md5.Sum([]byte(p4)))
return &authKey, nil // return &authKey, nil
} //}
func (d *Pan123) request(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) { func (d *Pan123) request(url string, method string, callback base.ReqCallback, resp interface{}) ([]byte, error) {
req := base.RestyClient.R() req := base.RestyClient.R()
@ -95,9 +93,10 @@ func (d *Pan123) request(url string, method string, callback base.ReqCallback, r
"origin": "https://www.123pan.com", "origin": "https://www.123pan.com",
"referer": "https://www.123pan.com/", "referer": "https://www.123pan.com/",
"authorization": "Bearer " + d.AccessToken, "authorization": "Bearer " + d.AccessToken,
"platform": "web", "user-agent": "Dart/2.19(dart:io)",
"app-version": "3", "platform": "android",
"user-agent": base.UserAgent, "app-version": "36",
//"user-agent": base.UserAgent,
}) })
if callback != nil { if callback != nil {
callback(req) callback(req)
@ -105,11 +104,11 @@ func (d *Pan123) request(url string, method string, callback base.ReqCallback, r
if resp != nil { if resp != nil {
req.SetResult(resp) req.SetResult(resp)
} }
authKey, err := authKey(url) //authKey, err := authKey(url)
if err != nil { //if err != nil {
return nil, err // return nil, err
} //}
req.SetQueryParam("auth-key", *authKey) //req.SetQueryParam("auth-key", *authKey)
res, err := req.Execute(method, url) res, err := req.Execute(method, url)
if err != nil { if err != nil {
return nil, err return nil, err