1
This commit is contained in:
@@ -3,6 +3,7 @@ package tiktok_api
|
|||||||
import (
|
import (
|
||||||
"fmt"
|
"fmt"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
"git.rosy.net.cn/baseapi/utils"
|
||||||
|
"reflect"
|
||||||
"testing"
|
"testing"
|
||||||
)
|
)
|
||||||
|
|
||||||
@@ -16,10 +17,34 @@ func TestCancelWaybill(t *testing.T) {
|
|||||||
err := a.ShopOrderDispatcher(62490423, "5017358149445080799", 2)
|
err := a.ShopOrderDispatcher(62490423, "5017358149445080799", 2)
|
||||||
fmt.Println(err)
|
fmt.Println(err)
|
||||||
}
|
}
|
||||||
|
|
||||||
|
type tete struct {
|
||||||
|
ids []int64
|
||||||
|
name string
|
||||||
|
}
|
||||||
|
|
||||||
func Test(t *testing.T) {
|
func Test(t *testing.T) {
|
||||||
a := make([]int64, 0)
|
//var a []int64
|
||||||
Strings2Objs(`[1262627,1723872383]`, &a)
|
var b interface{}
|
||||||
fmt.Println(a)
|
//stType := reflect.TypeOf(a)
|
||||||
|
//stValue := reflect.ValueOf(a)
|
||||||
|
x := reflect.TypeOf(b)
|
||||||
|
fmt.Println(reflect.TypeOf(a) == reflect.TypeOf([]int64{}))
|
||||||
|
switch x {
|
||||||
|
case reflect.TypeOf([]int64{}):
|
||||||
|
|
||||||
|
fmt.Println(1)
|
||||||
|
case reflect.TypeOf([]string{}):
|
||||||
|
fmt.Println(2)
|
||||||
|
|
||||||
|
}
|
||||||
|
//fmt.Println(stType.NumField())
|
||||||
|
//fmt.Println(stType.Field(0))
|
||||||
|
//temp := stType.Field(0)
|
||||||
|
//fmt.Println(temp.Type)
|
||||||
|
|
||||||
|
//Strings2Objs(`[1262627,1723872383]`, &a)
|
||||||
|
//fmt.Printf("%v", reflect.TypeOf(a).NumField())
|
||||||
}
|
}
|
||||||
func Strings2Objs(strAndObjAddPairs ...interface{}) (err error) {
|
func Strings2Objs(strAndObjAddPairs ...interface{}) (err error) {
|
||||||
str := ""
|
str := ""
|
||||||
|
|||||||
@@ -122,9 +122,8 @@ type GetOrderPriceReq struct {
|
|||||||
|
|
||||||
//计算订单价格返回体
|
//计算订单价格返回体
|
||||||
type GetOrderPriceResp struct {
|
type GetOrderPriceResp struct {
|
||||||
BaseRespInfo *BaseRespInfo
|
//必返回
|
||||||
OriginID string `json:"origin_id"` //第三方对接平台订单id
|
OriginID string `json:"origin_id"` //第三方对接平台订单id
|
||||||
PriceToken string `json:"price_token"` //金额令牌,提交订单前必须先计算价格
|
|
||||||
TotalMoney string `json:"total_money"` //订单总金额(优惠前)
|
TotalMoney string `json:"total_money"` //订单总金额(优惠前)
|
||||||
NeedPayMoney string `json:"need_paymoney"` //实际需要支付金额
|
NeedPayMoney string `json:"need_paymoney"` //实际需要支付金额
|
||||||
TotalPriceOff string `json:"total_priceoff"` //总优惠金额
|
TotalPriceOff string `json:"total_priceoff"` //总优惠金额
|
||||||
@@ -133,6 +132,9 @@ type GetOrderPriceResp struct {
|
|||||||
AddFee string `json:"addfee"` //加价金额
|
AddFee string `json:"addfee"` //加价金额
|
||||||
GoodsInsuranceMoney string `json:"goods_insurancemoney"` //商品保价金额
|
GoodsInsuranceMoney string `json:"goods_insurancemoney"` //商品保价金额
|
||||||
ExpiresIn string `json:"expires_in"` //price_token的过期时间(单位:秒)
|
ExpiresIn string `json:"expires_in"` //price_token的过期时间(单位:秒)
|
||||||
|
//非必返回
|
||||||
|
PriceToken string `json:"price_token"` //金额令牌,提交订单前必须先计算价格
|
||||||
|
BaseRespInfo *BaseRespInfo
|
||||||
}
|
}
|
||||||
|
|
||||||
//发布订单请求体
|
//发布订单请求体
|
||||||
|
|||||||
@@ -1,25 +1,63 @@
|
|||||||
package uuptapi
|
package uuptapi
|
||||||
|
|
||||||
import (
|
//
|
||||||
"fmt"
|
//import (
|
||||||
"testing"
|
// "fmt"
|
||||||
)
|
// "testing"
|
||||||
|
//)
|
||||||
var (
|
//
|
||||||
api = New("55c4542ae60e4d348edcfc93b06dd302", "76b362c06b1b4baa9e47bab6387a5356", "8d8464e7c9354c1e88a3f5afa2a7922e")
|
//var (
|
||||||
)
|
// api = New("55c4542ae60e4d348edcfc93b06dd302", "76b362c06b1b4baa9e47bab6387a5356", "8d8464e7c9354c1e88a3f5afa2a7922e")
|
||||||
|
//)
|
||||||
func TestSignParam(t *testing.T) {
|
//
|
||||||
testStr := map[string]interface{}{
|
//func TestSignParam(t *testing.T) {
|
||||||
"origin_id": "T00001",
|
// testStr := map[string]interface{}{
|
||||||
"from_address": "郑州国际会展中心",
|
// "origin_id": "T00001",
|
||||||
"from_usernote": "1层",
|
// "from_address": "郑州国际会展中心",
|
||||||
"to_address": "商务外环路17号",
|
// "from_usernote": "1层",
|
||||||
"to_usernote": "1楼101",
|
// "to_address": "商务外环路17号",
|
||||||
}
|
// "to_usernote": "1楼101",
|
||||||
ans := api.signParam(testStr)
|
// }
|
||||||
fmt.Print(ans)
|
// ans := api.signParam(testStr)
|
||||||
}
|
// fmt.Print(ans)
|
||||||
func TestRandStr(t *testing.T) {
|
//}
|
||||||
fmt.Print(randStr())
|
//func TestRandStr(t *testing.T) {
|
||||||
}
|
// fmt.Print(randStr())
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
////计算运单价格
|
||||||
|
//func TestGetWaybillPrice(t *testing.T) {
|
||||||
|
// needPayMoney, priceToken, err := api.GetOrderPrice(&GetOrderPriceReq{
|
||||||
|
// //BaseReqInfo: &BaseReqInfo{
|
||||||
|
// //Sign: "A9D4D4380B6012F2E9A00E37243306D4",
|
||||||
|
// // NonceStr: "01c3ce7ce7604ab49d12ec69dfbdcfe8",
|
||||||
|
// //Timestamp: "1672998838",
|
||||||
|
// // OpenID: "8d8464e7c9354c1e88a3f5afa2a7922e",
|
||||||
|
// // AppID: "55c4542ae60e4d348edcfc93b06dd302",
|
||||||
|
// //},
|
||||||
|
// OriginID: "T00001",
|
||||||
|
// FromAddress: "郑州国际会展中心",
|
||||||
|
// ToAddress: "商务外环路17号",
|
||||||
|
// CityName: "郑州市",
|
||||||
|
// SendType: "0",
|
||||||
|
// ToLat: "34.784275",
|
||||||
|
// ToLng: "113.736445",
|
||||||
|
// FromLat: "34.778494",
|
||||||
|
// FromLng: "113.736858",
|
||||||
|
// })
|
||||||
|
//
|
||||||
|
// fmt.Println(needPayMoney, priceToken, err)
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//type testStruct struct {
|
||||||
|
// name string
|
||||||
|
//}
|
||||||
|
//
|
||||||
|
//func Test(t *testing.T) {
|
||||||
|
// var temp testStruct
|
||||||
|
// //var test bool
|
||||||
|
// //test = true
|
||||||
|
// //temp.name = "hdueu"
|
||||||
|
// fmt.Println(temp == testStruct{})
|
||||||
|
// //fmt.Print(utils.IsNil(temp))
|
||||||
|
//}
|
||||||
|
|||||||
@@ -1,103 +1,107 @@
|
|||||||
package uuptapi
|
package uuptapi
|
||||||
|
|
||||||
import (
|
//
|
||||||
"crypto/md5"
|
//import (
|
||||||
"encoding/json"
|
// "crypto/md5"
|
||||||
"fmt"
|
// "encoding/json"
|
||||||
"git.rosy.net.cn/baseapi/platformapi"
|
// "fmt"
|
||||||
"git.rosy.net.cn/baseapi/utils"
|
// "git.rosy.net.cn/baseapi/platformapi"
|
||||||
"math/rand"
|
// "git.rosy.net.cn/baseapi/utils"
|
||||||
"net/http"
|
// "math/rand"
|
||||||
"sort"
|
// "net/http"
|
||||||
"strings"
|
// "sort"
|
||||||
"time"
|
// "strings"
|
||||||
)
|
// "time"
|
||||||
|
//)
|
||||||
const (
|
//
|
||||||
ReturnSuccess = "ok"
|
//const (
|
||||||
ReturnFail = "fail"
|
// BaseURL = "https://openapi.uupt.com/v2_0"
|
||||||
signKey = "sign"
|
// ReturnSuccess = "ok"
|
||||||
secretKey = "secret"
|
// ReturnFail = "fail"
|
||||||
letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
// signKey = "sign"
|
||||||
)
|
// secretKey = "secret"
|
||||||
|
// UUOpenID = "8d8464e7c9354c1e88a3f5afa2a7922e"
|
||||||
func (a *API) MakeUURequestHead() map[string]interface{} {
|
// UUAppID = "55c4542ae60e4d348edcfc93b06dd302"
|
||||||
requestParam := make(map[string]interface{}, 5)
|
// letters = "abcdefghijklmnopqrstuvwxyzABCDEFGHIJKLMNOPQRSTUVWXYZ1234567890"
|
||||||
requestParam["sign"] = a.sign
|
//)
|
||||||
requestParam["timestamp"] = a.timestamp
|
//
|
||||||
requestParam["nonce_str"] = a.noncestr
|
//func (a *API) MakeUURequestHead() map[string]interface{} {
|
||||||
requestParam["openid"] = a.openid
|
// requestParam := make(map[string]interface{}, 5)
|
||||||
requestParam["appid"] = a.appid
|
// requestParam["sign"] = a.sign
|
||||||
return requestParam
|
// requestParam["timestamp"] = a.timestamp
|
||||||
}
|
// requestParam["nonce_str"] = a.noncestr
|
||||||
func New(appID, appKey, openID string) *API {
|
// requestParam["openid"] = a.openid
|
||||||
if appID == "" {
|
// requestParam["appid"] = a.appid
|
||||||
return nil
|
// return requestParam
|
||||||
}
|
//}
|
||||||
return &API{
|
//func New(appID, appKey, openID string) *API {
|
||||||
appid: appID,
|
// if appID == "" {
|
||||||
appKey: appKey,
|
// return nil
|
||||||
openid: openID,
|
// }
|
||||||
}
|
// return &API{
|
||||||
}
|
// appid: appID,
|
||||||
|
// appKey: appKey,
|
||||||
func (a *API) signParam(params map[string]interface{}) (sign string) {
|
// openid: openID,
|
||||||
keyValues := make([]string, 0)
|
// }
|
||||||
for k, v := range params {
|
//}
|
||||||
if k != signKey {
|
//
|
||||||
if temp := fmt.Sprint(v); temp != "" {
|
//func (a *API) signParam(params map[string]interface{}) (sign string) {
|
||||||
keyValues = append(keyValues, k+"="+temp)
|
// keyValues := make([]string, 0)
|
||||||
}
|
// for k, v := range params {
|
||||||
}
|
// if k != signKey {
|
||||||
}
|
// if temp := fmt.Sprint(v); temp != "" {
|
||||||
sort.Sort(sort.StringSlice(keyValues)) //字典升序
|
// keyValues = append(keyValues, k+"="+temp)
|
||||||
sign = strings.Join(keyValues, "&")
|
// }
|
||||||
sign += "&key=" + a.appKey //末尾拼接密钥
|
// }
|
||||||
sign = strings.ToUpper(sign) //大写
|
// }
|
||||||
return fmt.Sprintf("%X", md5.Sum([]byte(sign)))
|
// sort.Sort(sort.StringSlice(keyValues)) //字典升序
|
||||||
}
|
// sign = strings.Join(keyValues, "&")
|
||||||
|
// sign += "&key=" + a.appKey //末尾拼接密钥
|
||||||
func (a *API) AccessAPI(baseUrl, actionApi, method string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
// sign = strings.ToUpper(sign) //大写
|
||||||
bizParams["timestamp"] = utils.Int64ToStr(time.Now().Unix() * 1000)
|
// return fmt.Sprintf("%X", md5.Sum([]byte(sign)))
|
||||||
bizParams["sign"] = a.signParam(bizParams)
|
//}
|
||||||
//序列化
|
//
|
||||||
data, err := json.Marshal(bizParams)
|
//func (a *API) AccessAPI(baseUrl, actionApi, method string, bizParams map[string]interface{}) (retVal map[string]interface{}, err error) {
|
||||||
if err != nil {
|
// bizParams["timestamp"] = utils.Int64ToStr(time.Now().Unix() * 1000)
|
||||||
return nil, err
|
// bizParams["sign"] = a.signParam(bizParams)
|
||||||
}
|
// //序列化
|
||||||
//完整请求url
|
// data, err := json.Marshal(bizParams)
|
||||||
fullPath := utils.GenerateGetURL(baseUrl, actionApi, nil)
|
// if err != nil {
|
||||||
//发送请求
|
// return nil, err
|
||||||
sendUrl := func() *http.Request {
|
// }
|
||||||
var request *http.Request
|
// //完整请求url
|
||||||
if method == RequestPost {
|
// fullPath := utils.GenerateGetURL(baseUrl, actionApi, nil)
|
||||||
request, _ = http.NewRequest(http.MethodPost, fullPath, strings.NewReader(string(data)))
|
// //发送请求
|
||||||
} else {
|
// sendUrl := func() *http.Request {
|
||||||
request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(baseUrl, actionApi, bizParams), nil)
|
// var request *http.Request
|
||||||
}
|
// if method == RequestPost {
|
||||||
return request
|
// request, _ = http.NewRequest(http.MethodPost, fullPath, strings.NewReader(string(data)))
|
||||||
}
|
// } else {
|
||||||
//数据解析
|
// request, _ = http.NewRequest(http.MethodGet, utils.GenerateGetURL(baseUrl, actionApi, bizParams), nil)
|
||||||
dataMarshal := func(response *http.Response, bodyStr string, jsonResp map[string]interface{}) (errMsg string, err error) {
|
// }
|
||||||
if jsonResp == nil {
|
// return request
|
||||||
return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
// }
|
||||||
}
|
// //数据解析
|
||||||
if jsonResp["return_code"] != ReturnSuccess {
|
// dataMarshal := func(response *http.Response, bodyStr string, jsonResp map[string]interface{}) (errMsg string, err error) {
|
||||||
errMsg = platformapi.ErrLevelGeneralFail
|
// if jsonResp == nil {
|
||||||
err = utils.NewErrorCode(jsonResp["return_msg"].(string), utils.Int64ToStr(utils.MustInterface2Int64(jsonResp["return_code"])))
|
// return platformapi.ErrLevelRecoverableErr, fmt.Errorf("mapData is nil")
|
||||||
}
|
// }
|
||||||
retVal = jsonResp
|
// if jsonResp["return_code"] != ReturnSuccess {
|
||||||
return errMsg, err
|
// errMsg = platformapi.ErrLevelGeneralFail
|
||||||
}
|
// err = utils.NewErrorCode(jsonResp["return_msg"].(string), utils.Int64ToStr(utils.MustInterface2Int64(jsonResp["return_code"])))
|
||||||
err = platformapi.AccessPlatformAPIWithRetry(a.client, sendUrl, a.config, dataMarshal)
|
// }
|
||||||
return retVal, err
|
// retVal = jsonResp
|
||||||
}
|
// return errMsg, err
|
||||||
|
// }
|
||||||
//以下为辅助函数
|
// err = platformapi.AccessPlatformAPIWithRetry(a.client, sendUrl, a.config, dataMarshal)
|
||||||
func randStr() string {
|
// return retVal, err
|
||||||
b := make([]byte, 16)
|
//}
|
||||||
for i := range b {
|
//
|
||||||
b[i] = letters[rand.Intn(len(letters))]
|
////以下为辅助函数
|
||||||
}
|
//func randStr() string {
|
||||||
return string(b)
|
// b := make([]byte, 16)
|
||||||
}
|
// for i := range b {
|
||||||
|
// b[i] = letters[rand.Intn(len(letters))]
|
||||||
|
// }
|
||||||
|
// return string(b)
|
||||||
|
//}
|
||||||
|
|||||||
@@ -1,14 +1,31 @@
|
|||||||
package uuptapi
|
package uuptapi
|
||||||
|
|
||||||
import "encoding/json"
|
//
|
||||||
|
//import (
|
||||||
//计算订单价格
|
// "encoding/json"
|
||||||
func (a *API) GetOrderPrice(req *GetOrderPriceReq) (needPayMoney, priceToken string, err error) {
|
// "git.rosy.net.cn/baseapi/utils"
|
||||||
preOrder := a.MakeUURequestHead()
|
//)
|
||||||
bytes, err := json.Marshal(req)
|
//
|
||||||
if err != nil {
|
////计算订单价格
|
||||||
return "", "", err
|
//func (a *API) GetOrderPrice(req *GetOrderPriceReq) (needPayMoney, priceToken string, err error) {
|
||||||
}
|
// preOrder := a.MakeUURequestHead()
|
||||||
preOrder["param"] = string(bytes)
|
// bytes, err := json.Marshal(req)
|
||||||
return "", "", nil
|
// if err != nil {
|
||||||
}
|
// return "", "", err
|
||||||
|
// }
|
||||||
|
// preOrder["param"] = string(bytes)
|
||||||
|
// resp, err := a.AccessAPI(BaseURL, "getorderprice.ashx", RequestPost, preOrder)
|
||||||
|
// if err != nil {
|
||||||
|
// return "", "", err
|
||||||
|
// }
|
||||||
|
// retVal := GetOrderPriceResp{}
|
||||||
|
// if err := json.Unmarshal([]byte(resp["param"].(string)), &retVal); err != nil {
|
||||||
|
// return "", "", err
|
||||||
|
// }
|
||||||
|
// con := retVal == GetOrderPriceResp{}
|
||||||
|
// if !utils.IsNil(retVal) && !con {
|
||||||
|
// needPayMoney = retVal.NeedPayMoney
|
||||||
|
// priceToken = retVal.PriceToken
|
||||||
|
// }
|
||||||
|
// return needPayMoney, priceToken, nil
|
||||||
|
//}
|
||||||
|
|||||||
Reference in New Issue
Block a user