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

69 lines
1.7 KiB

3 years ago
  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. * redirect_url 跳转的url
  16. * mini_program 公众号模板消息所要跳转的小程序小程序的必须与公众号具有绑定关系
  17. * data 公众号模板消息的数据
  18. */
  19. func SendUniformMessage(dbname, site_id string, appid, secret, touser, mp_appid, temp_id, redirect_url string, mini_program, data interface{}, url ...string) (*WxApiRes, error) {
  20. conn, err := rpc_server_conn(url...)
  21. uniform_message_data := UniformMessageReq{}
  22. uniform_message_data.SiteId = site_id
  23. uniform_message_data.Dbname = dbname
  24. uniform_message_data.Appid = appid
  25. uniform_message_data.Secret = secret
  26. uniform_message_data.Touser = touser
  27. uniform_message_data.MpAppid = mp_appid
  28. uniform_message_data.TemplateId = temp_id
  29. uniform_message_data.Url = redirect_url
  30. uniform_message_data.MiniProgram = mini_program
  31. uniform_message_data.Data = data
  32. data_json, err := json.Marshal(uniform_message_data)
  33. if err != nil {
  34. return nil, err
  35. }
  36. encryData := crypter.DesEn(string(data_json), DES_KEY)
  37. now_int64 := time.Now().Unix()
  38. now := strconv.FormatInt(now_int64, 10)
  39. sign := Sign(encryData, now)
  40. req := &Request{
  41. proto.String(encryData),
  42. proto.String(now),
  43. proto.String(sign),
  44. nil}
  45. res := &Response{}
  46. err = conn.SendUniformMessage(req, res)
  47. if err != nil {
  48. return nil, err
  49. }
  50. return HandleRes(res)
  51. }