apiutils

package
v0.0.0-...-4687089 Latest Latest
Warning

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

Go to latest
Published: Dec 27, 2024 License: AGPL-3.0 Imports: 19 Imported by: 2

Documentation

Index

Constants

This section is empty.

Variables

View Source
var AppInfoDefaultGetter = func(ctx echo.Context, cond db.Compound) (appInfo AppInfo, err error) {
	err = ctx.NewError(code.Unsupported, `尚未设置App信息获取方式`)
	return
}
View Source
var DefaultURLValuesGenerator = func(values url.Values) URLValuesGenerator {
	return URLValues(values)
}
View Source
var OauthOptionsCreater = func(ctx echo.Context, typ Type, generators ...URLValuesGenerator) OauthOption {
	return NewOptions(ctx, TypeOauth, generators...)
}

Functions

func BuildURLValues

func BuildURLValues(values url.Values, secret string) url.Values

BuildURLValues 构建API参数值

func CheckSign

func CheckSign(raw string, sign string) error

CheckSign 检查签名是否匹配

func Decrypt

func Decrypt(decrypted string, secret string) string

func Encrypt

func Encrypt(raw string, secret string) string

func GenSign

func GenSign(formData url.Values) string

GenSign 根据url.Values类型值生成签名

func GetOauthProviderTitle

func GetOauthProviderTitle(list []*OauthProvider, name string) string

func MakeSign

func MakeSign(data url.Values, secret string) string

MakeSign 生成签名 规则说明:数据按照以键的字母顺序排列后进行url编码,然后拼接上`&secret=密钥` 等价的PHP代码: ```php <?php

function makeSign(array $data, string $secret): string{
	ksort($data);
	return hash('sha256',http_build_query($data).'&secret='.$secret);
}

```

func SignString

func SignString(raw string) string

SignString 生成签名字符串

func Submit

func Submit(ctx echo.Context, apiURL string, formData url.Values, method ...string) (*echo.RawData, error)

func SubmitWithRecv

func SubmitWithRecv(ctx echo.Context, recv interface{}, apiURL string, formData url.Values, method ...string) (*resty.Response, error)

func Submitx

func Submitx(ctx echo.Context, apiURL string, formData url.Values, method ...string) (echo.H, string, error)

Types

type AppInfo

type AppInfo interface {
	GetAppSecret() string
	GetAppId() string
}

type OauthOption

type OauthOption interface {
	GetAccountID() uint64
	ApplySetting() (err error)
	GetAppID() string
	OauthProvierListURL(appID string) (string, error)
}

type OauthProvider

type OauthProvider struct {
	Name      string `json:"name" xml:"name"`
	English   string `json:"english" xml:"english"`
	IconClass string `json:"iconClass" xml:"iconClass"`
	IconImage string `json:"iconImage" xml:"iconImage"`
	WrapClass string `json:"wrapClass" xml:"wrapClass"`
	LoginURL  string `json:"loginURL" xml:"loginURL"`
}

func GetOauthProvider

func GetOauthProvider(list []*OauthProvider, name string) *OauthProvider

func OauthProviders

func OauthProviders(ctx echo.Context) ([]*OauthProvider, error)

func OauthProvidersFrom

func OauthProvidersFrom(accounts []oauth2.Account) []*OauthProvider

type OauthProvidersResponse

type OauthProvidersResponse struct {
	List []*OauthProvider `json:"list"`
}

type Options

type Options struct {
	Account   *dbschema.OfficialCommonApiAccount
	App       AppInfo
	URLPrefix string
	Type      Type
	// contains filtered or unexported fields
}

func NewOptions

func NewOptions(ctx echo.Context, typ Type, generators ...URLValuesGenerator) *Options

func (*Options) ApplySetting

func (o *Options) ApplySetting() (err error)

func (*Options) Context

func (o *Options) Context() echo.Context

func (*Options) GetAccountID

func (o *Options) GetAccountID() uint64

func (*Options) GetAppID

func (o *Options) GetAppID() string

func (*Options) GetAppSecret

func (o *Options) GetAppSecret() string

func (*Options) OauthProvierListURL

func (o *Options) OauthProvierListURL(appID string) (string, error)

OauthProvierListURL 社区登录供应商列表

func (*Options) SetAppInfoGetter

func (o *Options) SetAppInfoGetter(appInfoGetter func(ctx echo.Context, cond db.Cond) (appInfo AppInfo, err error)) *Options

func (*Options) SetGenerator

func (o *Options) SetGenerator(g URLValuesGenerator) *Options

func (*Options) SetSignaturer

func (o *Options) SetSignaturer(fn func(url.Values) string) *Options

func (*Options) ToURL

func (o *Options) ToURL(urlPath string, strength ...bool) (uri string, formData url.Values, err error)

type Type

type Type string
const (
	// TypeOauth 社区登录类型
	TypeOauth Type = "oauth"
	// TypePayment 支付类型
	TypePayment Type = "payment"
)

type URLValues

type URLValues url.Values

func (URLValues) URLValues

func (u URLValues) URLValues(signGenerators ...func(url.Values) string) url.Values

type URLValuesGenerator

type URLValuesGenerator interface {
	URLValues(signGenerators ...func(url.Values) string) url.Values
}

Jump to

Keyboard shortcuts

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