135 lines
2.9 KiB
Go
135 lines
2.9 KiB
Go
package jdshopapi
|
|
|
|
import (
|
|
"bytes"
|
|
"crypto/aes"
|
|
"crypto/cipher"
|
|
"encoding/base64"
|
|
"fmt"
|
|
"testing"
|
|
|
|
"git.rosy.net.cn/baseapi/utils"
|
|
)
|
|
|
|
func TestCreateShopCategory(t *testing.T) {
|
|
var CreateShopCategoryParams = []*CreateShopCategoryParam{
|
|
&CreateShopCategoryParam{
|
|
HomeShow: "0",
|
|
ID: "0",
|
|
Open: "",
|
|
OrderNo: "0",
|
|
ParentID: "",
|
|
Title: "测试1",
|
|
Type: "3",
|
|
},
|
|
}
|
|
result, _ := api.CreateShopCategory(CreateShopCategoryParams)
|
|
fmt.Println(result)
|
|
}
|
|
|
|
func TestUpdateStoreStatus(t *testing.T) {
|
|
err := api.UpdateStoreStatus(24332466, 1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
}
|
|
|
|
func TestNewInfoList(t *testing.T) {
|
|
result, err := api.NewInfoList(1)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func Test11(t *testing.T) {
|
|
change := func(s ...string) {
|
|
s[0] = "Go"
|
|
s = append(s, "playground")
|
|
fmt.Println(s)
|
|
}
|
|
|
|
welcome := []string{"hello", "world"}
|
|
change(welcome...)
|
|
fmt.Println(welcome)
|
|
|
|
}
|
|
|
|
func TestAllOrders(t *testing.T) {
|
|
result, err := api.AllOrders(&AllOrdersParam{
|
|
Current: 1,
|
|
PageSize: 1,
|
|
OrderID: "118793082128",
|
|
})
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestOrderDetail(t *testing.T) {
|
|
result, err := api.OrderDetail("125138699851")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestPhoneSensltiveInfo(t *testing.T) {
|
|
result, err := api.PhoneSensltiveInfo("124396047880", "10b1707dc87755373d488a7a4f422f7d")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestUpdateWaybill(t *testing.T) {
|
|
err := api.UpdateWaybill("123076499052", "1274", "88328977356545 ")
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
// t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestTryGetCookie(t *testing.T) {
|
|
result, err := api.TryGetCookie()
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
t.Log(utils.Format4Output(result, false))
|
|
}
|
|
|
|
func TestAAADS(t *testing.T) {
|
|
str := "AASWvkdk5a60bjm3lFqaoCyzBFIjrHQjoKSY+LN5VcswOzDkqjbjxVyK1Psdqcj3ci0+4I9v3evrtrJHLuUSo3eEfT3+psX6DF45CILeq0VbKxwxkE+AS1WTxr9RTHqaM3g="
|
|
data, _ := base64.StdEncoding.DecodeString(str)
|
|
data2, _ := base64.StdEncoding.DecodeString("XsGNdyDyDHnR79iKU6d5LTSJYaQyWAEssDoD7VM5Kks=")
|
|
b := bytes.NewBuffer(data)
|
|
b.Next(18)
|
|
iv := make([]byte, 16)
|
|
b.Read(iv)
|
|
main := make([]byte, len(data)-18-16)
|
|
b.Read(main)
|
|
decryptedData, err := utils.AESCBCDecpryt(main, data2[:16], iv)
|
|
// decryptedData, err := Decrypt(main, data2[:16], iv)
|
|
if err != nil {
|
|
t.Fatal(err)
|
|
}
|
|
fmt.Println("data", string(decryptedData))
|
|
}
|
|
|
|
func Decrypt(decryptBytes, key, iv []byte) ([]byte, error) {
|
|
block, err := aes.NewCipher(key)
|
|
if err != nil {
|
|
return nil, err
|
|
}
|
|
blockMode := cipher.NewCBCDecrypter(block, iv)
|
|
blockMode.CryptBlocks(decryptBytes, decryptBytes)
|
|
return PKCS5UnPadding(decryptBytes), nil
|
|
}
|
|
|
|
func PKCS5UnPadding(decrypted []byte) []byte {
|
|
length := len(decrypted)
|
|
unPadding := int(decrypted[length-1])
|
|
return decrypted[:(length - unPadding)]
|
|
}
|