package weixinapi

import (
	"fmt"
	"git.rosy.net.cn/baseapi/utils"
	"testing"
	"time"
)

func TestSNSRetrieveToken(t *testing.T) {
	result, err := api.SNSRetrieveToken("021UGn0006ICgQ13UC1005f2kD4UGn0r")
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(result)
}

func TestSNSDecodeMiniProgramData(t *testing.T) {
	// encryptedData := "rvV8ztGgNeOAafzydhMTASoilrSBlWcfWQ+GbEoiM+Ls72KJYKm/VYuvwahvoaGNC2EBG9sU6Bsy2Y4NsDww41DQw5aRstQqiI9yFIdvnB5YMwlTm/BN/Pt0LyL0POSouj6C2unUm3WFvOVYWtZtb8N2w0WIq1phnQ9YrJp8ynocw7KOEnRIpOUe1yyIWwT4zgi75fl87Wvku+s52WgjWw=="
	// sessionKey := "xXrDRVNCjlq2hZ+ePouEPg=="
	// iv := "Bl68JDy3I+pPN85sg7ckMg=="

	encryptedData := "spUntKHbzUfj+xIJ5b+beEN3yJw6gGBZWo26c9xoW9n9dBkHWkHQ+a/gY/lDjHVPlZ60LGglUNlY0XDBFGuh7exCm05jws+Rev1dTJh9YzBUrGaStR7Hw/niXPj4aJsb7lQVMZ/mNIbcsaNUAWSEEzRCkPmrl6/gLqeRO0sWa83liFmp0dyGDaR5ChUoHAPHvsBSC6Xf2BkDnoCMPB7f1w=="
	sessionKey := "xXrDRVNCjlq2hZ+ePouEPg=="
	iv := "4UMSl6uqdontQIHl/i7ojg=="

	// encryptedData := "C2R/vkmHAOhMq4/6KlrAWsYAGH6PHPTAs5jf2rJVF0keEMF1RzcbRBVDVpZVsy335OsDL1tZ7HDLyhKimFUCEP45fZDnlTp6FgV2zW4jY9tWqCqxUJ/M6o1FvlHk27FM3XIGXlxdXanvJ3KVdbtYwKxlwbJ9on6k5JL3w90Md3wE0IvQquBRTkWCfa5nJr38I3SR2VBFjyE+vnoFx2tqX31ZfY4zanr+ts1pno/VAfuXkpnnlvINir9HiEBnIPipLXkxcd/XlSPF2Osf66DSHj7WDHAqJKt4yKgEN+zt0cYT0kSZEGSJypRFGpsRAESzqmkUIE0JQW7WQANfc4W/5PpXEDXGYdv/FKt1LT3cqg0oHHjxdXojhbNR4T4dNPa+4rfbV2OcEl4m2CgwQLulb6uxEcBHD/hSUPuUSr5IHNpakKZrlDgBTyJgJs2679x+wCCHJRmLR77PgSGxh1D3rFq1lMpaZkahO6guSi1rdSQ6URwOgbudVM3WNwgwZ+Ga"
	// sessionKey := "xXrDRVNCjlq2hZ+ePouEPg=="
	// iv := "oi4qlhn1DjAKDedxHrDHNw=="
	result, err := api.SNSDecodeMiniProgramData(encryptedData, sessionKey, iv)
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(string(result))
	sugarLogger.Debug(len(result))
}

func TestSNSGetUserInfo(t *testing.T) {
	result, err := api.SNSGetUserInfo("38_l84lcm8hNHIByEaC2JZkBz4F1Lu6xWkADYMVUQ3e3psrTaWS7cz8EgZpvAn5xUwLTLZZZez4oCkVQ9RW0C8BFscWKJhMSnQq0bG287iEUyQ", "071GLDkl2GTdG64RyXll2GXXe54GLDkc")
	if err != nil {
		t.Fatal(err.Error())
	}
	sugarLogger.Debug(result)
}

func TestSNSSendGoodsOrder(t *testing.T) {
	param := &SNSSendOrderParameter{
		OrderKey: struct {
			OrderNumberType int    `json:"order_number_type"`
			TransactionId   string `json:"transaction_id"`
			Mchid           string `json:"mchid"`
			OutTradeNo      string `json:"out_trade_no"`
		}{
			OrderNumberType: 2,
			TransactionId:   "4200003129202603312111844342",
		},
		LogisticsType:  1,
		DeliveryMode:   1,
		IsAllDelivered: false,
		ShippingList: append([]ShippingList{}, ShippingList{
			TrackingNo:     "88512672858565",
			ExpressCompany: "YD",
			ItemDesc:       "背心袋",
			Contact: struct {
				ConsignorContact string `json:"consignor_contact"`
				ReceiverContact  string `json:"receiver_contact"`
			}{},
		}),
		UploadTime: time.Now().Format(time.RFC3339),
		Payer: struct {
			Openid string `json:"openid"`
		}{
			Openid: "ojWb10PPi04pA8QvKZqUfoe3eRSs",
		},
	}

	api.SNSSendGoodsOrder(param)
}

func TestSNSDeliveryGoodsOrder(t *testing.T) {
	api.SNSDeliveryGoodsOrder(&DeliveryOrder{
		TransactionId:   "4200003007202603198574473654",
		MerchantId:      "",
		MerchantTradeNo: "",
		SubMerchantId:   "",
		ReceivedTime:    time.Now().Unix(),
	})
}

func TestName(t *testing.T) {
	vendorId := 113
	fromVendorID := utils.Str2Int(string(utils.Int2Str(vendorId)[0]))
	to := utils.Str2Int(string(utils.Int2Str(vendorId)[1:]))
	fmt.Println(fromVendorID)
	fmt.Println(to)
}
