weiyunsdkgo

package module
v0.1.3 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Oct 31, 2023 License: Apache-2.0 Imports: 22 Imported by: 1

README

weiyun-sdk-go

weiyun SDK for the Go programming language

Installation

go get github.com/foxxorcat/weiyun-sdk-go

Usage

package main

import (
	"context"
	"fmt"
	"os"

	weiyunsdkgo "github.com/foxxorcat/weiyun-sdk-go"
)

func main() {
	client := weiyunsdkgo.NewWeiYunClient()
	_, err := client.QQQRLogin(context.TODO(), func(b []byte) error {
		os.WriteFile("qr.png", b, 0777)
		return nil
	})
	if err != nil {
		fmt.Println(err)
	}
	// client.SetCookiesStr("cookies")
	// client.QQFastLogin(context.Background(), "qq number")
	userInfo, err := client.DiskUserInfoGet()
	if err != nil {
		fmt.Println(err)
	}
	fmt.Println(userInfo)
}

Documentation

Index

Constants

View Source
const (
	FileAndDir = iota
	OnlyDir
	OnlyFile
)

Variables

View Source
var (
	ErrCode403 = errors.New("http code 403")

	ErrTokenExpiration  = errors.New("token expiration")
	ErrTokenIsNil       = errors.New("token is nil")
	ErrCookieExpiration = errors.New("the login cookie is invalid, please login in again")
)

Functions

func ClearCookie

func ClearCookie(cookies []*http.Cookie) []*http.Cookie

func CookieToString

func CookieToString(cookies []*http.Cookie) string

func GetCookieValue

func GetCookieValue(name string, cks []*http.Cookie) string

func GetDirFileIDFormUrl

func GetDirFileIDFormUrl(url string) string

func GetHash33

func GetHash33(d string) string

func GetSha1State

func GetSha1State(h hash.Hash) []byte

func MustJsonMarshalToString

func MustJsonMarshalToString(v any) string

func MustSliceConvert

func MustSliceConvert[S any, D any](srcS []S, convert func(src S) D) []D

func ParseCookieStr

func ParseCookieStr(str string) []*http.Cookie

func RandomT

func RandomT() string

func SetCookieValue

func SetCookieValue(name string, value string, cks []*http.Cookie)

func SliceContains

func SliceContains[T comparable](arrs []T, v T, contains func(arr, v T) bool) bool

* Slice *

func SliceConvert

func SliceConvert[S any, D any](srcS []S, convert func(src S) (D, error)) ([]D, error)

SliceConvert convert slice to another type slice

Types

type AddChannelData

type AddChannelData struct {
	// 源通道数量
	OrigChannelCount int `json:"orig_channel_count"`
	// 当前通道数量
	FinalChannelCount int `json:"final_channel_count"`

	// 源通道信息
	OrigChannels []UploadChannelData `json:"orig_channels"`
	// 增加通道信息
	AddChannels []UploadChannelData `json:"channels"`
}

type DiskDirFileBatchListParam

type DiskDirFileBatchListParam struct {
	DirKey      string
	ParamOption []ParamOption
}

type DiskFileDownloadData

type DiskFileDownloadData struct {
	Retcode int    `json:"retcode"`
	Retmsg  string `json:"retmsg"`

	CookieName  string `json:"cookie_name"`
	CookieValue string `json:"cookie_value"`

	DownloadUrl string `json:"download_url"`
}

type DiskFilePackageDownloadParam

type DiskFilePackageDownloadParam struct {
	PdirKey  string `json:"pdir_key"`
	PdirList any    `json:"pdir_list"`
}

type DiskListData

type DiskListData struct {
	DirList        []Folder `json:"dir_list"`
	FileList       []File   `json:"file_list"`
	PdirKey        string   `json:"pdir_key"`
	FinishFlag     bool     `json:"finish_flag"`
	TotalDirCount  int64    `json:"total_dir_count"`
	TotalFileCount int64    `json:"total_file_count"`
	TotalSpace     int64    `json:"total_space"`
	HideDirCount   int64    `json:"hide_dir_count"`
	HideFileCount  int64    `json:"hide_file_count"`
}

type DiskUserInfoGetData

type DiskUserInfoGetData struct {
	Uin        int64     `json:"uin"`
	NickName   string    `json:"nick_name"`
	HeadImgUrl string    `json:"head_img_url"`
	UserCtime  TimeStamp `json:"user_ctime"`
	UserMtime  TimeStamp `json:"user_mtime"`

	UsedSpace  int64 `json:"used_space"`
	TotalSpace int64 `json:"total_space"`

	DirTotal  int64 `json:"dir_total"`
	FileTotal int64 `json:"file_total"`

	RootDirKey string `json:"root_dir_key"`
	MainDirKey string `json:"main_dir_key"`
}

type File

type File struct {
	FileID    string    `json:"file_id"`
	FileName  string    `json:"filename"`
	FileSize  int64     `json:"file_size"`
	FileSha   string    `json:"file_sha"`
	FileCtime TimeStamp `json:"file_ctime"`
	FileMtime TimeStamp `json:"file_mtime"`

	ExtInfo struct {
		ThumbURL string `json:"thumb_url"`
	} `json:"ext_info"`
}

type FileParam

type FileParam struct {
	PPdirKey string `json:"ppdir_key,omitempty"` // 父父目录ID(下载忽略)
	PdirKey  string `json:"pdir_key,omitempty"`  // 父目录ID
	FileID   string `json:"file_id,omitempty"`   // 文件ID
	FileName string `json:"filename,omitempty"`  // 文件名称(下载忽略)
}

type Folder

type Folder struct {
	DirKey   string    `json:"dir_key"`
	DirName  string    `json:"dir_name"`
	DirCtime TimeStamp `json:"dir_ctime"`
	DirMtime TimeStamp `json:"dir_mtime"`
}

type FolderParam

type FolderParam struct {
	PPdirKey string `json:"ppdir_key,omitempty"` // 父父目录ID(打包下载忽略)(移动dst忽略)
	PdirKey  string `json:"pdir_key,omitempty"`  // 父目录ID(打包下载忽略)
	DirKey   string `json:"dir_key,omitempty"`   // 目录ID(创建忽略)
	DirName  string `json:"dir_name,omitempty"`  // 目录名称
}

type FolderPath

type FolderPath struct {
	PdirKey string `json:"pdir_key"`
	Folder
}

type GetType

type GetType int8

type Json

type Json map[string]any

func ApplyParamOption

func ApplyParamOption(param Json, option ...ParamOption) Json

func NewBody

func NewBody(cmdName string, data, tokenInfo Json) Json

func NewHeader

func NewHeader(cmd int, tokenInfo Json) Json

type OpenApiErron

type OpenApiErron struct {
	ErrCode int    `json:"err_code"`
	ErrMsg  string `json:"err_msg"`
}

func (*OpenApiErron) Error

func (e *OpenApiErron) Error() string

func (*OpenApiErron) IsError

func (e *OpenApiErron) IsError() bool

type OpenApiToken

type OpenApiToken struct {
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	TokenType    string `json:"token_type"`
}

type OrderBy

type OrderBy int8
const (
	FileName OrderBy
	FileMtime
	FileSize
)

type ParamOption

type ParamOption func(Json)

func QueryFileOptionCount

func QueryFileOptionCount(size int) ParamOption

func QueryFileOptionGetType

func QueryFileOptionGetType(t GetType) ParamOption

func QueryFileOptionOffest

func QueryFileOptionOffest(start int64) ParamOption

func QueryFileOptionSort

func QueryFileOptionSort(orderBy OrderBy, desc bool) ParamOption

func WarpParamOption

func WarpParamOption(option ...ParamOption) []ParamOption

type PreUploadData

type PreUploadData struct {
	FileExist bool `json:"file_exist"` // 文件是否存在
	File      File `json:"common_upload_rsp"`

	UploadScr int `json:"upload_scr"` // 未知

	// 上传授权
	UploadAuthData

	ChannelList []UploadChannelData `json:"channel_list"` // 上传通道

	Speedlimit int `json:"speedlimit"` // 上传速度限制
	FlowState  int `json:"flow_state"`

	UploadState     int `json:"upload_state"`      // 上传状态 1:上传未完成,3:该通道无剩余分片,2:上传完成
	UploadedDataLen int `json:"uploaded_data_len"` // 已经上传的长度
}

type Resp

type Resp struct {
	Code int    `json:"ret"`
	Msg  string `json:"msg"`

	Data *struct {
		RspHeader RespHeader `json:"rsp_header"`
		RspBody   struct {
			RspMsgBody json.RawMessage `json:"RspMsg_body"`
		} `json:"rsp_body"`
	} `json:"data"`
}

func (*Resp) Error

func (r *Resp) Error() string

func (*Resp) GetBody

func (r *Resp) GetBody() json.RawMessage

func (*Resp) GetHeader

func (r *Resp) GetHeader() RespHeader

func (*Resp) HasError

func (r *Resp) HasError() bool

type RespHeader

type RespHeader struct {
	Retcode int    `json:"retcode"`
	Retmsg  string `json:"retmsg"`

	Cmd     int    `json:"cmd"`
	CmdName string `json:"cmdName"`

	Uin  int64 `json:"uin"`
	Type int   `json:"type"`

	// flag
	ZipFlag int `json:"zip_flag"`
	Encrypt int `json:"encrypt"`

	Seq int64 `json:"seq"`
}

type RestyOption

type RestyOption func(request *resty.Request)

type SafeBoxCheckStatusData added in v0.1.3

type SafeBoxCheckStatusData struct {
	SafeBoxPdirkey string `json:"safe_box_pdirkey"`
	SafeBoxDirkey  string `json:"safe_box_dirkey"`
	PwdFailLimit   any    `json:"pwd_fail_limit"`
	PwdRetryCnt    int    `json:"pwd_retry_cnt"`
	NeedNotice     any    `json:"need_notice"`
}

type SafeBoxPublicKeyGetData added in v0.1.3

type SafeBoxPublicKeyGetData struct {
	PublicKey string `json:"public_key"`
}

type TimeStamp

type TimeStamp time.Time

* Json * 时间戳

func (*TimeStamp) UnmarshalJSON

func (t *TimeStamp) UnmarshalJSON(b []byte) error

type UpdloadFileParam

type UpdloadFileParam struct {
	PdirKey string // 父父目录ID
	DirKey  string // 父目录ID

	FileName string
	FileSize int64
	File     io.ReadSeeker

	ChannelCount int // 上传通道数量

	// 遇到同名文件操作
	// 1(覆盖) 2 to n(重命名)
	FileExistOption int
}

type UploadAuthData

type UploadAuthData struct {
	UploadKey string `json:"upload_key"`
	Ex        string `json:"ex"`
}

type UploadChannelData

type UploadChannelData struct {
	ID     int   `json:"id"`
	Offset int64 `json:"offset"`
	Len    int   `json:"len"`
}

type UploadPieceData

type UploadPieceData struct {
	Channel UploadChannelData `json:"channel"` // 下一个分片
	Ex      string            `json:"ex"`

	UploadState int `json:"upload_state"` // 上传状态 1:上传未完成,3:该通道无剩余分片,2:上传完成
	FlowState   int `json:"flow_state"`
}

type WeiXinRefreshTokenData

type WeiXinRefreshTokenData struct {
	Openid       string `json:"openid"`
	AccessToken  string `json:"access_token"`
	ExpiresIn    int    `json:"expires_in"`
	RefreshToken string `json:"refresh_token"`
	Scope        string `json:"scope"`
}

type WeiYunClient

type WeiYunClient struct {
	Client *resty.Client
	// contains filtered or unexported fields
}

func NewWeiYunClient

func NewWeiYunClient() *WeiYunClient

func NewWeiYunClientWithRestyClient

func NewWeiYunClientWithRestyClient(client *resty.Client) *WeiYunClient

func (*WeiYunClient) AddUploadChannel

func (c *WeiYunClient) AddUploadChannel(origChannelCount, destChannelCount int, auth UploadAuthData, opts ...RestyOption) (*AddChannelData, error)

增加上传通道

func (*WeiYunClient) DiskDirAttrModify

func (c *WeiYunClient) DiskDirAttrModify(dParam FolderParam, newDirName string, opts ...RestyOption) error

文件夹重命名

func (*WeiYunClient) DiskDirCreate

func (c *WeiYunClient) DiskDirCreate(dParam FolderParam, opts ...RestyOption) (*Folder, error)

文件夹创建

func (*WeiYunClient) DiskDirDelete

func (c *WeiYunClient) DiskDirDelete(dParam FolderParam, opts ...RestyOption) error

文件夹删除

func (*WeiYunClient) DiskDirFileBatchList

func (c *WeiYunClient) DiskDirFileBatchList(batchParam []DiskDirFileBatchListParam, commonParamOption []ParamOption, opts ...RestyOption) ([]DiskListData, error)

批量查询文件、文件夹

func (*WeiYunClient) DiskDirFileList

func (c *WeiYunClient) DiskDirFileList(dirKey string, paramOption []ParamOption, opts ...RestyOption) (*DiskListData, error)

查询文件、文件夹 数量限制 500

func (*WeiYunClient) DiskDirMove

func (c *WeiYunClient) DiskDirMove(srcParam FolderParam, dstParam FolderParam, opts ...RestyOption) error

文件夹移动

func (*WeiYunClient) DiskFileBatchDownload

func (c *WeiYunClient) DiskFileBatchDownload(fParam []FileParam, opts ...RestyOption) ([]DiskFileDownloadData, error)

批量下载

func (*WeiYunClient) DiskFileDelete

func (c *WeiYunClient) DiskFileDelete(fParam FileParam, opts ...RestyOption) error

文件删除

func (*WeiYunClient) DiskFileDownload

func (c *WeiYunClient) DiskFileDownload(fParam FileParam, opts ...RestyOption) (*DiskFileDownloadData, error)

文件下载

func (*WeiYunClient) DiskFileMove

func (c *WeiYunClient) DiskFileMove(srcParam FileParam, dstParam FolderParam, opts ...RestyOption) error

文件移动

func (*WeiYunClient) DiskFilePackageDownload

func (c *WeiYunClient) DiskFilePackageDownload(param []DiskFilePackageDownloadParam, zipFilename string, opts ...RestyOption) (*DiskFileDownloadData, error)

文件打包下载

func (*WeiYunClient) DiskFileRename

func (c *WeiYunClient) DiskFileRename(fParam FileParam, newFileName string, opts ...RestyOption) error

文件重命名

func (*WeiYunClient) DiskUserInfoGet

func (c *WeiYunClient) DiskUserInfoGet(opts ...RestyOption) (*DiskUserInfoGetData, error)

获取用户信息

func (*WeiYunClient) GetCookieJar

func (c *WeiYunClient) GetCookieJar() http.CookieJar

func (*WeiYunClient) GetCookies

func (c *WeiYunClient) GetCookies() []*http.Cookie

获取登录Cookie 内部未拷贝,谨慎修改

func (*WeiYunClient) KeepAlive

func (c *WeiYunClient) KeepAlive() error

func (*WeiYunClient) LibDirPathGet

func (c *WeiYunClient) LibDirPathGet(dirKey string, opts ...RestyOption) ([]FolderPath, error)

查询文件夹完整路径

func (*WeiYunClient) LoginType

func (c *WeiYunClient) LoginType() int8

2:wx 1:qq 0:not login

func (*WeiYunClient) ParseTokenInfo

func (c *WeiYunClient) ParseTokenInfo() Json

func (*WeiYunClient) PreUpload

func (c *WeiYunClient) PreUpload(ctx context.Context, param UpdloadFileParam, opts ...RestyOption) (*PreUploadData, error)

func (*WeiYunClient) QQFastLogin

func (c *WeiYunClient) QQFastLogin(ctx context.Context, qq string) ([]*http.Cookie, error)

本地qq快速登录

func (*WeiYunClient) QQLoginInit

func (c *WeiYunClient) QQLoginInit(ctx context.Context) (appid, daid, callbackURL string, err error)

func (*WeiYunClient) QQQRLogin

func (c *WeiYunClient) QQQRLogin(ctx context.Context, showQR func([]byte) error) ([]*http.Cookie, error)

QQ扫码登录

func (*WeiYunClient) RefreshCtoken

func (c *WeiYunClient) RefreshCtoken() error

func (*WeiYunClient) Request

func (c *WeiYunClient) Request(protocol, name string, cmd int, data Json, resp any, opts ...RestyOption) ([]byte, error)

func (*WeiYunClient) SafeBoxCheckStatus added in v0.1.3

func (c *WeiYunClient) SafeBoxCheckStatus(opts ...RestyOption) (*SafeBoxCheckStatusData, error)

func (*WeiYunClient) SafeBoxPublicKeyGet added in v0.1.3

func (c *WeiYunClient) SafeBoxPublicKeyGet(opts ...RestyOption) (*SafeBoxPublicKeyGetData, error)

func (*WeiYunClient) SetClient

func (c *WeiYunClient) SetClient(client *http.Client) *WeiYunClient

func (*WeiYunClient) SetCookies

func (c *WeiYunClient) SetCookies(cks []*http.Cookie) *WeiYunClient

设置登录Cookie

func (*WeiYunClient) SetCookiesStr

func (c *WeiYunClient) SetCookiesStr(str string) *WeiYunClient

设置登录Cookie字符串

func (*WeiYunClient) SetOnCookieExpired

func (c *WeiYunClient) SetOnCookieExpired(onCookieExpired func(error))

func (*WeiYunClient) SetOnCookieUpload

func (c *WeiYunClient) SetOnCookieUpload(onCookieUpload func([]*http.Cookie))

func (*WeiYunClient) SetProxy

func (c *WeiYunClient) SetProxy(proxy string) *WeiYunClient

func (*WeiYunClient) SetRestyClient

func (c *WeiYunClient) SetRestyClient(client *resty.Client) *WeiYunClient

func (*WeiYunClient) UploadFile

func (c *WeiYunClient) UploadFile(ctx context.Context, channel UploadChannelData, auth UploadAuthData, r io.Reader, opts ...RestyOption) (*UploadPieceData, error)

func (*WeiYunClient) UploadRequest

func (c *WeiYunClient) UploadRequest(name string, cmd int, data Json, resp any, opts ...RestyOption) ([]byte, error)

func (*WeiYunClient) WeiXinQRLogin

func (c *WeiYunClient) WeiXinQRLogin(ctx context.Context, showQR func([]byte) error) ([]*http.Cookie, error)

微信扫码登录 cookies: wx_login_ticket, access_token, refresh_token, openid, wy_appid, wyctoken, wx_uid, key_type

func (*WeiYunClient) WeiXinRefreshToken

func (c *WeiYunClient) WeiXinRefreshToken() (*WeiXinRefreshTokenData, error)

微信刷新Token

func (*WeiYunClient) WeiyunFileLibClientRequest

func (c *WeiYunClient) WeiyunFileLibClientRequest(name string, cmd int, data Json, resp any, opts ...RestyOption) ([]byte, error)

func (*WeiYunClient) WeiyunQdiskClientRequest

func (c *WeiYunClient) WeiyunQdiskClientRequest(name string, cmd int, data Json, resp any, opts ...RestyOption) ([]byte, error)

func (*WeiYunClient) WeiyunQdiskRequest

func (c *WeiYunClient) WeiyunQdiskRequest(name string, cmd int, data Json, resp any, opts ...RestyOption) ([]byte, error)

func (*WeiYunClient) WeiyunSafeBoxRequest added in v0.1.3

func (c *WeiYunClient) WeiyunSafeBoxRequest(name string, cmd int, data Json, resp any, opts ...RestyOption) ([]byte, error)

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL