package tiktok

import (
	"encoding/json"
	"fmt"
	"git.rosy.net.cn/baseapi"
	"go.uber.org/zap"
	"testing"
)

var (
	api         *API
	sugarLogger *zap.SugaredLogger
)

func init() {
	logger, _ := zap.NewDevelopment()
	sugarLogger = logger.Sugar()
	baseapi.Init(sugarLogger)
}

func TestCode(t *testing.T) {
	//a := New("5c08a0465cf0f996af254a03b6c2548defef87ad ", "tta6a1d01c399f264201")
	////data, err := a.GetTiktokToken("7aK7VOuXnlU2OIiFDFi_ssRX9vQdXtDekgW-yV77Q20rVsw8-8DX4ASbXMTA3Z-gr8tstJcgMgL04OFc-BgXB92DC6otQV6GQUiy-TzhpH109xZfZwhCKjt-OiI")
	//fmt.Println(err)
	//fmt.Println(data)
}

func TestCode2(t *testing.T) {
	a := New("5c08a0465cf0f996af254a03b6c2548defef87ad ", "tta6a1d01c399f264201")
	data, err := a.GetTiktokOauth("tYIYf03MgvPekdeWj91W3RhdzQMCovGG_QugelFswhWiZLdIwMFlMtC7PHZbl-JjrkwaonexoEahd1GDCS6K5jK4W7oegChlysU3kCw72cL965P0MWMyXdO_qeA")
	fmt.Println(err)
	fmt.Println(data)
}

func TestCode343(t *testing.T) {
	a := New("5c8492ec2744fb72bb6cc356983f3cfc317f85d4", "ttaceeda5333d7a7ab01")
	data, err := a.GetTiktokOauth("eDpIjQ2VdK4MC8wE9ORO63adZECE8no_yNLXQYPaILyLUXF24K02PNcs84lQeeJn68EQJPIiV6DO5z3vHoqLom4dr4Fy4KMcZK7O4a3yAHK0Vgs9Vc-2u9vLwAg")
	fmt.Println(err)
	fmt.Println(data)
}

//func TestCode343(t *testing.T) {
//	a := New("5c8492ec2744fb72bb6cc356983f3cfc317f85d4", "ttaceeda5333d7a7ab01")
//	data, err := a.GetTiktokOauth("-j_QmmDM7B-mjKKk9wcijMeUTAV75mNXbJI4rqabt1IMkDGEmmw1M0-azYJwoXNOrWaDeXlw4xNivEd-uobXuuZrtt7bNn-6AMzf8jvkXp6Jm3LPcP56KisO9w4")
//	fmt.Println(err)
//	fmt.Println(data)
//}

func TestCode22(t *testing.T) {
	fmt.Println(2&4 != 0)
	fmt.Println(2&2 != 0)
	fmt.Println(2&1 != 0)
	fmt.Println("==================")

	fmt.Println(3&4 != 0)
	fmt.Println(3&2 != 0)
	fmt.Println(3&1 != 0)
}

func TestGetToken(t *testing.T) {
	a := New("5c8492ec2744fb72bb6cc356983f3cfc317f85d4", "ttaceeda5333d7a7ab01")
	//a := New("5c08a0465cf0f996af254a03b6c2548defef87ad", "tta6a1d01c399f264201")
	err := a.GetTiktokToken()
	fmt.Println(err)
	fmt.Println(a.msgToken)
}

func TestFMT(t *testing.T) {
	fmt.Println(3&4 != 0)
	fmt.Println(3&2 != 0)
	fmt.Println(3&1 != 0)
	fmt.Println(0&512 != 0)
}

func TestJieXi(t *testing.T) {
	aa := "{\"msg\":\"{\\\"appid\\\":\\\"tta6a1d01c399f264201\\\",\\\"cp_orderno\\\":\\\"88392225672205\\\",\\\"cp_extra\\\":\\\"msg\\\",\\\"way\\\":\\\"1\\\",\\\"channel_no\\\":\\\"4307101087202206060852144781\\\",\\\"channel_gateway_no\\\":\\\"\\\",\\\"payment_order_no\\\":\\\"PCP2022060615343025356252572215\\\",\\\"out_channel_order_no\\\":\\\"4307101087202206060852144781\\\",\\\"total_amount\\\":2,\\\"status\\\":\\\"SUCCESS\\\",\\\"seller_uid\\\":\\\"70915459488196877170\\\",\\\"extra\\\":\\\"\\\",\\\"item_id\\\":\\\"\\\",\\\"paid_at\\\":1654500885,\\\"message\\\":\\\"\\\",\\\"order_id\\\":\\\"7106026546158143752\\\",\\\"trade_item_list\\\":null}\",\"msg_signature\":\"85d4b28842be7294f8440363735476f225fce095\",\"nonce\":\"1670\",\"timestamp\":\"1654500886\",\"type\":\"payment\"}"
	payInfo := &CallBackResult{}
	err := json.Unmarshal([]byte(aa), payInfo)
	fmt.Println("err==========", err)
	fmt.Println("payInfo===", payInfo.Msg)

	callback := &DetailCallBackMessage{}
	err2 := json.Unmarshal([]byte(payInfo.Msg), callback)
	fmt.Println("err==========", err2)
	fmt.Println("payInfo===", callback.PaymentOrderNo)
}

func TestRefund(t *testing.T) {
	a := New("5c08a0465cf0f996af254a03b6c2548defef87ad ", "tta6a1d01c399f264201")
	data, err := a.QueryRefundMsg()
	fmt.Println(err)
	fmt.Println(data)
}

func TestSQRefund(t *testing.T) {
	a := New("5c08a0465cf0f996af254a03b6c2548defef87ad ", "tta6a1d01c399f264201")
	cc := &RefundOrderReq{
		AppID:        a.GetAppID(),
		OutOrderNo:   "88392206436412",
		OutRefundNo:  "ceshi11100100044",
		Reason:       "协商一致",
		RefundAmount: 99,
		//CpExtra:      "msg",
		//NotifyURL:    "jxc3.com",
	}
	aa, err := a.RefundOrderTT(cc)
	fmt.Println(aa)
	fmt.Println(err)
}

func TestQrCode(t *testing.T) {
	//a := New("5c08a0465cf0f996af254a03b6c2548defef87ad ", "tta6a1d01c399f264201")

	//data, err := a.GetTiktokQrCode("storeID=668506")
	//fmt.Println("Err", err)
	//tiktokName := "tiktok" + utils.Int64ToStr(time.Now().Unix()) + ".jpg"
	//tiktokQrCode, err2 := jxutils.UploadExportContent([]byte(data["fakeData"].(string)), tiktokName)
	//fmt.Println(err2)
	//fmt.Println("tiktokQrCode", tiktokQrCode)
}
