1
This commit is contained in:
@@ -6,6 +6,7 @@ import (
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/platformapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
"net/http"
|
||||
"sort"
|
||||
"strings"
|
||||
@@ -77,7 +78,26 @@ func (a *API) GetToken() error {
|
||||
return nil
|
||||
}
|
||||
|
||||
// AccessAPI2 发送请求
|
||||
// AccessAPI1 发送请求(支付)
|
||||
func (a *API) AccessAPI1(url string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
request, _ := http.NewRequest(http.MethodPost, url, strings.NewReader(utils.Map2URLValues(params).Encode()))
|
||||
request.Header.Set("Content-Type", "application/json")
|
||||
return request
|
||||
},
|
||||
a.config,
|
||||
func(response *http.Response, bodyStr string, jsonResult1 map[string]interface{}) (errLevel string, err error) {
|
||||
if jsonResult1 == nil {
|
||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||
}
|
||||
retVal = jsonResult1
|
||||
return platformapi.ErrLevelSuccess, nil
|
||||
})
|
||||
return retVal, err
|
||||
}
|
||||
|
||||
// AccessAPI2 发送请求(登录)
|
||||
func (a *API) AccessAPI2(url string, params map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||
err = platformapi.AccessPlatformAPIWithRetry(a.client,
|
||||
func() *http.Request {
|
||||
@@ -116,9 +136,12 @@ func (a *API) sign(param map[string]interface{}) string {
|
||||
}
|
||||
|
||||
sort.Strings(paramsArr)
|
||||
signParma := make([]string, 0, 0)
|
||||
|
||||
globals.SugarLogger.Debugf("param := %s", utils.Format4Output(param, false))
|
||||
globals.SugarLogger.Debugf("paramsArr := %s", utils.Format4Output(paramsArr, false))
|
||||
signParma := make([]string, len(paramsArr))
|
||||
for k, v := range paramsArr {
|
||||
if utils.IsNil(param[v]) {
|
||||
if !utils.IsNil(param[v]) {
|
||||
signParma[k] = v + "=" + fmt.Sprintf("%v", param[v])
|
||||
}
|
||||
}
|
||||
|
||||
@@ -4,6 +4,7 @@ import (
|
||||
"errors"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"time"
|
||||
)
|
||||
|
||||
// PreCreateOrder 预下单生成支付信息
|
||||
@@ -13,7 +14,7 @@ func (a *API) PreCreateOrder(param *PreCreateOrderReq) (string, error) {
|
||||
}
|
||||
|
||||
param.Sign = a.sign(utils.Struct2MapByJson(param))
|
||||
result, err := a.AccessAPI2(a.FullUrl(KuaiShouPreCreateOrder), utils.Struct2MapByJson(param))
|
||||
result, err := a.AccessAPI1(a.FullUrl(KuaiShouPreCreateOrder), utils.Struct2MapByJson(param))
|
||||
if err != nil {
|
||||
return "", err
|
||||
}
|
||||
@@ -31,5 +32,8 @@ func (a *API) PreCreateOrder(param *PreCreateOrderReq) (string, error) {
|
||||
}
|
||||
|
||||
func (a *API) FullUrl(bashUrl string) string {
|
||||
if a.accessToken == "" || a.expiresIn < time.Now().Unix() {
|
||||
a.GetToken()
|
||||
}
|
||||
return fmt.Sprintf(bashUrl+"?app_id=%s&access_token=%s", a.appId, a.accessToken)
|
||||
}
|
||||
|
||||
@@ -2,6 +2,7 @@ package kuaishou_mini
|
||||
|
||||
import (
|
||||
"encoding/base64"
|
||||
"fmt"
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"git.rosy.net.cn/jx-callback/globals"
|
||||
@@ -79,14 +80,26 @@ func TestPreCreateOrder(t *testing.T) {
|
||||
TypeDetail: 1832, // 素菜
|
||||
ExpireTime: 10 * 60,
|
||||
Sign: "",
|
||||
Attach: "",
|
||||
Attach: "1111",
|
||||
NotifyUrl: "https://callback.jxc4.com/tictoc/tiktokMsg",
|
||||
GoodsId: "",
|
||||
GoodsDetailUrl: "",
|
||||
MultiCopiesGoodsInfo: "",
|
||||
GoodsId: "1122",
|
||||
GoodsDetailUrl: "/page/index/anima",
|
||||
MultiCopiesGoodsInfo: "[{\"copies\":2}]",
|
||||
CancelOrder: 0,
|
||||
}
|
||||
data, err := api.PreCreateOrder(param)
|
||||
globals.SugarLogger.Debugf("data := %s", utils.Format4Output(data, false))
|
||||
globals.SugarLogger.Debugf("err := %s", utils.Format4Output(err, false))
|
||||
}
|
||||
|
||||
func TestAaww(t *testing.T) {
|
||||
aa := make(map[string]interface{}, 1)
|
||||
aa["a"] = ""
|
||||
if value, ok := aa["a"].(int64); ok {
|
||||
fmt.Println(value)
|
||||
}
|
||||
if value, ok := aa["a"].(string); ok {
|
||||
|
||||
fmt.Println(utils.Str2Int64(value))
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user