parent
a0ed28bf12
commit
05a9a0041d
@ -1,40 +0,0 @@
|
||||
package wechatminiprogram
|
||||
|
||||
import (
|
||||
"crypto/sha1"
|
||||
"fmt"
|
||||
"gopkg.in/dtapps/go-library.v3/utils/gorandom"
|
||||
"io"
|
||||
"time"
|
||||
)
|
||||
|
||||
type ShareResponse 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"`
|
||||
}
|
||||
|
||||
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 {
|
||||
var response ShareResponse
|
||||
response.AppId = app.AppId
|
||||
response.NonceStr = gorandom.Alphanumeric(32)
|
||||
response.Timestamp = time.Now().Unix()
|
||||
response.Url = url
|
||||
response.RawString = fmt.Sprintf("jsapi_ticket=%v&noncestr=%v×tamp=%v&url=%v", app.JsapiTicket, response.NonceStr, response.Timestamp, response.Url)
|
||||
t := sha1.New()
|
||||
_, err := io.WriteString(t, response.RawString)
|
||||
response.Signature = fmt.Sprintf("%x", t.Sum(nil))
|
||||
return NewShareResult(response, err)
|
||||
}
|
@ -1,16 +1,36 @@
|
||||
package wechatoffice
|
||||
|
||||
import (
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"net/http"
|
||||
)
|
||||
|
||||
type MessageTemplateSendResponse struct {
|
||||
Errcode int `json:"errcode"`
|
||||
Errmsg string `json:"errmsg"`
|
||||
Msgid int `json:"msgid"`
|
||||
}
|
||||
|
||||
type MessageTemplateSendResult struct {
|
||||
Result MessageTemplateSendResponse // 结果
|
||||
Byte []byte // 内容
|
||||
Err error // 错误
|
||||
}
|
||||
|
||||
func NewMessageTemplateSendResult(result MessageTemplateSendResponse, byte []byte, err error) *MessageTemplateSendResult {
|
||||
return &MessageTemplateSendResult{Result: result, Byte: byte, Err: err}
|
||||
}
|
||||
|
||||
// MessageTemplateSend 模板消息
|
||||
// https://developers.weixin.qq.com/doc/offiaccount/Message_Management/Template_Message_Interface.html
|
||||
func (app *App) MessageTemplateSend(notMustParams ...Params) (body []byte, err error) {
|
||||
func (app *App) MessageTemplateSend(notMustParams ...Params) *MessageTemplateSendResult {
|
||||
// 参数
|
||||
params := app.NewParamsWith(notMustParams...)
|
||||
// 请求
|
||||
body, err = app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s", app.AccessToken), params, http.MethodPost)
|
||||
return
|
||||
body, err := app.request(fmt.Sprintf("https://api.weixin.qq.com/cgi-bin/message/template/send?access_token=%s", app.AccessToken), params, http.MethodPost)
|
||||
// 定义
|
||||
var response MessageTemplateSendResponse
|
||||
err = json.Unmarshal(body, &response)
|
||||
return NewMessageTemplateSendResult(response, body, err)
|
||||
}
|
||||
|
Loading…
Reference in new issue