-
Notifications
You must be signed in to change notification settings - Fork 85
Create ali_ecc_golang.go #2
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Open
msterzhang
wants to merge
1
commit into
kazutoiris:main
Choose a base branch
from
msterzhang:main
base: main
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Changes from all commits
Commits
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains hidden or 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,127 @@ | ||
| package main | ||
|
|
||
| import ( | ||
| "bytes" | ||
| "encoding/hex" | ||
| "errors" | ||
| "fmt" | ||
| "io/ioutil" | ||
| "log" | ||
| "math/rand" | ||
| "net/http" | ||
| "strings" | ||
| "time" | ||
|
|
||
| "github.com/tendermint/tendermint/crypto/secp256k1" | ||
| ) | ||
|
|
||
| var ( | ||
| appId = "25dzX3vbYqktVxyX" | ||
| deviceId = "URJuHA0FgRACAW8eGUh/zJ+2" | ||
| userId = "31a1407588d94e47961094xxxxxxxxx" | ||
| nonce = 0 | ||
| publicKey = "" | ||
| signatureData = "" | ||
| ) | ||
|
|
||
| func randomString(l int) []byte { | ||
| bytes := make([]byte, l) | ||
| for i := 0; i < l; i++ { | ||
| rand.NewSource(time.Now().UnixNano()) | ||
| bytes[i] = byte(randInt(1, 2^256-1)) | ||
| } | ||
| return bytes | ||
| } | ||
|
|
||
| func randInt(min int, max int) int { | ||
| return min + rand.Intn(max-min) | ||
| } | ||
|
|
||
| func AddHeader(req *http.Request) *http.Request { | ||
| req.Header.Set("authorization", "Bearer xxxxxxxxxxxxxxx") | ||
| req.Header.Add("content-type", "application/json") | ||
| req.Header.Add("user-agent", "Mozilla/5.0 (Windows NT 10.0; Win64; x64) AppleWebKit/537.36 (KHTML, like Gecko) Chrome/87.0.4280.88 Safari/537.36") | ||
| req.Header.Add("origin", "https://aliyundrive.com") | ||
| req.Header.Add("accept", "*/*") | ||
| req.Header.Add("Accept-Language", "zh-CN,zh;q=0.8,en-US;q=0.5,en;q=0.3") | ||
| req.Header.Add("x-canary", "client=web,app=adrive,version=v3.17.0") | ||
| req.Header.Add("x-device-id", deviceId) | ||
| req.Header.Add("x-signature", signatureData) | ||
| return req | ||
| } | ||
|
|
||
| func CreateSession() error { | ||
| api := "https://api.aliyundrive.com/users/v1/users/device/create_session" | ||
| form := fmt.Sprintf(`{"deviceName": "Edge浏览器","modelName": "Windows网页版","pubKey":"%s"}`, publicKey) | ||
| req, err := http.NewRequest("POST", api, bytes.NewBufferString(form)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
| req = AddHeader(req) | ||
| resp, err := http.DefaultClient.Do(req) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer resp.Body.Close() | ||
| body, err := ioutil.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if strings.Contains(string(body), "true") { | ||
| return nil | ||
| } | ||
| return errors.New(string(body)) | ||
| } | ||
|
|
||
| func AliDownload(fileId string) error { | ||
| api := "https://api.aliyundrive.com/v2/file/get_download_url" | ||
| form := fmt.Sprintf(`{"expire_sec": 14400, "drive_id": "409666480","file_id": "636767a8287a5f3ae94b4bd480bf0e56dc294029"}`) | ||
| req, err := http.NewRequest("POST", api, bytes.NewBufferString(form)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| req.Header.Set("Content-Type", "application/json; charset=utf-8") | ||
| req = AddHeader(req) | ||
| resp, err := http.DefaultClient.Do(req) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| defer resp.Body.Close() | ||
| body, err := ioutil.ReadAll(resp.Body) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| if strings.Contains(string(body), "url") { | ||
| log.Println(string(body)) | ||
| return nil | ||
| } | ||
| return errors.New(string(body)) | ||
| } | ||
|
|
||
| func InitAliKey() error { | ||
| max := 32 | ||
| key := randomString(max) | ||
| data := fmt.Sprintf("%s:%s:%s:%d", appId, deviceId, userId, nonce) | ||
| var privKey = secp256k1.PrivKey(key) | ||
| pubKey := privKey.PubKey() | ||
| publicKey = "04" + hex.EncodeToString(pubKey.Bytes()) | ||
| signature, err := privKey.Sign([]byte(data)) | ||
| if err != nil { | ||
| return err | ||
| } | ||
| signatureData = hex.EncodeToString(signature) + "01" | ||
| return nil | ||
| } | ||
|
|
||
| func main() { | ||
| err := InitAliKey() | ||
| if err != nil { | ||
| log.Println(err) | ||
| } | ||
| err = CreateSession() | ||
| if err != nil { | ||
| log.Println(err) | ||
| } | ||
| AliDownload("") | ||
| } | ||
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
Uh oh!
There was an error while loading. Please reload this page.