verify_data.go 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657
  1. package provincial_department
  2. import (
  3. "context"
  4. "fmt"
  5. "github.com/tidwall/gjson"
  6. "go.uber.org/zap"
  7. "smart-provincial/errors"
  8. "smart-provincial/pb/v1"
  9. "smart-provincial/thirdparty"
  10. "strings"
  11. "smart-provincial/parser"
  12. "github.com/jaryhe/gopkgs/logger"
  13. )
  14. func ProvincialVerifyData(ctx context.Context, req *v1.ProvincialVerifyDataRequest)(reply *v1.ProvincialVerifyDataReply, err error) {
  15. token, err := Login()
  16. if err != nil {
  17. return nil, err
  18. }
  19. data := map[string]interface{}{
  20. "ID":req.Id,
  21. }
  22. bytes, err := thirdparty.ProvincialPost(parser.Conf.ThirdParty.Provincial.ProvincialVerifyApi, token, data)
  23. fmt.Printf("provincial verify data: %s,%v\n", bytes, err)
  24. if err != nil {
  25. logger.Error("thirdpary provincial verify data",
  26. zap.String("call", parser.Conf.ThirdParty.Provincial.ProvincialVerifyApi),
  27. zap.String("param", req.Id),
  28. zap.String("error", err.Error()))
  29. return nil, errors.ProvincialVerifyDataError
  30. }
  31. ack := gjson.GetBytes(bytes, "ack_code").String()
  32. if strings.ToUpper(ack) != "SUCCESS" {
  33. logger.Error("thirdpary provincial verify data",
  34. zap.String("call", parser.Conf.ThirdParty.Provincial.ProvincialVerifyApi),
  35. zap.String("param", req.Id),
  36. zap.String("error",string(bytes)))
  37. return nil, errors.ProvincialVerifyDataError
  38. }
  39. array := gjson.GetBytes(bytes, "datas").Array()
  40. if len(array) == 0 {
  41. logger.Error("thirdpary provincial verify data",
  42. zap.String("call", parser.Conf.ThirdParty.Provincial.ProvincialVerifyApi),
  43. zap.String("param", req.Id),
  44. zap.String("error",string(bytes)))
  45. return nil, errors.ProvincialVerifyDataError
  46. }
  47. reply = &v1.ProvincialVerifyDataReply{}
  48. reply.State = int32(array[0].Get("Status").Int())
  49. reply.Result = int32(array[0].Get("Code").Int())
  50. reply.AllMessage = fmt.Sprintf("%s,%s", array[0].Get("VerificationMessage").String(), array[0].Get("message").String())
  51. return reply, nil
  52. }