You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

58 lines
1.5 KiB

package service
import (
"encoding/json"
"errors"
"fmt"
"github.com/gogf/gf/v2/encoding/gjson"
"io/ioutil"
"net/http"
"strings"
"time"
"tyj_admin/api/v1/game"
)
func GetHuaWeiConfig() *DemoConfig {
var demoConfig DemoConfig
demoConfig.RootUrlOrder = "https://orders-drcn.iap.cloud.huawei.com.cn/applications/v1/merchantQuery"
return &demoConfig
}
func GetHuaWeiOrderList(continuationToken string, startAt, endAt int64) (*game.HuaWeiOrderResponse, error) {
demoConfig := GetHuaWeiConfig()
urlValue := map[string]interface{}{
"startAt": startAt,
"endAt": endAt,
}
if len(continuationToken) > 0 {
urlValue["continuationToken"] = continuationToken
}
var atResponse game.HuaWeiOrderResponse
req, err := http.NewRequest("POST", demoConfig.RootUrlOrder, strings.NewReader(gjson.MustEncodeString(urlValue)))
if err != nil {
return &atResponse, err
}
auth, _ := BuildAuthorization()
req.Header.Set("Authorization", auth)
req.Header.Set("Content-Type", "application/json; charset=UTF-8")
req.Header.Set("Accept", "application/json")
client := &http.Client{Timeout: 15 * time.Second}
resp, err := client.Do(req)
if err != nil {
return nil, fmt.Errorf("API请求失败: %v", err)
}
defer resp.Body.Close()
bodyBytes, err := ioutil.ReadAll(resp.Body)
if err != nil {
return &atResponse, err
}
_ = json.Unmarshal(bodyBytes, &atResponse)
if atResponse.ResponseCode != "" {
return &atResponse, nil
} else {
return &atResponse, errors.New("Get order fail, " + string(bodyBytes))
}
}