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

  1. package weixinrpc
  2. import (
  3. "encoding/json"
  4. "strconv"
  5. "time"
  6. "git.tetele.net/tgo/crypter"
  7. "github.com/golang/protobuf/proto"
  8. )
  9. /**
  10. * 发送小程序订阅服务消息
  11. * appid,secret 小程序ID 密钥
  12. * touser 小程序openid
  13. * mp_appid 关联公众号appid要求与小程序有绑定且同主体
  14. * temp_id 模板id
  15. * page 跳转的url
  16. * lang 进入小程序查看的语言类型支持zh_CN(简体中文)en_US(英文)zh_HK(繁体中文)zh_TW(繁体中文)默认为zh_CN
  17. * miniprogram_state 跳转小程序类型developer为开发版trial为体验版formal为正式版默认为正式版
  18. * data 公众号模板消息的数据
  19. */
  20. func SendMiniSubscribeMessage(dbname, site_id string, appid, secret, touser, temp_id, page string, miniprogram_state, lang string, data interface{}, url ...string) (*WxApiRes, error) {
  21. conn, err := rpc_server_conn(url...)
  22. message_data := SubscribeMessageReq{}
  23. message_data.SiteId = site_id
  24. message_data.Dbname = dbname
  25. message_data.Appid = appid
  26. message_data.Secret = secret
  27. message_data.Touser = touser
  28. message_data.TemplateId = temp_id
  29. message_data.Page = page
  30. message_data.MiniprogramState = miniprogram_state
  31. message_data.Lang = lang
  32. message_data.Data = data
  33. data_json, err := json.Marshal(message_data)
  34. if err != nil {
  35. return nil, err
  36. }
  37. encryData := crypter.DesEn(string(data_json), DES_KEY)
  38. now_int64 := time.Now().Unix()
  39. now := strconv.FormatInt(now_int64, 10)
  40. sign := Sign(encryData, now)
  41. req := &Request{
  42. proto.String(encryData),
  43. proto.String(now),
  44. proto.String(sign),
  45. nil}
  46. res := &Response{}
  47. err = conn.SendMiniappSubscribeMessage(req, res)
  48. if err != nil {
  49. return nil, err
  50. }
  51. return HandleRes(res)
  52. }