123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- package provincial_department
- import (
- "context"
- "fmt"
- "github.com/tidwall/gjson"
- "go.uber.org/zap"
- "smart-provincial/errors"
- "smart-provincial/pb/v1"
- "smart-provincial/thirdparty"
- "strings"
- "smart-provincial/parser"
- "github.com/jaryhe/gopkgs/logger"
- )
- func ProvincialVerifyData(ctx context.Context, req *v1.ProvincialVerifyDataRequest)(reply *v1.ProvincialVerifyDataReply, err error) {
- token, err := Login()
- if err != nil {
- return nil, err
- }
- data := map[string]interface{}{
- "ID":req.Id,
- }
- bytes, err := thirdparty.ProvincialPost(parser.Conf.ThirdParty.Provincial.ProvincialVerifyApi, token, data)
- fmt.Printf("provincial verify data: %s,%v\n", bytes, err)
- if err != nil {
- logger.Error("thirdpary provincial verify data",
- zap.String("call", parser.Conf.ThirdParty.Provincial.ProvincialVerifyApi),
- zap.String("param", req.Id),
- zap.String("error", err.Error()))
- return nil, errors.ProvincialVerifyDataError
- }
- ack := gjson.GetBytes(bytes, "ack_code").String()
- if strings.ToUpper(ack) != "SUCCESS" {
- logger.Error("thirdpary provincial verify data",
- zap.String("call", parser.Conf.ThirdParty.Provincial.ProvincialVerifyApi),
- zap.String("param", req.Id),
- zap.String("error",string(bytes)))
- return nil, errors.ProvincialVerifyDataError
- }
- array := gjson.GetBytes(bytes, "datas").Array()
- if len(array) == 0 {
- logger.Error("thirdpary provincial verify data",
- zap.String("call", parser.Conf.ThirdParty.Provincial.ProvincialVerifyApi),
- zap.String("param", req.Id),
- zap.String("error",string(bytes)))
- return nil, errors.ProvincialVerifyDataError
- }
- reply = &v1.ProvincialVerifyDataReply{}
- reply.State = int32(array[0].Get("Status").Int())
- reply.Result = int32(array[0].Get("Code").Int())
- reply.AllMessage = fmt.Sprintf("%s,%s", array[0].Get("VerificationMessage").String(), array[0].Get("message").String())
- return reply, nil
- }
|