package mixrepoimpl import ( "context" "encoding/json" "fmt" "github.com/go-kratos/kratos/v2/log" "net/http" "time" v1 "voucher/api/v1" "voucher/internal/biz/kx" "voucher/internal/biz/mixrepos" "voucher/internal/biz/vo" "voucher/internal/conf" "voucher/internal/pkg/request" ) type KxMixRepoImpl struct { bc *conf.Bootstrap } func NewKxMixRepoImpl(bc *conf.Bootstrap) mixrepos.KxMixRepo { return &KxMixRepoImpl{bc: bc} } func (s *KxMixRepoImpl) Request(ctx context.Context, req *kx.SynNotice) error { body, err := req.Marshal() if err != nil { log.Errorf("请求掌上生活Marshal报错:%s", err.Error()) return err } h := http.Header{ "Content-Type": []string{"application/x-www-form-urlencoded"}, } url := "" _, bodyBytes, err := request.Post(ctx, url, body, request.WithHeaders(h), request.WithTimeout(time.Second*20)) if err != nil { log.Errorf("请求kx报错,url:%s,err:%v", url, err) return err } var response *v1.CmbReply if err = json.Unmarshal(bodyBytes, &response); err != nil { log.Errorf("请求kx返回数据解析报错:%s,url:%s,bodyBytes:%s", err.Error(), url, string(bodyBytes)) return err } if response.RespCode != vo.CmbResponseStatusSuccess.GetValue() { log.Errorf("请求kx返回报错:msg:%s,url:%s,bodyBytes:%s", response.RespMsg, url, string(bodyBytes)) return fmt.Errorf(response.RespMsg) } return nil }