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

96 lines
1.6 KiB

  1. package weixinrpc
  2. import (
  3. "encoding/json"
  4. "git.tetele.net/tgo/crypter"
  5. "github.com/golang/protobuf/proto"
  6. "strconv"
  7. "time"
  8. )
  9. //检测图片是否合法
  10. func ImgSecCheck(appId, appSecret,imgUrl string, url ...string) (error) {
  11. conn, err := rpc_server_conn(url...)
  12. if err != nil {
  13. return err
  14. }
  15. defer conn.Close()
  16. data := map[string]interface{}{}
  17. data["app_id"] = appId
  18. data["app_secret"] = appSecret
  19. data["img_url"] = imgUrl
  20. data_json, err := json.Marshal(data)
  21. if err != nil {
  22. return err
  23. }
  24. encryData := crypter.DesEn(string(data_json), DES_KEY)
  25. now_int64 := time.Now().Unix()
  26. now := strconv.FormatInt(now_int64, 10)
  27. sign := Sign(encryData, now)
  28. req := &Request{
  29. proto.String(encryData),
  30. proto.String(now),
  31. proto.String(sign),
  32. nil}
  33. res := &Response{}
  34. err = conn.ImgSecCheck(req, res)
  35. if err != nil {
  36. return err
  37. }
  38. return nil
  39. }
  40. //检测文本是否合法
  41. func MsgSecCheck(appId, appSecret string,checkData map[string]interface{}, url ...string)error{
  42. conn, err := rpc_server_conn(url...)
  43. if err != nil {
  44. return err
  45. }
  46. defer conn.Close()
  47. data := map[string]interface{}{}
  48. data["app_id"] = appId
  49. data["app_secret"] = appSecret
  50. data["check_data"] = checkData
  51. data_json, err := json.Marshal(data)
  52. if err != nil {
  53. return err
  54. }
  55. encryData := crypter.DesEn(string(data_json), DES_KEY)
  56. now_int64 := time.Now().Unix()
  57. now := strconv.FormatInt(now_int64, 10)
  58. sign := Sign(encryData, now)
  59. req := &Request{
  60. proto.String(encryData),
  61. proto.String(now),
  62. proto.String(sign),
  63. nil}
  64. res := &Response{}
  65. err = conn.MsgSecCheck(req, res)
  66. if err != nil {
  67. return err
  68. }
  69. return nil
  70. }