12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879 |
- package thirdparty
- import (
- "bytes"
- "context"
- "fmt"
- "gd_vehicle/apis"
- "io/ioutil"
- "net/http"
- "strconv"
- "time"
- "gd_vehicle/common.in/config"
- "gd_vehicle/common.in/utils"
- jsoniter "github.com/json-iterator/go"
- "go.uber.org/zap"
- )
- func Adm(
- ctx context.Context,
- api string,
- params map[string]string,
- provider apis.MerchantProviderLimitInfo,
- ) (result []byte, err error) {
- defer func() {
- l.Info("thirdparty",
- zap.String("api", api),
- zap.String("request", utils.MarshalJsonString(params)),
- zap.String("response", utils.MarshalJsonString(result)))
- }()
- ts := strconv.FormatInt(time.Now().Unix(), 10)
- appkey := config.Conf.ThirdPart.AdmAppkey
- sign := utils.MD5(appkey + ts)
- body := map[string]interface{}{
- "api": api,
- }
- body["param"], _ = jsoniter.MarshalToString(params)
- b, err := jsoniter.Marshal(body)
- if err != nil {
- return result, err
- }
- client := &http.Client{}
- req, err := http.NewRequest(
- provider.ThirdpartApiMethod,
- provider.ThirdpartHost+"/"+provider.ThirdpartApiRouter,
- bytes.NewBuffer(b),
- )
- if err != nil {
- return result, err
- }
- req.Header.Add("Content-Type", "application/json")
- req.Header.Add("appkey", appkey)
- req.Header.Add("ts", ts)
- req.Header.Add("sign", sign)
- resp, err := client.Do(req)
- if err != nil {
- return result, err
- }
- if resp.StatusCode != http.StatusOK {
- return nil, fmt.Errorf("wrong status code: %d", resp.StatusCode)
- }
- defer resp.Body.Close()
- result, err = ioutil.ReadAll(resp.Body)
- return result, err
- }
|