forked from chanxuehong/wechat
-
Notifications
You must be signed in to change notification settings - Fork 0
/
sign.go
33 lines (27 loc) · 1001 Bytes
/
sign.go
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
// @description wechat 是腾讯微信公众平台 api 的 golang 语言封装
// @link https://github.com/chanxuehong/wechat for the canonical source repository
// @license https://github.com/chanxuehong/wechat/blob/master/LICENSE
// @authors chanxuehong(chanxuehong@gmail.com)
package jssdk
import (
"crypto/sha1"
"encoding/hex"
)
// 微信 js-sdk wx.config 的参数签名.
func WXConfigSign(jsapiTicket, nonceStr, timestamp, url string) (signature string) {
n := len("jsapi_ticket=") + len(jsapiTicket) +
len("&noncestr=") + len(nonceStr) +
len("×tamp=") + len(timestamp) +
len("&url=") + len(url)
buf := make([]byte, 0, n)
buf = append(buf, "jsapi_ticket="...)
buf = append(buf, jsapiTicket...)
buf = append(buf, "&noncestr="...)
buf = append(buf, nonceStr...)
buf = append(buf, "×tamp="...)
buf = append(buf, timestamp...)
buf = append(buf, "&url="...)
buf = append(buf, url...)
hashsum := sha1.Sum(buf)
return hex.EncodeToString(hashsum[:])
}