wxsign

package module
v0.0.0-...-0fed058 Latest Latest
Warning

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

Go to latest
Published: Aug 29, 2016 License: MIT Imports: 8 Imported by: 0

README

wxsign

微信(weixin)自定义分享的签名版golang后端实现,自带ticket暂存机制

安装

go get github.com/EagleChen/wxsign

用法

appID := "aaa" // 微信公众号的appid 和 密钥
secret   := "bbb"
url := "www.qq.com" // 要分享的URL
signer := wxsign.NewSigner(appID, secret)
resp, _ := signer.GenSignature(url)
fmt.Printf("%+v\n", resp)

输出类似结果:

{NonceStr:A9FpXzp1LGIehp1b Timestamp:1470249579 Signature:cb8433318a68f76c381be2a1f277f2d337b41dfb}

说明

根据微信官方文档,token和ticket需要缓存在客户端,不要每次生成签名都请求新的。这个缓存机制已经实现。

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Response

type Response struct {
	NonceStr  string `json:"nonceStr"`
	Timestamp int64  `json:"timestamp"`
	Signature string `json:"signature"`
}

Response contains values for configuring wx.config in front end see: http://mp.weixin.qq.com/wiki/7/aaa137b55fb2e0456bf8dd9148dd613f.html

type WxSigner

type WxSigner struct {
	TokenURL           string
	SignatureURLFormat string
	Ticket             string
	ExpireTime         int64
}

WxSigner is the struct for generating weixin signature

func NewSigner

func NewSigner(appID, secret string, urls ...string) *WxSigner

NewSigner creates a WxSigner. AppID and secret are mandatory

func (*WxSigner) GenSignature

func (w *WxSigner) GenSignature(url string) (Response, error)

GenSignature generates the signature response for a given url

func (*WxSigner) RequestTicket

func (w *WxSigner) RequestTicket() (string, error)

RequestTicket sends http requests to weixin server to fetch json api ticket In most cases, users don't need to call this method

Jump to

Keyboard shortcuts

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