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

75 lines
1.2 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. func GetAccessToken(dbname, site_id string, appid, secret string, url ...string) (*AccessTokenRes, error) {
  10. conn, err := rpc_server_conn(url...)
  11. data := AccessTokenReq{}
  12. data.SiteId = site_id
  13. data.Dbname = dbname
  14. data.Appid = appid
  15. data.Secret = secret
  16. data_json, err := json.Marshal(data)
  17. if err != nil {
  18. return nil, err
  19. }
  20. encryData := crypter.DesEn(string(data_json), DES_KEY)
  21. now_int64 := time.Now().Unix()
  22. now := strconv.FormatInt(now_int64, 10)
  23. sign := Sign(encryData, now)
  24. req := &Request{
  25. proto.String(encryData),
  26. proto.String(now),
  27. proto.String(sign),
  28. nil}
  29. res := &Response{}
  30. err = conn.GetAccessToken(req, res)
  31. if err != nil {
  32. return nil, err
  33. }
  34. return HandleAccessToken(res)
  35. }
  36. /**
  37. * 处理返回结果
  38. */
  39. func HandleAccessToken(res *Response) (*AccessTokenRes, error) {
  40. //解密
  41. res_data_de, err := GetOrgData(res)
  42. if err != nil {
  43. return nil, err
  44. }
  45. var res_arr AccessTokenRes
  46. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  47. if err != nil {
  48. return nil, err
  49. }
  50. return &res_arr, nil
  51. }