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

125 lines
1.9 KiB

3 years ago
3 years ago
3 years ago
3 years ago
  1. package weixinrpc
  2. import (
  3. "git.tetele.net/tgo/conf"
  4. )
  5. const DES_KEY = "wxserrpc"
  6. type WxApiRes struct {
  7. Errcode int
  8. Errmsg string
  9. }
  10. type Req struct {
  11. SiteId string
  12. Dbname string
  13. }
  14. type AccessTokenReq struct {
  15. Req
  16. Appid string
  17. Secret string
  18. }
  19. type AccessTokenRes struct {
  20. AccessToken string
  21. }
  22. type UniformMessageReq struct {
  23. Req
  24. Appid string
  25. Secret string
  26. Touser string
  27. MpAppid string
  28. TemplateId string
  29. Url string
  30. MiniProgram interface{}
  31. Data interface{}
  32. }
  33. type SubscribeMessageReq struct {
  34. Req
  35. Appid string
  36. Secret string
  37. Touser string
  38. TemplateId string
  39. Page string
  40. MiniprogramState string
  41. Lang string
  42. Data interface{}
  43. }
  44. /**
  45. * 获取小程序openid请求参数
  46. */
  47. type MiniAppOpenidReq struct {
  48. Appid string
  49. Secret string
  50. JsCode string
  51. }
  52. /**
  53. * 获取小程序openid返回参数
  54. */
  55. type MiniAppOpenidRes struct {
  56. Openid string
  57. SessionKey interface{}
  58. Unionid interface{}
  59. NickName string
  60. AvatarUrl string
  61. WxApiRes
  62. }
  63. /**
  64. * 获取公众号openid返回参数
  65. */
  66. type MpOpenidRes struct {
  67. AccessToken string
  68. ExpiresIn string
  69. RefreshToken string
  70. Openid string
  71. Scope string
  72. }
  73. /**
  74. * 获取公众号用户信息请求参数
  75. */
  76. type MpUserInfoReq struct {
  77. AccessToken string
  78. Openid string
  79. }
  80. /**
  81. * 根据用户access_token换取用户信息返回参数
  82. */
  83. type MpUserInfoRes struct {
  84. Openid string
  85. Nickname string
  86. Sex string
  87. Province string
  88. City string
  89. Country string
  90. Headimgurl string
  91. Privilege string
  92. Unionid string
  93. }
  94. func rpc_server_conn(url ...string) (*WeixinRpcServiceClient, error) {
  95. var wx_rpc_url string
  96. if len(url) > 0 && url[0] != "" {
  97. wx_rpc_url = url[0]
  98. wx_rpc_url = conf.WEIXIN_RPC_PORT
  99. } else {
  100. wx_rpc_url = "127.0.0.1:" + conf.WEIXIN_RPC_PORT
  101. }
  102. conn, _, err := DialWeixinRpcService("tcp", wx_rpc_url)
  103. if err != nil {
  104. return nil, err
  105. }
  106. return conn, nil
  107. }