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

70 lines
1.7 KiB

package weixinrpc
import (
"encoding/json"
"strconv"
"time"
"git.tetele.net/tgo/crypter"
"github.com/golang/protobuf/proto"
)
/**
* 发送小程序订阅服务消息
* appid,secret 小程序ID 密钥
* touser 小程序openid
* mp_appid 关联公众号appid,要求与小程序有绑定且同主体
* temp_id 模板id
* page 跳转的url
* lang 进入小程序查看”的语言类型,支持zh_CN(简体中文)、en_US(英文)、zh_HK(繁体中文)、zh_TW(繁体中文),默认为zh_CN
* miniprogram_state 跳转小程序类型:developer为开发版;trial为体验版;formal为正式版;默认为正式版
* data 公众号模板消息的数据
*/
func SendMiniSubscribeMessage(dbname, site_id string, appid, secret, touser, temp_id, page string, miniprogram_state, lang string, data interface{}, url ...string) (*WxApiRes, error) {
conn, err := rpc_server_conn(url...)
message_data := SubscribeMessageReq{}
message_data.SiteId = site_id
message_data.Dbname = dbname
message_data.Appid = appid
message_data.Secret = secret
message_data.Touser = touser
message_data.TemplateId = temp_id
message_data.Page = page
message_data.MiniprogramState = miniprogram_state
message_data.Lang = lang
message_data.Data = data
data_json, err := json.Marshal(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.SendMiniappSubscribeMessage(req, res)
if err != nil {
return nil, err
}
return HandleRes(res)
}