package tonglianpayapi

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

func TestSignRSA(t *testing.T) {
	sginParma := map[string]interface{}{
		"appid":     "00000051",
		"cusid":     "990581007426001",
		"randomstr": "82712208",
		"signtype":  "RSA",
		"trxid":     "112094120001088317",
		"version":   "11",
	}
	sgin, _ := api.signParamRSA(sginParma, cusRsaPrivateTestKey)
	fmt.Println(sgin)
	data2 := `ce6EAOj4rhoBMJM5MJCNG4qQ/CVMTWkoRuSGpSzRAnD3U3V5QyHkQUEej2eZXRaa+qSbw2/IJJSPV0sPuAia1+ccb7OnvxyZqkV9wQyimX6qAMz0K+UWFhQ5McCcQ/XsFhhezoVd5QgL7PtdvuK1AtjuzA3J9yzNmwuPssPnKnc=`
	fmt.Println(sgin == data2)
}

func TestOnlinePayData(t *testing.T) {
	param := &OnlinePayParam{
		Orgid:         "",
		Cusid:         "", // 不用
		Appid:         "", // 不用
		Version:       "", // 不用
		Randomstr:     "", // 不用
		Trxamt:        "1",
		Reqsn:         "202504221811",
		Body:          "测试订单",
		Remark:        "这是一个测试",
		Authcode:      "133040799834193135", // 支付授权码
		LimitPay:      "",
		GoodsTag:      "",
		Benefitdetail: "",
		SubAppid:      "",
		Chnlstoreid:   "666667",
		Subbranch:     "",
		Idno:          "",
		Extendparams:  "",
		Truename:      "",
		Asinfo:        "",
		Fqnum:         "",
		NotifyUrl:     "https://www.callback.com/tonglian/onlinePay",
		Signtype:      "RSA",
		Unpid:         "",
		Sign:          "",
		Terminfo:      "",
		Operatorid:    "",
	}
	terminfo := &TerminfoBase{
		Termno:         "N502F01147",
		Devicetype:     "10",
		Termsn:         "N502F01147",
		Encryptrandnum: "",
		Secrettext:     "",
		Appversion:     "",
		Longitude:      "+121.48352",
		Latitude:       "-03.561345",
		Deviceip:       "",
	}
	terminfoBByte, _ := json.Marshal(terminfo)
	param.Terminfo = string(terminfoBByte)
	api.CreateOnlineBankOrder(param)
}

func TestRefreshPayStatus(t *testing.T) {
	param := &PayTransactionStatusQuery{
		//Orgid:     "",
		//Cusid:     "",
		//Appid:     "",
		//Version:   "",
		Reqsn:     "202504221811",
		Trxid:     "",
		Randomstr: utils.GetUUID(),
		Signtype:  "RSA",
		Sign:      "",
	}
	api.QueryPayTransaction(param)
}

func TestOrderRefund(t *testing.T) {
	param := &OnLineOrderRefundParam{
		Trxamt:        utils.Int2Str(1),
		Reqsn:         "202504250924",
		Oldreqsn:      "202504221811",
		Oldtrxid:      "",
		Remark:        "测试退款",
		Benefitdetail: "",
		Randomstr:     utils.GetUUID(),
		Signtype:      EncryptionRsa,
		Sign:          "",
	}

	_, _, err := api.OrderRefund(param)
	fmt.Println(err)
}

func TestTLAddTerm(t *testing.T) {
	param := &AddTermReq{
		Termno:      fmt.Sprintf("%d00", 668470),
		Devicetype:  "11",
		Termsn:      fmt.Sprintf("%d00", 668470),
		Operation:   "00",
		Termstate:   "",
		Termaddress: fmt.Sprintf("%s-%s-%s-%s", "四川省", "成都市", "金牛区", "圃圆小筑"),
		Signtype:    "RSA",
		Sign:        "",
	}
	param.Termstate = "00"

	api.TLAddTerm(param)
}

func TestTLTLQueryTerm(t *testing.T) {
	param := &AddTermQuery{
		Termno:   "66847000",
		Signtype: "RSA",
		Sign:     "",
	}
	api.TLQueryTerm(param)
}

func Test111(t *testing.T) {
	aa := time.Since(time.Now().AddDate(0, 0, -5)) > 7*24*time.Hour
	fmt.Println(aa)
}
