微信接口的RPC包
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.
 

83 lines
1.9 KiB

package weixinrpc
import (
"encoding/json"
"strconv"
"time"
"git.tetele.net/tgo/crypter"
"github.com/golang/protobuf/proto"
)
//公众号模板消息
type MpTempMsg struct {
Appid string
TemplateId string
Url string
Miniprogram string
Data string
}
type UniformMessageReq struct {
MiniAppid string
Touser string
MpTemplateMsg MpTempMsg
}
/**
* 发送小程序统一服务消息,默认发送公众号消息
* appid,secret 小程序ID 密钥
* touser 小程序openid
* mp_appid 关联公众号appid,要求与小程序有绑定且同主体
* temp_id 公众号模板id
* redirect_url 跳转的url
* mini_program 公众号模板消息所要跳转的小程序,小程序的必须与公众号具有绑定关系
* data 公众号模板消息的数据
*/
func SendUniformMessage(dbname, site_id string, appid, secret, touser, mp_appid, temp_id, redirect_url, mini_program, data string, url ...string) (*WxApiRes, error) {
conn, err := rpc_server_conn(url...)
uniform_message_data := UniformMessageReq{}
uniform_message_data.SiteId = site_id
uniform_message_data.Dbname = dbname
uniform_message_data.Appid = appid
uniform_message_data.Secret = secret
uniform_message_data.Touser = touser
uniform_message_data.MpAppid = mp_appid
uniform_message_data.TemplateId = temp_id
uniform_message_data.Url = redirect_url
uniform_message_data.MiniProgram = mini_program
uniform_message_data.Data = data
data_json, err := json.Marshal(uniform_message_data)
if err != nil {
return nil, err
}
encryData := crypter.DesEn(string(data_json), DES_KEY)
now_int64 := time.Now().Unix()
now := strconv.FormatInt(now_int64, 10)
sign := Sign(encryData, now)
req := &Request{
proto.String(encryData),
proto.String(now),
proto.String(sign),
nil}
res := &Response{}
err = conn.SendUniformMessage(req, res)
if err != nil {
return nil, err
}
return HandleRes(res)
}