You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
31 lines
813 B
31 lines
813 B
2 years ago
|
package wechatoffice
|
||
|
|
||
|
import (
|
||
|
"crypto/sha1"
|
||
|
"fmt"
|
||
|
"gopkg.in/dtapps/go-library.v3/utils/gorandom"
|
||
|
"io"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
|
type ShareResult struct {
|
||
|
AppId string `json:"app_id"`
|
||
|
NonceStr string `json:"nonce_str"`
|
||
|
Timestamp int64 `json:"timestamp"`
|
||
|
Url string `json:"url"`
|
||
|
RawString string `json:"raw_string"`
|
||
|
Signature string `json:"signature"`
|
||
|
}
|
||
|
|
||
|
func (app *App) Share(url string) (result ShareResult) {
|
||
|
result.AppId = app.AppId
|
||
|
result.NonceStr = gorandom.Alphanumeric(32)
|
||
|
result.Timestamp = time.Now().Unix()
|
||
|
result.Url = url
|
||
|
result.RawString = fmt.Sprintf("jsapi_ticket=%v&noncestr=%v×tamp=%v&url=%v", app.JsapiTicket, result.NonceStr, result.Timestamp, result.Url)
|
||
|
t := sha1.New()
|
||
|
io.WriteString(t, result.RawString)
|
||
|
result.Signature = fmt.Sprintf("%x", t.Sum(nil))
|
||
|
return result
|
||
|
}
|