core

package
v1.1.7 Latest Latest
Warning

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

Go to latest
Published: Nov 18, 2018 License: MIT Imports: 24 Imported by: 1

Documentation

Index

Constants

View Source
const (
	DataTypeXML       = "xml"
	DataTypeJSON      = "json"
	DataTypeQuery     = "query"
	DataTypeForm      = "form_params"
	DataTypeFile      = "file"
	DataTypeMultipart = "multipart"
	DataTypeSecurity  = "security"
)

data types

View Source
const (
	MPDomain   = "https://mp.weixin.qq.com"
	BaseDomain = "https://api.mch.weixin.qq.com"
	APIWeixin  = "https://api.weixin.qq.com"
	API2Domain = "https://api2.mch.weixin.qq.com"
	HKDomain   = "https://apihk.mch.weixin.qq.com"
	USDomain   = "https://apius.mch.weixin.qq.com"

	FileAPIWeixin = "http://file.api.weixin.qq.com"
)

domain defines

View Source
const AccessTokenSafeSeconds = 500

AccessTokenSafeSeconds token安全时间

View Source
const GET = "GET"

GET ...

View Source
const POST = "POST"

POST ...

Variables

View Source
var ErrNilRequestBody = errors.New("nil request body")

ErrNilRequestBody ...

Functions

func ClientCredential added in v1.0.1

func ClientCredential(config *Config) util.Map

ClientCredential ...

func Connect added in v1.0.1

func Connect(domain string, uri string) string

Connect 拼接地址

func CredentialGet added in v1.0.1

func CredentialGet(v []interface{}) util.Map

CredentialGet ...

func DomainHost

func DomainHost(domain string) string

DomainHost get host domain

func GetClientIP

func GetClientIP(r *http.Request) string

GetClientIP 取得客户端IP

func GetRaw added in v1.1.2

func GetRaw(url string, query util.Map) []byte

GetRaw get请求 返回[]byte

func GetServerIP

func GetServerIP() string

GetServerIP 获取服务端IP

func KeyMap

func KeyMap(at *AccessToken) (util.Map, error)

KeyMap get accessToken's key,value with map

func Link(uri string, host ...string) string

Link link domain address

func MustKeyMap

func MustKeyMap(at *AccessToken) util.Map

MustKeyMap get accessToken's key,value with map when nil or error return nil map

func ParseRequest added in v1.1.1

func ParseRequest(r *http.Request) ([]byte, error)

ParseRequest ...

func ParseResponse added in v1.1.2

func ParseResponse(r *http.Response) ([]byte, error)

ParseResponse get response data

func RequestRaw added in v1.1.2

func RequestRaw(method, url string, option util.Map) []byte

RequestRaw ...

func RequestToMap added in v1.1.1

func RequestToMap(r *http.Request) (util.Map, error)

RequestToMap ...

func SaveEncodingTo added in v1.0.1

func SaveEncodingTo(response Responder, path string, t transform.Transformer) error

SaveEncodingTo ...

func SaveTo added in v1.0.1

func SaveTo(response Responder, path string) error

SaveTo ...

func WriteJSON added in v1.0.1

func WriteJSON(w http.ResponseWriter, status int, obj interface{}) error

WriteJSON 将参数obj作为json返回

Types

type AccessToken

type AccessToken struct {
	URL      string
	TokenKey string
	// contains filtered or unexported fields
}

AccessToken AccessToken

func NewAccessToken

func NewAccessToken(v ...interface{}) *AccessToken

NewAccessToken NewAccessToken

func (*AccessToken) Credentials added in v1.0.1

func (a *AccessToken) Credentials() util.Map

Credentials ...

func (*AccessToken) GetRefreshedToken

func (a *AccessToken) GetRefreshedToken() *Token

GetRefreshedToken 获取刷新token

func (*AccessToken) GetToken

func (a *AccessToken) GetToken() *Token

GetToken 获取token

func (*AccessToken) GetTokenWithRefresh

func (a *AccessToken) GetTokenWithRefresh() *Token

GetTokenWithRefresh 重新获取token

func (*AccessToken) Refresh

func (a *AccessToken) Refresh() *AccessToken

Refresh 刷新AccessToken

func (*AccessToken) RequestToken

func (a *AccessToken) RequestToken(credentials string) *Token

RequestToken 请求获取token

func (*AccessToken) SetCredentials added in v1.0.1

func (a *AccessToken) SetCredentials(p util.Map) *AccessToken

SetCredentials set request credential

func (*AccessToken) SetToken

func (a *AccessToken) SetToken(token string) *AccessToken

SetToken set string accessToken

func (*AccessToken) SetTokenWithLife

func (a *AccessToken) SetTokenWithLife(token string, lifeTime time.Time) *AccessToken

SetTokenWithLife set string accessToken with life time

type Base

type Base struct {
	*Config
	// contains filtered or unexported fields
}

Base 基础

func NewBase added in v1.0.1

func NewBase(config *Config, v ...interface{}) *Base

NewBase NewBase Deprecated: Base is moved to official_account.Base

func (*Base) AccessToken added in v1.0.1

func (b *Base) AccessToken() *AccessToken

AccessToken ...

func (*Base) ClearQuota

func (b *Base) ClearQuota() Responder

ClearQuota 公众号的所有api调用(包括第三方帮其调用)次数进行清零 Deprecated: ClearQuota is moved to official_account.Base 公众号调用或第三方平台帮公众号调用对公众号的所有api调用(包括第三方帮其调用)次数进行清零: HTTP请求:POST HTTP调用: https://api.weixin.qq.com/cgi-bin/clear_quota?access_token=ACCESS_TOKEN

func (*Base) GetCallbackIP

func (b *Base) GetCallbackIP() Responder

GetCallbackIP 请求微信的服务器IP列表 Deprecated: GetCallbackIP is moved to official_account.Base 接口调用请求说明 http请求方式: GET https://api.weixin.qq.com/cgi-bin/getcallbackip?access_token=ACCESS_TOKEN

func (*Base) SetAccessToken added in v1.0.1

func (b *Base) SetAccessToken(accessToken *AccessToken)

SetAccessToken ...

type Config added in v1.0.1

type Config struct {
	*toml.Tree
}

Config Config Tree

func DefaultConfig added in v1.0.1

func DefaultConfig() *Config

DefaultConfig get the default config from cache

func LoadConfig added in v1.0.1

func LoadConfig(f string) (*Config, error)

LoadConfig get config tree with file name

func NewConfig added in v1.0.1

func NewConfig(tree *toml.Tree) *Config

NewConfig create a new null config

func NilConfig added in v1.1.2

func NilConfig() *Config

NilConfig ...

func (*Config) Check added in v1.0.1

func (c *Config) Check(s ...string) int

Check check all input keys return -1 if all is exist return index when not found

func (*Config) DeepGet added in v1.0.1

func (c *Config) DeepGet(s ...string) interface{}

DeepGet get an interface from config when was in values

func (*Config) DeepGetD added in v1.0.1

func (c *Config) DeepGetD(def string, s ...string) interface{}

DeepGetD get an interface from config when was in values

func (*Config) Get added in v1.0.1

func (c *Config) Get(s string) interface{}

Get get an interface from config

func (*Config) GetArray added in v1.0.1

func (c *Config) GetArray(key string) []interface{}

GetArray return array

func (*Config) GetArrayD added in v1.0.1

func (c *Config) GetArrayD(key string, d []interface{}) []interface{}

GetArrayD return array with default value

func (*Config) GetBool added in v1.0.1

func (c *Config) GetBool(s string) bool

GetBool get bool value

func (*Config) GetBoolD added in v1.0.1

func (c *Config) GetBoolD(s string, d bool) bool

GetBoolD get bool with default value

func (*Config) GetD added in v1.0.1

func (c *Config) GetD(s string, d interface{}) interface{}

GetD get interface with default value

func (*Config) GetInt added in v1.0.1

func (c *Config) GetInt(s string) int64

GetInt get int value

func (*Config) GetIntD added in v1.0.1

func (c *Config) GetIntD(s string, d int64) int64

GetIntD get int with default value

func (*Config) GetString added in v1.0.1

func (c *Config) GetString(s string) string

GetString get string with out default value

func (*Config) GetStringArray added in v1.0.1

func (c *Config) GetStringArray(key string) []string

GetStringArray return string array

func (*Config) GetStringArrayD added in v1.0.1

func (c *Config) GetStringArrayD(key string, d []string) []string

GetStringArrayD return string array with default value

func (*Config) GetStringD added in v1.0.1

func (c *Config) GetStringD(s, d string) string

GetStringD get string with default value

func (*Config) GetSubConfig added in v1.0.1

func (c *Config) GetSubConfig(s string) *Config

GetSubConfig get sub config from current config

func (*Config) GetTree added in v1.0.1

func (c *Config) GetTree(s string) interface{}

GetTree get config tree

func (*Config) IsNil added in v1.1.2

func (c *Config) IsNil() bool

IsNil ...

func (*Config) Set added in v1.0.1

func (c *Config) Set(k string, v interface{}) *Config

Set set value

type JSSDK added in v1.1.2

type JSSDK struct {
	*Config

	URL      string
	CacheKey func() string
	// contains filtered or unexported fields
}

JSSDK JSSDK

func NewJSSDK added in v1.1.2

func NewJSSDK(config *Config) *JSSDK

NewJSSDK NewJSSDK

func (*JSSDK) AppConfig added in v1.1.2

func (j *JSSDK) AppConfig(pid string) util.Map

AppConfig app 设置

func (*JSSDK) BridgeConfig added in v1.1.2

func (j *JSSDK) BridgeConfig(pid string) util.Map

BridgeConfig bridge 设置

func (*JSSDK) BuildConfig added in v1.1.2

func (j *JSSDK) BuildConfig(maps util.Map) util.Map

BuildConfig ...

func (*JSSDK) GetTicket added in v1.1.2

func (j *JSSDK) GetTicket(genre string, refresh bool) string

GetTicket ...

func (*JSSDK) SdkConfig added in v1.1.2

func (j *JSSDK) SdkConfig(pid string) util.Map

SdkConfig sdk 设置

func (*JSSDK) SetTicket added in v1.1.2

func (j *JSSDK) SetTicket(ticket *Ticket)

SetTicket ...

func (*JSSDK) ShareAddressConfig added in v1.1.2

func (j *JSSDK) ShareAddressConfig(v interface{}) util.Map

ShareAddressConfig ...

参数:token
类型:string或*core.AccessToken

func (*JSSDK) Ticket added in v1.1.2

func (j *JSSDK) Ticket() *Ticket

Ticket ...

type MediaType

type MediaType string

MediaType MediaType

const (
	MediaTypeImage MediaType = "image"
	MediaTypeVoice MediaType = "voice"
	MediaTypeVideo MediaType = "video"
	MediaTypeThumb MediaType = "thumb"
)

media types

func (MediaType) String

func (m MediaType) String() string

String transfer MediaType to string

type Message

type Message struct {
	message.Message
	/*message*/
	Content      message.CDATA      `xml:"content"`
	PicURL       message.CDATA      `xml:"pic_url"`        // 图片链接(由系统生成)
	MediaID      message.CDATA      `xml:"media_id"`       // 图片消息媒体id,可以调用多媒体文件下载接口拉取数据。
	Title        message.CDATA      `xml:"title"`          // 标题
	AppID        message.CDATA      `xml:"app_id"`         // 小程序appid
	PagePath     message.CDATA      `xml:"page_path"`      // 小程序页面路径
	ThumbURL     message.CDATA      `xml:"thumb_url"`      // 封面图片的临时cdn链接
	ThumbMediaID message.CDATA      `xml:"thumb_media_id"` // 封面图片的临时素材id
	Items        []*message.NewItem `xml:"items"`
	Format       message.CDATA      `xml:"format"`      // 语音格式,如amr,speex等
	Recognition  message.CDATA      `xml:"recognition"` // 语音识别结果,UTF8编码
	LocationX    float64            `xml:"location_x"`
	LocationY    float64            `xml:"location_y"`
	Scale        int64              `xml:"scale"`
	Label        message.CDATA      `xml:"label"`
	Description  message.CDATA      `xml:"description"` // 消息描述
	URL          message.CDATA      `xml:"url"`
	/*event*/
	message.Event
	EventKey  message.CDATA `xml:"event_key"` // 事件KEY值,qrscene_为前缀,后面为二维码的参数值
	Ticket    message.CDATA `xml:"ticket"`    // 二维码的ticket,可用来换取二维码图片
	Latitude  float64       `xml:"latitude"`  // 地理位置纬度
	Longitude float64       `xml:"longitude"` // 地理位置经度
	Precision float64       `xml:"precision"` // 地理位置精度

	MenuID message.CDATA `xml:"menu_id"` // 指菜单ID,如果是个性化菜单,则可以通过这个字段,知道是哪个规则的菜单被点击了。

	ScanCodeInfo     message.ScanCodeInfo     `xml:"scan_code_info"`     // 扫描信息
	SendPicsInfo     message.SendPicsInfo     `xml:"send_pics_info"`     // 发送的图片信息
	SendLocationInfo message.SendLocationInfo `xml:"send_location_info"` // 发送的位置信息

	Status      message.CDATA `xml:"status"`       // 	发送状态为成功
	ExpiredTime int64         `xml:"expired_time"` // 有效期 (整形),指的是时间戳,将于该时间戳认证过期
	FailTime    int64         `xml:"fail_time"`    // 失败发生时间 (整形),时间戳
	FailReason  message.CDATA `xml:"fail_reason"`  // 认证失败的原因
	// 名称认证成功(即命名成功)
	UniqID      message.CDATA `xml:"uniq_id"`
	PoiID       message.CDATA `xml:"poi_id"`
	Result      message.CDATA `xml:"result"`
	Msg         message.CDATA `xml:"msg"`
	SessionFrom message.CDATA `xml:"session_from"`

	OrderID     message.CDATA `xml:"order_id"`
	OrderStatus int64         `xml:"order_status"`
	ProductID   message.CDATA `xml:"product_id"`
	SkuInfo     message.CDATA `xml:"sku_info"`
}

Message 回调消息结构

func (*Message) GetType

func (m *Message) GetType() message.MsgType

GetType 获取消息类型

func (*Message) SetType

func (m *Message) SetType(msgType message.MsgType) *Message

SetType 设置消息类型

type MessageCallback

type MessageCallback func(message *Message) message.Messager

MessageCallback 消息回调函数定义

type PaymentCallback

type PaymentCallback func(p util.Map) bool

PaymentCallback 支付回调函数定义

type RequestBuildFunc added in v1.1.2

type RequestBuildFunc func(url, method string, i interface{}) *http.Request

type Requester added in v1.1.2

type Requester interface {
	Do(ctx context.Context) Responder
}

Requester ...

type Responder added in v1.1.2

type Responder interface {
	ToMap() util.Map
	Bytes() []byte
	Error() error
}

Responder Responder

func CastToResponse added in v1.1.2

func CastToResponse(resp *http.Response) Responder

CastToResponse ...

func Err added in v1.0.1

func Err(data []byte, err error) Responder

Err return if response has error

func Get added in v1.1.2

func Get(url string, query util.Map) Responder

Get get请求

func Post added in v1.1.2

func Post(url string, maps util.Map) Responder

Post post请求

func PostForm added in v1.1.2

func PostForm(url string, query util.Map, form interface{}) Responder

PostForm post form request

func PostJSON added in v1.1.2

func PostJSON(url string, query util.Map, json interface{}) Responder

PostJSON json post请求

func PostXML added in v1.1.2

func PostXML(url string, query util.Map, xml interface{}) Responder

PostXML xml post请求

func Request added in v1.1.2

func Request(method string, url string, option util.Map) Responder

Request ...

func RequestWithContext added in v1.1.2

func RequestWithContext(ctx context.Context, method string, url string, option util.Map) Responder

RequestWithContext ...

func Upload added in v1.1.2

func Upload(url string, query, multi util.Map) Responder

Upload upload请求

type Server added in v1.1.1

type Server struct {
}

Server ...

func (*Server) ServeHTTP added in v1.1.1

func (s *Server) ServeHTTP(writer http.ResponseWriter, req *http.Request)

ServeHTTP ...

type Ticket added in v1.1.2

type Ticket struct {
	*Config
	// contains filtered or unexported fields
}

Ticket Ticket

func NewTicket added in v1.1.2

func NewTicket(config *Config, v ...interface{}) *Ticket

NewTicket NewTicket

func (*Ticket) AccessToken added in v1.1.2

func (t *Ticket) AccessToken() *AccessToken

AccessToken ...

func (*Ticket) Get added in v1.1.2

func (t *Ticket) Get(typ string) Responder

Get 获取api_ticket http请求方式: GET https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=ACCESS_TOKEN&type=wx_card

func (*Ticket) SetAccessToken added in v1.1.2

func (t *Ticket) SetAccessToken(accessToken *AccessToken)

SetAccessToken ...

type Token

type Token struct {
	// AccessToken is the accessToken that authorizes and authenticates
	// the requests.
	AccessToken string `json:"access_token"`

	// RefreshToken is a accessToken that's used by the application
	// (as opposed to the user) to refresh the access accessToken
	// if it expires.
	RefreshToken string `json:"refresh_token"`

	// Expiry is the optional expiration time of the access accessToken.
	//
	// If zero, TokenSource implementations will reuse the same
	// accessToken forever and RefreshToken or equivalent
	// mechanisms for that TokenSource will not be used.
	ExpiresIn int64 `json:"expires_in"`

	// wechat openid
	OpenID string `json:"openid"`

	// wechat scope
	Scope string `json:"scope"`
	// Raw optionally contains extra metadata from the server
	// when updating a accessToken.
	Raw interface{}
}

Token represents the credentials used to authorize the requests to access protected resources on the OAuth 2.0 provider's backend.

This type is a mirror of oauth2.Token and exists to break an otherwise-circular dependency. Other internal packages should convert this Token into an oauth2.Token before use.

func ParseToken

func ParseToken(j string) (*Token, error)

ParseToken parse accessToken from string

func (*Token) GetExpiresIn

func (t *Token) GetExpiresIn() time.Time

GetExpiresIn get expires time

func (*Token) GetScopes

func (t *Token) GetScopes() []string

GetScopes get accessToken scopes for get accessToken

func (*Token) KeyMap

func (t *Token) KeyMap() util.Map

KeyMap get accessToken's key,value with map

func (*Token) SetExpiresIn

func (t *Token) SetExpiresIn(ti time.Time) *Token

SetExpiresIn set expires time

func (*Token) SetScopes

func (t *Token) SetScopes(s []string) *Token

SetScopes set accessToken scopes for get accessToken

func (*Token) ToJSON

func (t *Token) ToJSON() string

ToJSON transfer accessToken to json

type URL

type URL struct {
	*Config
	// contains filtered or unexported fields
}

URL URL

func NewURL

func NewURL(config *Config, v ...interface{}) *URL

NewURL NewURL

func (*URL) AccessToken added in v1.0.1

func (url *URL) AccessToken() *AccessToken

AccessToken ...

func (*URL) SetAccessToken added in v1.0.1

func (url *URL) SetAccessToken(accessToken *AccessToken)

SetAccessToken ...

func (*URL) ShortURL

func (url *URL) ShortURL(long string) Responder

ShortURL 转换短链接 https://apihk.mch.weixin.qq.com/tools/shorturl (建议接入点:东南亚) https://apius.mch.weixin.qq.com/tools/shorturl (建议接入点:其它) https://api.mch.weixin.qq.com/tools/shorturl (建议接入点:中国国内) 请求参数 URL链接 long_url 是 String(512、 weixin://wxpay/bizpayurl?sign=XXXXX&appid=XXXXX&mch_id=XXXXX&product_id=XXXXXX&time_stamp=XXXXXX&nonce_str=XXXXX 需要转换的URL,签名用原串,传输需URLencode 返回结果 返回状态码 return_code 是 String(16) SUCCESS/FAIL URL链接 short_url 是 String(64) weixin://wxpay/s/XXXXXX 转换后的URL

type UserID

type UserID struct {
	OpenID string `json:"openid"`
	Lang   string `json:"lang,omitempty"`
}

UserID UserID

type UserInfo

type UserInfo struct {
	City           string   `json:"city"`
	Country        string   `json:"country"`
	HeadImgURL     string   `json:"headimgurl"`
	Language       string   `json:"language"`
	Nickname       string   `json:"nickname"`
	Openid         string   `json:"openid"`
	Privilege      []string `json:"privilege"`
	Province       string   `json:"province"`
	Sex            uint     `json:"sex"`
	Subscribe      int      `json:"subscribe"`
	SubscribeTime  uint32   `json:"subscribe_time"`
	UnionID        string   `json:"unionid"`
	Remark         string   `json:"remark"`
	GroupID        int      `json:"groupid"`
	TagIDList      []int    `json:"tagid_list"`
	SubscribeScene string   `json:"subscribe_scene"`
	QrScene        int      `json:"qr_scene"`
	QrSceneStr     string   `json:"qr_scene_str"`
}

UserInfo UserInfo

type WriteAble

type WriteAble interface {
	ToBytes() []byte
}

WriteAble WriteAble

Directories

Path Synopsis

Jump to

Keyboard shortcuts

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