common

package
v0.6.2 Latest Latest
Warning

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

Go to latest
Published: Nov 14, 2020 License: Apache-2.0 Imports: 11 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
	MaGetPaidUnionIdUrl  = ApiDefaultHostUrl + "/wxa/getpaidunionid" + ApiSuffix

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

	MaGetPubTemplateTitleListUrl    = ApiDefaultHostUrl + "/wxaapi/newtmpl/getpubtemplatetitles" + ApiSuffix
	MaGetPubTemplateKeyWordsByIdUrl = ApiDefaultHostUrl + "/wxaapi/newtmpl/getpubtemplatekeywords" + ApiSuffix
	MaTemplateListUrl               = ApiDefaultHostUrl + "/wxaapi/newtmpl/gettemplate" + ApiSuffix
	MaGetCategoryUrl                = ApiDefaultHostUrl + "/wxaapi/newtmpl/getcategory" + ApiSuffix
	MaTemplateDelUrl                = ApiDefaultHostUrl + "/wxaapi/newtmpl/deltemplate" + ApiSuffix
	MaTemplateAddUrl                = ApiDefaultHostUrl + "/wxaapi/newtmpl/addtemplate" + ApiSuffix

	MaSubscribeMsgSendUrl = ApiDefaultHostUrl + "/cgi-bin/message/subscribe/send" + ApiSuffix
	MaUniformMsgSendUrl   = ApiDefaultHostUrl + "/cgi-bin/message/wxopen/template/uniform_send" + ApiSuffix
	MaKefuMessageSendUrl  = ApiDefaultHostUrl + "/cgi-bin/message/custom/send" + ApiSuffix
	MaUpdatableMsgSendUrl = ApiDefaultHostUrl + "/cgi-bin/message/wxopen/updatablemsg/send" + ApiSuffix
	MaActivityIdCreateUrl = ApiDefaultHostUrl + "/cgi-bin/message/wxopen/activityid/create" + ApiSuffix

	MaCreateRoom  = ApiDefaultHostUrl + "/wxaapi/broadcast/room/create" + ApiSuffix
	MaEditRoom    = ApiDefaultHostUrl + "/wxaapi/broadcast/room/editroom" + ApiSuffix
	MaGetLiveInfo = ApiDefaultHostUrl + "/wxa/business/getliveinfo" + ApiSuffix
	MaAddGoods    = ApiDefaultHostUrl + "/wxaapi/broadcast/room/addgoods" + ApiSuffix
)

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"`
}

自定义error

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 Ticket added in v0.6.1

type Ticket struct {
	Err
	Ticket    string    `json:"ticket"`
	ExpiresIn uint64    `json:"expires_in"`
	Time      time.Time `json:"time"`
	Type      string    `json:"type"`
}

授权页ticket

type TicketType added in v0.6.1

type TicketType string

ticket类型

const (
	JSAPI  TicketType = "jsapi"
	SDK    TicketType = "2"
	WxCard TicketType = "wx_card"
)

type WxAccessToken

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

access_token接口

type WxConfig

type WxConfig interface {
	// 获取appId
	GetAppID() string
	// 获取密钥
	GetSecret() string

	// 获取access_token
	GetAccessToken() *AccessToken
	// 设置access_token
	SetAccessToken(*AccessToken)

	// 获取Ticket
	GetWxTicket() WxTicket
}

配置的接口

type WxJsapi added in v0.6.1

type WxJsapi interface {
	// 获得jsapi_ticket,不强制刷新jsapi_ticket.
	GetJsapiTicket() (*Ticket, error)
	/* 获得jsapi_ticket.
	   获得时会检查jsapiToken是否过期,如果过期了,那么就刷新一下,否则就什么都不干
	   详情请见:http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN */
	ForceGetJsapiTicket(bool) (*Ticket, error)
	// 获得ticket,不强制刷新ticket.
	GetTicket(TicketType) (*Ticket, error)
	// 获得时会检查 Token是否过期,如果过期了,那么就刷新一下,否则就什么都不干
	ForceGetTicket(ticketType TicketType, forceRefresh bool) (*Ticket, error)
	/* 创建调用jsapi时所需要的签名.
	   详情请见:http://mp.weixin.qq.com/wiki?t=resource/res_main&id=mp1421141115&token=&lang=zh_CN */
	CreateJsapiSignature(url string) (*WxJsapiSignature, error)
}

type WxJsapiSignature added in v0.6.1

type WxJsapiSignature struct {
	AppId     string `json:"app_id"`
	NonceStr  string `json:"nonce_str"`
	Timestamp string `json:"timestamp"`
	Url       string `json:"url"`
	Signature string `json:"signature"`
}

jspai signature.

func CreateJsapiSignature added in v0.6.1

func CreateJsapiSignature(url, appId, ticket string) (*WxJsapiSignature, error)

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)
}

wxAPI,获取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 WxTicket added in v0.6.1

type WxTicket interface {
	// 获取Ticket
	GetTicket(TicketType) *Ticket
	// 更新Ticket
	UpdateTicket(TicketType, *Ticket)
	// Ticket是否过期
	IsTicketExpired(TicketType) bool
	// 直接过期Ticket
	ExpireTicket(TicketType)
}

type WxTicketImpl added in v0.6.1

type WxTicketImpl struct {
	JsapiTicket  *Ticket
	SdkTicket    *Ticket
	WxCardTicket *Ticket
}

func (*WxTicketImpl) ExpireTicket added in v0.6.1

func (c *WxTicketImpl) ExpireTicket(ticketType TicketType)

func (*WxTicketImpl) GetTicket added in v0.6.1

func (c *WxTicketImpl) GetTicket(ticketType TicketType) *Ticket

func (*WxTicketImpl) IsTicketExpired added in v0.6.1

func (c *WxTicketImpl) IsTicketExpired(ticketType TicketType) bool

func (*WxTicketImpl) UpdateTicket added in v0.6.1

func (c *WxTicketImpl) UpdateTicket(ticketType TicketType, ticket *Ticket)

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