36 lines
848 B
Go
36 lines
848 B
Go
package kuaishou_mini
|
|
|
|
import (
|
|
"errors"
|
|
"fmt"
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
)
|
|
|
|
// PreCreateOrder 预下单生成支付信息
|
|
func (a *API) PreCreateOrder(param *PreCreateOrderReq) (string, error) {
|
|
if a.appId == "" || a.appSecret == "" {
|
|
return "", errors.New("appId/appSecret 不能为空")
|
|
}
|
|
|
|
param.Sign = a.sign(utils.Struct2MapByJson(param))
|
|
result, err := a.AccessAPI2(a.FullUrl(KuaiShouPreCreateOrder), utils.Struct2MapByJson(param))
|
|
if err != nil {
|
|
return "", err
|
|
}
|
|
|
|
order := PreCreateOrderResponse{}
|
|
if err := utils.Map2StructByJson(result, &order, false); err != nil {
|
|
return "", err
|
|
}
|
|
|
|
if order.Result != 1 {
|
|
return "", errors.New(order.ErrorMsg)
|
|
}
|
|
|
|
return order.OrderInfo, nil
|
|
}
|
|
|
|
func (a *API) FullUrl(bashUrl string) string {
|
|
return fmt.Sprintf(bashUrl+"?app_id=%s&access_token=%s", a.appId, a.accessToken)
|
|
}
|