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

78 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 GetMiniAppOpenid(appid, secret, js_code string, url ...string) (*MiniAppOpenidRes, error) {
  10. conn, err := rpc_server_conn(url...)
  11. if err != nil {
  12. return nil, err
  13. }
  14. defer conn.Close()
  15. data := MiniAppOpenidReq{}
  16. data.Appid = appid
  17. data.Secret = secret
  18. data.JsCode = js_code
  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.GetMiniAppOpenid(req, res)
  34. if err != nil {
  35. return nil, err
  36. }
  37. return HandleMiniAppOpenid(res)
  38. }
  39. /**
  40. * 处理返回结果
  41. */
  42. func HandleMiniAppOpenid(res *Response) (*MiniAppOpenidRes, error) {
  43. //解密
  44. res_data_de, err := GetOrgData(res)
  45. if err != nil {
  46. return nil, err
  47. }
  48. var res_arr MiniAppOpenidRes
  49. err = json.Unmarshal([]byte(res_data_de), &res_arr)
  50. if err != nil {
  51. return nil, err
  52. }
  53. return &res_arr, nil
  54. }