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.
43 lines
1.1 KiB
43 lines
1.1 KiB
3 years ago
|
package wechatoffice
|
||
|
|
||
|
import (
|
||
|
"crypto/sha1"
|
||
|
"fmt"
|
||
2 years ago
|
"go.dtapp.net/library/gorandom"
|
||
3 years ago
|
"io"
|
||
|
"time"
|
||
|
)
|
||
|
|
||
3 years ago
|
type ShareResponse struct {
|
||
3 years ago
|
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"`
|
||
|
}
|
||
|
|
||
3 years ago
|
type ShareResult struct {
|
||
|
Result ShareResponse // 结果
|
||
|
Err error // 错误
|
||
|
}
|
||
|
|
||
|
func NewShareResult(result ShareResponse, err error) *ShareResult {
|
||
|
return &ShareResult{Result: result, Err: err}
|
||
|
}
|
||
|
|
||
|
func (app *App) Share(url string) *ShareResult {
|
||
2 years ago
|
app.accessToken = app.GetAccessToken()
|
||
|
app.jsapiTicket = app.GetJsapiTicket()
|
||
3 years ago
|
var response ShareResponse
|
||
2 years ago
|
response.AppId = app.appId
|
||
3 years ago
|
response.NonceStr = gorandom.Alphanumeric(32)
|
||
|
response.Timestamp = time.Now().Unix()
|
||
|
response.Url = url
|
||
2 years ago
|
response.RawString = fmt.Sprintf("jsapi_ticket=%v&noncestr=%v×tamp=%v&url=%v", app.jsapiTicket, response.NonceStr, response.Timestamp, response.Url)
|
||
3 years ago
|
t := sha1.New()
|
||
3 years ago
|
_, err := io.WriteString(t, response.RawString)
|
||
|
response.Signature = fmt.Sprintf("%x", t.Sum(nil))
|
||
|
return NewShareResult(response, err)
|
||
3 years ago
|
}
|