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

77 lines
1.2 KiB

  1. package weixinrpc
  2. import (
  3. "encoding/json"
  4. "log"
  5. "strconv"
  6. "time"
  7. "git.tetele.net/tgo/crypter"
  8. "github.com/golang/protobuf/proto"
  9. )
  10. func GetMpUserInfo(accessToken,openId string,url ...string) (*MpUserInfoRes, error) {
  11. conn, err := rpc_server_conn(url...)
  12. if err != nil {
  13. return nil, err
  14. }
  15. defer conn.Close()
  16. data := MpUserInfoReq{}
  17. data.AccessToken = accessToken
  18. data.Openid = openId
  19. data_json, err := json.Marshal(data)
  20. if err != nil {
  21. return nil, err
  22. }
  23. encryData := crypter.DesEn(string(data_json), DES_KEY)
  24. now_int64 := time.Now().Unix()
  25. now := strconv.FormatInt(now_int64, 10)
  26. sign := Sign(encryData, now)
  27. req := &Request{
  28. proto.String(encryData),
  29. proto.String(now),
  30. proto.String(sign),
  31. nil}
  32. res := &Response{}
  33. err = conn.GetMpUserInfo(req, res)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return HandleMpUserInfo(res)
  38. }
  39. /**
  40. * 处理返回结果
  41. */
  42. func HandleMpUserInfo(res *Response) (*MpUserInfoRes, error) {
  43. //解密
  44. res_data_de, err := GetOrgData(res)
  45. if err != nil {
  46. return nil, err
  47. }
  48. var res_arr MpUserInfoRes
  49. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  50. if err != nil {
  51. log.Println(err, res_data_de)
  52. return nil, err
  53. }
  54. return &res_arr, nil
  55. }