common

package
v0.5.0 Latest Latest
Warning

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

Go to latest
Published: Nov 7, 2020 License: Apache-2.0 Imports: 10 Imported by: 0

Documentation

Index

Constants

View Source
const (
	ApiDefaultHostUrl  = "https://api.weixin.qq.com"
	MpDefaultHostUrl   = "https://mp.weixin.qq.com"
	OpenDefaultHostUrl = "https://open.weixin.qq.com"

	AccessTokenUrl = ApiDefaultHostUrl + "/cgi-bin/token?grant_type=client_credential&appid=%s&secret=%s"

	ApiSuffix = "?access_token=%s"

	Success = "SUCCESS"
	Fail    = "FAIL"
)

common

View Source
const (
	MaSessionInfoUrl = ApiDefaultHostUrl + "/sns/jscode2session?appid=%s&secret=%s&js_code=%s&grant_type=authorization_code"

	MaQrcodeUrl          = ApiDefaultHostUrl + "/cgi-bin/wxaapp/createwxaqrcode" + ApiSuffix
	MaQrWxaCodeUrl       = ApiDefaultHostUrl + "/wxa/getwxacode" + ApiSuffix
	MaQrCodeUnlimitedUrl = ApiDefaultHostUrl + "/wxa/getwxacodeunlimit" + ApiSuffix

	MaSetUserStorage = ApiDefaultHostUrl + "/wxa/set_user_storage?appid=%s&signature=%s&openid=%s&sig_method=%s"
)

ma

View Source
const (
	MpGetTicketUrl = ApiDefaultHostUrl + "/cgi-bin/ticket/getticket" + ApiSuffix + "&type="

	MpQrcodeUrl = ApiDefaultHostUrl + "/cgi-bin/qrcode/create" + ApiSuffix

	MpUserUpdateRemarkUrl = ApiDefaultHostUrl + "/cgi-bin/user/info/updateremark" + ApiSuffix
	MpUserInfoUrl         = ApiDefaultHostUrl + "/cgi-bin/user/info" + ApiSuffix + "&openid=%s&lang=%s"
	MpUserGetUrl          = ApiDefaultHostUrl + "/cgi-bin/user/get" + ApiSuffix + "&next_openid="
	MpUserInfoBatchGetUrl = ApiDefaultHostUrl + "/cgi-bin/user/info/batchget" + ApiSuffix
	MpUserChangeOpenidUrl = ApiDefaultHostUrl + "/cgi-bin/changeopenid"
)

mp

View Source
const (
	PayDefaultPayBaseUrl = "https://api.mch.weixin.qq.com"
	PayUnifiedOrder      = "/pay/unifiedorder"
	PayCloseOrder        = "/pay/closeorder"
	PayQueryOrder        = "/pay/orderquery"

	PayGetSandboxSignKey = "https://api.mch.weixin.qq.com/sandboxnew/pay/getsignkey"

	PayRefundUrl          = "/secapi/pay/refund"
	PayRefundUrlV2        = "/secapi/pay/refundv2"
	PayRefundSandboxUrl   = "/pay/refund"
	PayRefundSandboxUrlV2 = "/pay/refundv2"
	PayQueryRefundUrl     = "/pay/refundquery"
	PayQueryRefundUrlV2   = "/pay/refundqueryv2"

	EntPayUrl          = "/mmpaymkttransfers/promotion/transfers"
	EntPayQueryUrl     = "/mmpaymkttransfers/gettransferinfo"
	EntPayBankUrl      = "/mmpaysptrans/pay_bank"
	EntPayQueryBankUrl = "/mmpaysptrans/query_bank"

	EntSendEnterpriseRedPackUrl  = "/mmpaymkttransfers/sendworkwxredpack"
	EntQueryEnterpriseRedPackUrl = "/mmpaymkttransfers/queryworkwxredpack"
)

pay

View Source
const (
	PostXmlContentType  = "application/xml; charset=utf-8"
	PostJsonContentType = "application/json; charset=utf-8"
)

http header

Variables

This section is empty.

Functions

This section is empty.

Types

type AccessToken

type AccessToken struct {
	Err
	AccessToken string    `json:"access_token"`
	ExpiresIn   uint64    `json:"expires_in"`
	Time        time.Time `json:"time"`
}

小程序access_token

type Err

type Err struct {
	ErrCode uint64 `json:"errcode"`
	ErrMsg  string `json:"errmsg"`
}

接口返回错误

func (*Err) Error added in v0.5.0

func (e *Err) Error() string

type ErrMsg added in v0.5.0

type ErrMsg struct {
	Err
	Msg string `json:"msg"`
}

func ErrorOf added in v0.5.0

func ErrorOf(msg string, params ...interface{}) *ErrMsg

func (*ErrMsg) Error added in v0.5.0

func (e *ErrMsg) Error() string

type Service

type Service interface {
	// 执行Get请求
	Get(url string, args ...interface{}) ([]byte, error)
	// 执行Post请求
	Post(url string, contentType string, data interface{}, args ...interface{}) ([]byte, error)

	// Get 执行Get请求并将结果转成对象
	GetFor(v interface{}, url string, args ...interface{}) error
	// Post 执行Post请求并将结果转成对象
	PostFor(v interface{}, url string, contentType string, data interface{}, args ...interface{}) error
}

http请求

func NewService

func NewService() Service

func NewServiceFor added in v0.2.0

func NewServiceFor(client *http.Client) Service

func NewXmlService added in v0.2.0

func NewXmlService() Service

func NewXmlServiceFor added in v0.2.0

func NewXmlServiceFor(client *http.Client) Service

type ServiceImpl

type ServiceImpl struct {
	// contains filtered or unexported fields
}

http请求默认实现(json传参)

func (*ServiceImpl) Get

func (s *ServiceImpl) Get(url string, args ...interface{}) ([]byte, error)

func (*ServiceImpl) GetFor

func (s *ServiceImpl) GetFor(v interface{}, url string, args ...interface{}) error

func (*ServiceImpl) Post

func (s *ServiceImpl) Post(url string, contentType string, data interface{}, args ...interface{}) ([]byte, error)

func (*ServiceImpl) PostFor

func (s *ServiceImpl) PostFor(v interface{}, url string, contentType string, data interface{}, args ...interface{}) error

type WxAccessToken

type WxAccessToken interface {
	// 获取access_token
	GetAccessToken() (*AccessToken, error)
	// access_token是否过期, ture:是
	IsAccessTokenExpired() bool
	// 强制过期access_token
	ExpireAccessToken()
}

type WxConfig

type WxConfig interface {
	// 获取appId
	GetAppID() string
	// 获取密钥
	GetSecret() string
	// 获取access_token
	GetAccessToken() *AccessToken
	// 设置access_token
	SetAccessToken(*AccessToken)
}

配置的接口

type WxService

type WxService interface {
	Service
	// 获取access_token
	GetAccessToken() (*AccessToken, error)
	// 是否强制获取access_token
	ForceGetAccessToken(forceRefresh bool) (*AccessToken, error)

	// 配置读取
	GetWxConfig() WxConfig
	// 配置设置
	SetWxConfig(WxConfig)

	// 设置http请求方式
	SetHttpService(Service)
}

http请求,获取accessToken

type WxServiceImpl

type WxServiceImpl struct {
	// contains filtered or unexported fields
}

http请求默认实现

func (*WxServiceImpl) ExpireAccessToken

func (s *WxServiceImpl) ExpireAccessToken()

func (*WxServiceImpl) ForceGetAccessToken

func (s *WxServiceImpl) ForceGetAccessToken(forceRefresh bool) (*AccessToken, error)

func (*WxServiceImpl) Get

func (s *WxServiceImpl) Get(url string, args ...interface{}) ([]byte, error)

func (*WxServiceImpl) GetAccessToken

func (s *WxServiceImpl) GetAccessToken() (*AccessToken, error)

func (*WxServiceImpl) GetFor

func (s *WxServiceImpl) GetFor(v interface{}, url string, args ...interface{}) error

func (*WxServiceImpl) GetWxConfig

func (s *WxServiceImpl) GetWxConfig() WxConfig

func (*WxServiceImpl) IsAccessTokenExpired

func (s *WxServiceImpl) IsAccessTokenExpired() bool

func (*WxServiceImpl) Post

func (s *WxServiceImpl) Post(url string, contentType string, data interface{}, args ...interface{}) ([]byte, error)

func (*WxServiceImpl) PostFor

func (s *WxServiceImpl) PostFor(v interface{}, url string, contentType string, data interface{}, args ...interface{}) error

func (*WxServiceImpl) SetHttpService

func (s *WxServiceImpl) SetHttpService(service Service)

func (*WxServiceImpl) SetWxConfig

func (s *WxServiceImpl) SetWxConfig(config WxConfig)

type XmlServiceImpl added in v0.2.0

type XmlServiceImpl struct {
	// contains filtered or unexported fields
}

http请求默认实现(xml传参)

func (*XmlServiceImpl) Get added in v0.2.0

func (s *XmlServiceImpl) Get(url string, args ...interface{}) ([]byte, error)

func (*XmlServiceImpl) GetFor added in v0.2.0

func (s *XmlServiceImpl) GetFor(v interface{}, url string, args ...interface{}) error

func (*XmlServiceImpl) Post added in v0.2.0

func (s *XmlServiceImpl) Post(url string, contentType string, data interface{}, args ...interface{}) ([]byte, error)

func (*XmlServiceImpl) PostFor added in v0.2.0

func (s *XmlServiceImpl) PostFor(v interface{}, url string, contentType string, data interface{}, args ...interface{}) error

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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