bytedance

package
v0.4.3 Latest Latest
Warning

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

Go to latest
Published: Jan 8, 2021 License: MIT Imports: 19 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

func AESCBCDecrypt

func AESCBCDecrypt(encryptData, key []byte) ([]byte, error)

AESCBCDecrypt aes cbc 解密

func CheckResponse

func CheckResponse(r *Response, reqBody []byte) error

CheckResponse checks the API response for errors, and returns them if present. API error responses are expected to have response body. If none error find, return bytedance.Response.

func Decrypt

func Decrypt(rawData, key string) (string, error)

Decrypt 解密

func DecryptMsg

func DecryptMsg(encodeAesKey string, encryptMsg string) map[string]interface{}

DecryptMsg 消息解密

func PKCS7UnPadding

func PKCS7UnPadding(origData []byte) []byte

PKCS7UnPadding un padding

func Sha1

func Sha1(str string) string

Sha1 sha1 加密

func Verify

func Verify(tpToken string, timestamp string, nonce string, encrypt string, msgSignature string) bool

Verify 校验加密信息

Types

type AddTemplateRequest

type AddTemplateRequest struct {
	DraftID int `json:"draft_id"`
}

AddTemplateRequest 添加模版请求

type AppCategoriesAuditInfo

type AppCategoriesAuditInfo struct {
	AppCategory           string `json:"app_category"`
	AppCategoryName       string `json:"app_category_name"`
	AppCategoryAuditState int    `json:"app_category_audit_state"`
	Reason                string `json:"reason"`
}

AppCategoriesAuditInfo 类目审核信息

type AppInfo

type AppInfo struct {
	AppID                  string                    `json:"app_id"`
	AppType                int                       `json:"app_type"`
	AppState               int                       `json:"app_state"`
	AppName                string                    `json:"app_name"`
	NewNameAuditInfo       *NewNameAuditInfo         `json:"new_name_audit_info"`
	AppIntro               string                    `json:"app_intro"`
	NewIntroAuditInfo      *NewIntroAuditInfo        `json:"new_intro_audit_info"`
	AppIcon                string                    `json:"app_icon"`
	NewIConAuditInfo       *NewIconAuditInfo         `json:"new_i_con_audit_info"`
	AppCategoriesAuditInfo []*AppCategoriesAuditInfo `json:"app_categories_audit_info"`
	SubjectAuditInfo       *SubjectAuditInfo         `json:"subject_audit_info"`
}

AppInfo 应用信息

type Audit

type Audit struct {
	VersionCommon

	ApprovedApps     []int           `json:"approvedApps"`
	AttachInfo       json.RawMessage `json:"attachInfo"`
	HasPublish       int             `json:"has_publish"`
	IsIllegalVersion bool            `json:"is_illegal_version"`
	Reason           string          `json:"reason"`
	ReasonDetail     json.RawMessage `json:"reason_detail"`
	Status           int             `json:"status"`
}

Audit 审核版本返回值

type AuthorizePermission

type AuthorizePermission struct {
	ID          int    `json:"id"`
	Category    string `json:"category"`
	Description string `json:"description"`
}

AuthorizePermission 授权小程序在授权跳转页勾选的权限

type Client

type Client struct {

	// Base URL for API.requests.
	// BaseURL should always be specified with a trailing slash.
	BaseURL *url.URL

	// User agent used when communication with bytedance API.
	UserAgent string

	// Services used for talking to different parts of bytedance API.
	ThirdParty *ThirdPartyService
	MicroApp   *MicroAppService
	// contains filtered or unexported fields
}

Client manages communication with the bytedance API.

func NewClient

func NewClient() *Client

NewClient returns a new bytedance API client.

func (*Client) Do

func (c *Client) Do(ctx context.Context, req *http.Request, v interface{}) (*http.Response, error)

Do Sends an API request and returns the API response. The API response is JSON decoded and stored in the value pointed to by v, or returned as an error if an API error has occurred. If v implements the io.Writer interface, the raw response body will be written to v, without attempting to first decode it.

The provided ctx must be non-nil, if it is nil an error is returned. If it is canceled or timeout, ctx.Err() will be returned.

func (*Client) NewRequest

func (c *Client) NewRequest(method, urlStr string, body interface{}) (*http.Request, error)

NewRequest creates an API request. A relative URL can be provided in urlStr, in which case it is resolved relative to the BaseURL of the Client. Relative URLs should always be specified without a preceding slash. If specified, the value pointed to by body is JSON encoded and included as request body.

type CommitAuditPackageRequest

type CommitAuditPackageRequest struct {
	HostNames []string `json:"hostNames"`
}

CommitAuditPackageRequest 提审代码请求

type ComponentAccessToken

type ComponentAccessToken struct {
	ComponentAccessToken string `json:"component_access_token"`
	ExpiresIn            int64  `json:"expires_in"`
}

ComponentAccessToken is response of API v1/auth/tp/token.

type CreatePreAuthCodeRequest

type CreatePreAuthCodeRequest struct {
	ShareRatio  int `json:"share_ratio"`
	ShareAmount int `json:"share_amount"`
}

CreatePreAuthCodeRequest 创建预授权码请求body

type Current

type Current struct {
	VersionCommon

	ApprovedApps    []int           `json:"approvedApps"`
	AttachInfo      json.RawMessage `json:"attachInfo"`
	HasDown         int             `json:"has_down"`
	NotApprovedApps []string        `json:"notApprovedApps"`
	Reason          string          `json:"reason"`
	ReasonDetail    json.RawMessage `json:"reason_detail"`
	Rollback        *Rollback       `json:"rollback"`
	LastVersion     string          `json:"last_version"`
	UID             string          `json:"uid,omitempty"`
}

Current 线上版本返回值

type DeleteTemplateRequest

type DeleteTemplateRequest struct {
	TemplateID int `json:"template_id"`
}

DeleteTemplateRequest 删除模版请求

type DownloadQrcodeRequest

type DownloadQrcodeRequest struct {
	Version string `json:"version"` // 入参:current 或 audit 或 latest current 线上版 audit 审核版 latest 测试版
	Path    string `json:"path,omitempty"`
}

DownloadQrcodeRequest 获取二维码请求

type Draft

type Draft struct {
	DraftID     int        `json:"draft_id"`
	UserVersion string     `json:"user_version"`
	UserDesc    string     `json:"user_desc"`
	CreateTime  *Timestamp `json:"create_time"`
}

Draft 草稿

type Drafts

type Drafts struct {
	DraftList []*Draft `json:"draft_list"`
}

Drafts 获取草稿列表返回值

type ErrorResponse

type ErrorResponse struct {
	*http.Response

	ErrNo   int    `json:"errno"`
	Message string `json:"message"`
	// contains filtered or unexported fields
}

ErrorResponse represents bytedance Error Response.

func (*ErrorResponse) Error

func (r *ErrorResponse) Error() string

Error implements builtin.error interface.

type File

type File struct {
	Name    string
	Content io.Reader
}

File wrapped file content

func (File) Read

func (f File) Read(p []byte) (n int, err error)

Read proxy Content Read

type FormRender

type FormRender interface {
	Params() map[string]string
	MultipartParams() map[string]io.Reader
}

FormRender for form with file request.

type Latest

type Latest struct {
	VersionCommon

	HasAudit   int    `json:"has_audit"`
	ScreenShot string `json:"screen_shot"`
}

Latest 测试版本返回值

type MicroAppService

type MicroAppService service

MicroAppService handles communication with the micro app related method of the ByteDance API.

func (*MicroAppService) CheckAppName

func (s *MicroAppService) CheckAppName(ctx context.Context, componentAppID, authorizerAccessToken, appName string) (*http.Response, error)

CheckAppName 小程序名称检测

func (*MicroAppService) Code2Session added in v0.1.12

func (s *MicroAppService) Code2Session(ctx context.Context, componentAppID, authorizerAccessToken,
	code, anonymousCode string) (*Session, *http.Response, error)

Code2Session code2session

func (*MicroAppService) CommitAuditPackage

func (s *MicroAppService) CommitAuditPackage(ctx context.Context, componentAppID, authorizerAccessToken string,
	body *CommitAuditPackageRequest) (*http.Response, error)

CommitAuditPackage 提审代码 v2 支持传入宿主端参数 为授权小程序提审代码(审核成功后,授权小程序具有审核版本)

func (*MicroAppService) DownloadQrcode

func (s *MicroAppService) DownloadQrcode(ctx context.Context, componentAppID, authorizerAccessToken string,
	body *DownloadQrcodeRequest) (*http.Response, error)

DownloadQrcode 获取二维码

func (*MicroAppService) GetAppInfo

func (s *MicroAppService) GetAppInfo(ctx context.Context, componentAppID, authorizerAccessToken string) (
	*AppInfo, *http.Response, error)

GetAppInfo 获取应用信息

func (*MicroAppService) GetPackageAuditHosts

func (s *MicroAppService) GetPackageAuditHosts(ctx context.Context, componentAppID, authorizerAccessToken string) (
	*PackageAuditHosts, *http.Response, error)

GetPackageAuditHosts 获取可选审核宿主端列表 获取可以提审的端,作为参数传入提审代码v2接口中

func (*MicroAppService) GetPackageVersions

func (s *MicroAppService) GetPackageVersions(ctx context.Context, componentAppID, authorizerAccessToken string) (
	*PackageVersions, *http.Response, error)

GetPackageVersions 获取小程序版本列表信息 返回的结果列表中一共会展示三种状态的小程序代码版本信息,包括测试版本、审核版本、线上版本。

func (*MicroAppService) ModifyAppIcon

func (s *MicroAppService) ModifyAppIcon(ctx context.Context, componentAppID, authorizerAccessToken string,
	body *ModifyAppIconRequest) (*http.Response, error)

ModifyAppIcon 修改小程序图标

func (*MicroAppService) ModifyAppName

func (s *MicroAppService) ModifyAppName(ctx context.Context, componentAppID, authorizerAccessToken string,
	body *ModifyAppNameRequest) (*http.Response, error)

ModifyAppName 修改小程序名称

func (*MicroAppService) ModifyIntro

func (s *MicroAppService) ModifyIntro(ctx context.Context, componentAppID, authorizerAccessToken string,
	body *ModifyAppIntroRequest) (*http.Response, error)

ModifyIntro 修改小程序简介

func (*MicroAppService) ModifyServerDomain

func (s *MicroAppService) ModifyServerDomain(ctx context.Context, componentAppID, authorizerAccessToken string,
	body *ModifyServerDomainRequest) (*ServerDomain, *http.Response, error)

ModifyServerDomain 修改服务域名

func (*MicroAppService) ModifyWebviewDomain

func (s *MicroAppService) ModifyWebviewDomain(ctx context.Context, componentAppID, authorizerAccessToken string,
	body *ModifyWebviewDomainRequest) ([]string, *http.Response, error)

ModifyWebviewDomain 修改webview域名

func (*MicroAppService) ReleasePackage

func (s *MicroAppService) ReleasePackage(ctx context.Context, componentAppID, authorizerAccessToken string) (
	*http.Response, error)

ReleasePackage 发布代码 为授权小程序发布代码(发布成功后,授权小程序具有线上版本)

func (*MicroAppService) RollbackPackage

func (s *MicroAppService) RollbackPackage(ctx context.Context, componentAppID, authorizerAccessToken string) (
	*http.Response, error)

RollbackPackage 回退代码版本 为授权小程序回退代码版本,此操作可能需要等待一会(如果可以回退,执行成功后,授权小程序将回退至上一个线上版本)

func (*MicroAppService) UploadPackage

func (s *MicroAppService) UploadPackage(ctx context.Context, componentAppID, authorizerAccessToken string,
	body *UploadPackageRequest) (*http.Response, error)

UploadPackage 提交代码 为授权小程序提交代码(提交成功后,授权小程序具有测试版本).

type ModifyAppIconRequest

type ModifyAppIconRequest struct {
	NewIconPath string `json:"new_icon_path"`
}

ModifyAppIconRequest 修改应用简介

type ModifyAppIntroRequest

type ModifyAppIntroRequest struct {
	NewIntro string `json:"new_intro"`
}

ModifyAppIntroRequest 修改应用简介

type ModifyAppNameRequest

type ModifyAppNameRequest struct {
	NewName          string `json:"new_name"`
	MaterialFilePath string `json:"material_file_path,omitempty"`
}

ModifyAppNameRequest 修改应用名称

type ModifyServerDomainRequest

type ModifyServerDomainRequest struct {
	// 默认将第三方平台配置好的 request、socket、upload、download 域名全部添加到授权小程序
	Action   string   `json:"action"` // add 添加,delete 删除,set 覆盖,get 获取
	Request  []string `json:"request"`
	Socket   []string `json:"socket"`
	Upload   []string `json:"upload"`
	Download []string `json:"download"`
}

ModifyServerDomainRequest 修改服务域名

type ModifyWebviewDomainRequest

type ModifyWebviewDomainRequest struct {
	// 默认将第三方平台配置好的 webview 域名全部添加到授权小程序
	Action  string   `json:"action"` // add 添加,delete 删除,set 覆盖,get 获取
	Webview []string `json:"webview"`
}

ModifyWebviewDomainRequest 修改webview域名

type NewIconAuditInfo

type NewIconAuditInfo struct {
	NewIcon           string `json:"new_icon"`
	RemainingTimes    int    `json:"remaining_times"`
	NewIconAuditState int    `json:"new_icon_audit_state"`
	Reason            string `json:"reason"`
	Advice            string `json:"advice"`
}

NewIconAuditInfo 图标审核信息

type NewIntroAuditInfo

type NewIntroAuditInfo struct {
	NewIntro           string `json:"new_intro"`
	RemainingTimes     int    `json:"remaining_times"`
	NewIntroAuditState int    `json:"new_intro_audit_state"`
	Reason             string `json:"reason"`
	Advice             string `json:"advice"`
}

NewIntroAuditInfo 介绍审核信息

type NewNameAuditInfo

type NewNameAuditInfo struct {
	NewName           string `json:"new_name"`
	RemainingTimes    int    `json:"remaining_times"`
	NewNameAuditState int    `json:"new_name_audit_state"`
	Reason            string `json:"reason"`
	Advice            string `json:"advice"`
}

NewNameAuditInfo 名字审核信息

type OAuthToken

type OAuthToken struct {
	AuthorizerAccessToken  string                 `json:"authorizer_access_token"`
	AuthorizerRefreshToken string                 `json:"authorizer_refresh_token"`
	ExpiresIn              int64                  `json:"expires_in"`
	AuthorizerAppID        string                 `json:"authorizer_appid"`
	AuthorizePermission    []*AuthorizePermission `json:"authorize_permission"`
}

OAuthToken 获取接口调用凭据

type PackageAuditHosts

type PackageAuditHosts struct {
	HostNames         []string `json:"hostNames"`
	ReleasedHostNames []string `json:"releasedHostNames"`
}

PackageAuditHosts 获取可选审核宿主端列表返回.

type PackageVersions

type PackageVersions struct {
	Audit   *Audit   `json:"audit"`
	Current *Current `json:"current"`
	Latest  *Latest  `json:"latest"`
}

PackageVersions 获取小程序版本列表信息返回

type PreAuthCode

type PreAuthCode struct {
	PreAuthCode string `json:"pre_auth_code"`
	ExpiresIn   int64  `json:"expires_in"`
}

PreAuthCode 创建预授权码返回值

type RefreshOAuthTokenResponse

type RefreshOAuthTokenResponse struct {
	AuthorizerAccessToken  string `json:"authorizer_access_token"`
	AuthorizerRefreshToken string `json:"authorizer_refresh_token"`
	ExpiresIn              int64  `json:"expires_in"`
}

RefreshOAuthTokenResponse 刷新授权小程序的接口调用凭据返回值

type Response

type Response struct {
	*http.Response

	ErrNo   int             `json:"errno"`
	Message string          `json:"message"`
	Data    json.RawMessage `json:"data"`
}

Response represents bytedance Response.

type RetrieveAuthorizationCodeResponse

type RetrieveAuthorizationCodeResponse struct {
	AuthorizationCode string `json:"authorization_code"`
	ExpiresIn         int64  `json:"expires_in"`
}

RetrieveAuthorizationCodeResponse 找回授权码

type Rollback

type Rollback struct {
	CanRollback bool   `json:"can_rollback"`
	LastVersion string `json:"last_version"`
}

Rollback info

type ServerDomain

type ServerDomain struct {
	Request  []string `json:"request"`
	Socket   []string `json:"socket"`
	Upload   []string `json:"upload"`
	Download []string `json:"download"`
}

ServerDomain 服务域名

type Session added in v0.1.12

type Session struct {
	SessionKey      string `json:"session_key"`
	OpenID          string `json:"openid"`
	AnonymousOpenID string `json:"anonymous_openid"`
}

Session 返回

type SubjectAuditInfo

type SubjectAuditInfo struct {
	SubjectNumber     string `json:"subject_number"`
	SubjectName       string `json:"subject_name"`
	SubjectType       int    `json:"subject_type"`
	SubjectAuditState int    `json:"subject_audit_state"`
	Reason            string `json:"reason"`
}

SubjectAuditInfo 主体信息

type Template

type Template struct {
	TemplateID  int        `json:"template_id"`
	UserVersion string     `json:"user_version"`
	UserDesc    string     `json:"user_desc"`
	CreateTime  *Timestamp `json:"create_time"`
}

Template 模版

type Templates

type Templates struct {
	TemplateList []*Template `json:"template_list"`
}

Templates 获取模版列表返回值

type ThirdPartyService

type ThirdPartyService service

ThirdPartyService handles communication with the third party related method of the ByteDance API.

func (*ThirdPartyService) AddTemplate

func (s *ThirdPartyService) AddTemplate(ctx context.Context, componentAppID, componentAccessToken string,
	body *AddTemplateRequest) (*http.Response, error)

AddTemplate adds a template from draft. 将临时草稿设置为持久的代码模板。每个第三方应用的模板上限为200个。

func (*ThirdPartyService) CreatePreAuthCode

func (s *ThirdPartyService) CreatePreAuthCode(ctx context.Context, componentAccessToken,
	componentAppID string, body *CreatePreAuthCodeRequest) (*PreAuthCode, *http.Response, error)

CreatePreAuthCode creates a pre_auth_code for auth. 用于获取预授权码,预授权码用于小程序授权时的第三方平台方安全验证。 每个预授权码有效期为 10 分钟。

func (*ThirdPartyService) DeleteTemplate

func (s *ThirdPartyService) DeleteTemplate(ctx context.Context, componentAppID, componentAccessToken string,
	body *DeleteTemplateRequest) (*http.Response, error)

DeleteTemplate deletes a template from draft. 将临时草稿设置为持久的代码模板。每个第三方应用的模板上限为200个。

func (*ThirdPartyService) DownloadWebViewFile

func (s *ThirdPartyService) DownloadWebViewFile(ctx context.Context, componentAppID, componentAccessToken string,
	body *DeleteTemplateRequest) (*http.Response, error)

DownloadWebViewFile 下载域名校验文件

func (*ThirdPartyService) GetComponentAccessToken

func (s *ThirdPartyService) GetComponentAccessToken(ctx context.Context, componentAppID, componentAppSecret,
	componentTicket string) (*ComponentAccessToken, *http.Response, error)

GetComponentAccessToken gets a component_access_token. 获取第三方平台 component_access_token 每个令牌有效期是 2 小时

func (*ThirdPartyService) GetDrafts

func (s *ThirdPartyService) GetDrafts(ctx context.Context, componentAppID, componentAccessToken string) (
	*Drafts, *http.Response, error)

GetDrafts 获取第三方应用的草稿

func (*ThirdPartyService) GetOAuthToken

func (s *ThirdPartyService) GetOAuthToken(ctx context.Context, componentAppID, componentAccessToken,
	authorizationCode, grantType string) (*OAuthToken, *http.Response, error)

GetOAuthToken get authorizer_access_token. 使用授权码换取小程序的接口调用凭据 authorizer_access_token 有效期 2 小时 authorizer_refresh_token 有效期 1 个月,且只可使用一次,使用后失效

func (*ThirdPartyService) GetTemplates

func (s *ThirdPartyService) GetTemplates(ctx context.Context, componentAppID, componentAccessToken string) (
	*Templates, *http.Response, error)

GetTemplates 获取第三方应用的所有模版

func (*ThirdPartyService) RefreshOAuthToken

func (s *ThirdPartyService) RefreshOAuthToken(ctx context.Context, componentAppID, componentAccessToken,
	authorizerRefreshToken, grantType string) (*RefreshOAuthTokenResponse, *http.Response, error)

RefreshOAuthToken refresh authorizer_access_token 刷新授权小程序的接口调用凭据

func (*ThirdPartyService) RetrieveAuthorizationCode

func (s *ThirdPartyService) RetrieveAuthorizationCode(ctx context.Context, componentAppID, componentAccessToken,
	authorizationAppID string) (*RetrieveAuthorizationCodeResponse, *http.Response, error)

RetrieveAuthorizationCode retrieve authorizer_access_token. 找回授权码 补偿机制

func (*ThirdPartyService) UploadPicMaterial

func (s *ThirdPartyService) UploadPicMaterial(ctx context.Context, componentAppID, componentAccessToken string,
	body *UploadPicMaterialRequest) (string, *http.Response, error)

UploadPicMaterial 上传图片材料 使用修改名称、图标、服务类目等涉及材料证明的接口前,都需要先使用这个图片上传接口拿到返回的图片地址 目前只支持bmp、jpeg、jpg、png格式。

type Timestamp added in v0.3.0

type Timestamp struct {
	time.Time
}

Timestamp represents a time that can be unmarshalled from a JSON string formatted as either an RFC3339 or Unix timestamp. This is necessary for some fields since the GitHub API is inconsistent in how it represents times. All exported methods of time.Time can be called on Timestamp.

func (Timestamp) Equal added in v0.3.0

func (t Timestamp) Equal(u Timestamp) bool

Equal reports whether t and u are equal based on time.Equal

func (Timestamp) String added in v0.3.0

func (t Timestamp) String() string

func (*Timestamp) UnmarshalJSON added in v0.3.0

func (t *Timestamp) UnmarshalJSON(data []byte) (err error)

UnmarshalJSON implements the json.Unmarshaler interface. Time is expected in RFC3339 or Unix format.

type UploadPackageRequest

type UploadPackageRequest struct {
	TemplateID  int    `json:"template_id"`
	UserDesc    string `json:"user_desc"`
	UserVersion string `json:"user_version"`
	ExtJSON     string `json:"ext_json"`
}

UploadPackageRequest 上传代码请求.

type UploadPicMaterialRequest

type UploadPicMaterialRequest struct {
	MaterialType int   `json:"material_type"`
	MaterialFile *File `json:"material_file"`
}

UploadPicMaterialRequest 上传图片请求

func (UploadPicMaterialRequest) MultipartParams

func (u UploadPicMaterialRequest) MultipartParams() map[string]io.Reader

MultipartParams implements FormRender interface.

func (UploadPicMaterialRequest) Params

func (u UploadPicMaterialRequest) Params() map[string]string

Params implements FormRender interface.

type VersionCommon

type VersionCommon struct {
	Categories      []string   `json:"categories"`
	Ctime           *Timestamp `json:"ctime"`
	DeveloperAvatar string     `json:"developer_avatar"`
	DeveloperID     string     `json:"developer_id"`
	DeveloperName   string     `json:"developer_name"`
	Summary         string     `json:"summary"`
	Version         string     `json:"version"`
}

VersionCommon 通用返回值

Jump to

Keyboard shortcuts

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