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

82 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. type MpTempMsg struct {
  11. Appid string
  12. TemplateId string
  13. Url string
  14. Miniprogram string
  15. Data string
  16. }
  17. type UniformMessageReq struct {
  18. MiniAppid string
  19. Touser string
  20. MpTemplateMsg MpTempMsg
  21. }
  22. /**
  23. * 发送小程序统一服务消息,默认发送公众号消息
  24. * appid,secret 小程序ID 密钥
  25. * touser 小程序openid
  26. * mp_appid 关联公众号appid要求与小程序有绑定且同主体
  27. * temp_id 公众号模板id
  28. * url 跳转的url
  29. * mini_program 公众号模板消息所要跳转的小程序小程序的必须与公众号具有绑定关系
  30. * data 公众号模板消息的数据
  31. */
  32. func SendUniformMessage(dbname, site_id string, appid, secret, touser, mp_appid, temp_id, url, mini_program, data string, url ...string) (*WxApiRes, error) {
  33. conn, err := rpc_server_conn(url...)
  34. data["dbname"] = dbname
  35. data["site_id"] = site_id
  36. data["appid"] = appid
  37. data["secret"] = secret
  38. data["touser"] = touser
  39. data["mp_appid"] = mp_appid
  40. data["temp_id"] = temp_id
  41. data["url"] = url
  42. data["mini_program"] = mini_program
  43. data["data"] = data
  44. data_json, err := json.Marshal(data)
  45. if err != nil {
  46. return nil, err
  47. }
  48. encryData := crypter.DesEn(string(data_json), DES_KEY)
  49. now_int64 := time.Now().Unix()
  50. now := strconv.FormatInt(now_int64, 10)
  51. sign := Sign(encryData, now)
  52. req := &Request{
  53. proto.String(encryData),
  54. proto.String(now),
  55. proto.String(sign),
  56. nil}
  57. res := &Response{}
  58. err = conn.SendUniformMessage(req, res)
  59. if err != nil {
  60. return nil, err
  61. }
  62. return HandleRes(res)
  63. }