Help us shape the future of Go! Take the 2026 Go Developer Survey

zwxoatoken

package module
v0.0.2 Latest Latest
Warning

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

Go to latest
Published: Oct 29, 2019 License: Apache-2.0 Imports: 10 Imported by: 0

README

zwxoatoken

获取微信公众号token

获取

go get -u -v github.com/zlyuancn/zwxoatoken

实例

    // 获取access_token
    at, err := GetAccessToken("your_appid", "your_secret")
    if err != nil {
        log.Fatal(err)
    }
    log.Println(at.AccessToken, at.ExpiresIn)

    // 获取jsapi_ticket
    jt, err := GetJsapiTicket(at.AccessToken)
    if err != nil {
        log.Fatal(err)
    }
    log.Println(jt.Ticket, jt.ExpiresIn)

    // 获取签名数据
    url := "http://yourdomain/route?parame=value#123"
    out := MakeSign(jt.Ticket, url)
    log.Println(out.Noncestr, out.Signature, out.Timestamp)

Documentation

Index

Constants

View Source
const (
	AccessTokenUri = "https://api.weixin.qq.com/cgi-bin/token?grant_type=%s&appid=%s&secret=%s"
	JsapiTicketUri = "https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=%s&type=jsapi"
)
View Source
const (
	GrantType = "client_credential"
)

Variables

View Source
var DefaultClient = &http.Client{
	Transport: &http.Transport{
		TLSClientConfig: &tls.Config{InsecureSkipVerify: true},
	}}

Functions

func Sha1

func Sha1(text string) string

Types

type AccessToken added in v0.0.2

type AccessToken struct {
	Errcode     int    `json:"errcode"`
	Errmsg      string `json:"errmsg"`
	AccessToken string `json:"access_token"`
	ExpiresIn   int    `json:"expires_in"`
}

func GetAccessToken

func GetAccessToken(appid, secret string) (*AccessToken, error)

获取公众号accesst_token

type JsapiTicket

type JsapiTicket struct {
	Errcode   int    `json:"errcode"`
	Errmsg    string `json:"errmsg"`
	Ticket    string `json:"ticket"`
	ExpiresIn int    `json:"expires_in"`
}

func GetJsapiTicket

func GetJsapiTicket(accesst_token string) (*JsapiTicket, error)

获取jsapi_ticket

type Signature

type Signature struct {
	Noncestr  string `json:"noncestr"`
	Signature string `json:"signature"`
	Timestamp int    `json:"timestamp"`
}

func MakeSign

func MakeSign(jsapi_ticket string, now_url string) *Signature

签名

微信 JS 接口签名校验工具地址: http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign

Jump to

Keyboard shortcuts

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