12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667 |
- package thirdparty
- import (
- "bytes"
- "gd_management/common.in/config"
- "gd_management/common.in/utils"
- "encoding/json"
- "go.uber.org/zap"
- "io/ioutil"
- "net/http"
- "strconv"
- "time"
- )
- /*const (
- //acarbangProductionHost = "http://api.acarbang.com/api"
- //acarbangAppId = "369907822114111489"
- //acarbangAppKey = "d494773a04dc44139a17d40a5c4d9445"
- acarbangAppId = "476795160986910721"
- acarbangAppKey = "897c86f2779341e88e38b3eb9acb384f"
- )
- */
- func AcarbangHttpPost(api string, data map[string]string) (result []byte, err error) {
- return []byte(`{"code":1 "data":"test"}`), nil
- defer func() {
- l.Info("thirdparty",
- zap.String("api", api),
- zap.String("request", utils.MarshalJsonString(data)),
- zap.String("response", utils.MarshalJsonString(result)))
- }()
- jsonData, err := json.Marshal(data)
- if err != nil {
- return nil, err
- }
- client := &http.Client{}
- client.Timeout = 60 * time.Second
- req, err := http.NewRequest("POST", api, bytes.NewBuffer(jsonData))
- if err != nil {
- return nil, err
- }
- timeNow := time.Now()
- requestsn := timeNow.Format("20060102150405000")
- timestamp := strconv.FormatInt(timeNow.UnixNano()/1000000, 10)
- req.Header.Set("appId", config.Conf.ThirdPart.ArcbangAppId)
- req.Header.Set("apiKey", config.Conf.ThirdPart.ArcbangAppKey)
- req.Header.Set("requestsn", requestsn)
- req.Header.Set("timestamp", timestamp)
- req.Header.Set("sign", utils.MD5(config.Conf.ThirdPart.ArcbangAppId+config.Conf.ThirdPart.ArcbangAppKey+requestsn+timestamp))
- req.Header.Set("Content-Type", "application/json")
- resp, err := client.Do(req)
- if err != nil {
- return nil, err
- }
- defer resp.Body.Close()
- result, err = ioutil.ReadAll(resp.Body)
- return
- }
- /*(func acarbangFullUrl(api string, host string) string {
- return host + "/" + api
- }*/
|