core

package
v1.0.5 Latest Latest
Warning

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

Go to latest
Published: Nov 5, 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 AccessTokenExpiresIn = "expires_in"

AccessTokenExpiresIn 过期

View Source
const AccessTokenSafeSeconds = 500

AccessTokenSafeSeconds token安全时间

Variables

This section is empty.

Functions

func BodyToMap added in v1.0.1

func BodyToMap(b []byte, d string) util.Map

BodyToMap transfer response body to map data

func ClientCredential added in v1.0.1

func ClientCredential(config *Config) util.Map

ClientCredential ...

func ClientSet added in v1.0.1

func ClientSet(setter ClientSetter, v []interface{}) bool

ClientSet ...

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 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 ParseBody added in v1.0.1

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

ParseBody get response data

func SaveEncodingTo added in v1.0.1

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

SaveEncodingTo ...

func SaveTo added in v1.0.1

func SaveTo(response Response, 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) SetClient added in v1.0.1

func (a *AccessToken) SetClient(client *Client)

SetClient ...

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() Response

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) Client added in v1.0.1

func (b *Base) Client() *Client

Client ...

func (*Base) GetCallbackIP

func (b *Base) GetCallbackIP() Response

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 ...

func (*Base) SetClient added in v1.0.1

func (b *Base) SetClient(client *Client)

SetClient ...

type Client

type Client struct {
	context.Context
}

Client Client

func ClientGet added in v1.0.1

func ClientGet(v []interface{}) *Client

ClientGet ...

func DefaultClient

func DefaultClient() *Client

DefaultClient result a client with default value

func NewClient

func NewClient(ctx context.Context) *Client

NewClient 创建一个client

func (*Client) Get added in v1.0.1

func (c *Client) Get(url string, query util.Map) Response

Get get请求

func (*Client) GetRaw added in v1.0.1

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

GetRaw get request result raw data

func (*Client) Post added in v1.0.1

func (c *Client) Post(url string, maps util.Map) Response

Post post请求

func (*Client) PostForm added in v1.0.1

func (c *Client) PostForm(url string, query util.Map, form interface{}) Response

PostForm post form request

func (*Client) PostJSON added in v1.0.1

func (c *Client) PostJSON(url string, query util.Map, json interface{}) Response

PostJSON json post请求

func (*Client) PostXML added in v1.0.1

func (c *Client) PostXML(url string, query util.Map, xml interface{}) Response

PostXML xml post请求

func (*Client) Request

func (c *Client) Request(url string, method string, ops util.Map) Response

Request 普通请求

func (*Client) RequestRaw

func (c *Client) RequestRaw(url string, method string, ops util.Map) []byte

RequestRaw raw请求

func (*Client) Upload added in v1.0.1

func (c *Client) Upload(url string, query, multi util.Map) Response

Upload upload请求

type ClientGetter added in v1.0.1

type ClientGetter interface {
	GetClient() *Client
}

ClientGetter ...

type ClientSetter added in v1.0.1

type ClientSetter interface {
	SetClient(*Client)
}

ClientSetter ...

type Config added in v1.0.1

type Config struct {
	*toml.Tree
}

Config Config Tree

func C added in v1.0.1

func C(p util.Map) *Config

C parse config from map

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 (*Config) Check added in v1.0.1

func (c *Config) Check(arr ...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(strings ...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, strings ...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) Set added in v1.0.1

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

Set set value

type CredentialSetter added in v1.0.1

type CredentialSetter interface {
}

CredentialSetter ...

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 Response added in v1.0.1

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

Response Response

func Err added in v1.0.1

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

Err return if response has error

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) Client added in v1.0.1

func (url *URL) Client() *Client

Client ...

func (*URL) SetAccessToken added in v1.0.1

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

SetAccessToken ...

func (*URL) SetClient added in v1.0.1

func (url *URL) SetClient(client *Client)

SetClient ...

func (*URL) ShortURL

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

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