service/library/payclients/alipaycli/client_test.go

69 lines
1.4 KiB
Go
Raw Normal View History

2023-12-21 22:17:40 +08:00
package alipaycli
import (
"context"
"fmt"
"os"
2024-02-12 23:41:41 +08:00
"service/app/mix/conf"
2024-02-03 17:23:08 +08:00
"service/bizcommon/util"
2023-12-21 22:17:40 +08:00
"service/library/configcenter"
"service/library/idgenerator"
"testing"
)
func TestMain(m *testing.M) {
2024-02-12 23:41:41 +08:00
cfg := new(conf.ConfigSt)
2024-02-18 23:47:58 +08:00
err := configcenter.LoadConfig("/Users/erwin/wishpalv2/service/etc/mix/mix-prod.yaml", cfg)
2024-02-12 23:41:41 +08:00
if err != nil {
fmt.Printf("%v\n", err)
2023-12-21 22:17:40 +08:00
}
2024-02-12 23:41:41 +08:00
2024-02-18 23:47:58 +08:00
err = InitMulti(cfg.Alipay, cfg.AlipayMYTS)
2023-12-21 22:17:40 +08:00
if err != nil {
fmt.Println(err)
os.Exit(1)
}
m.Run()
}
2024-02-12 23:41:41 +08:00
func TestAlipayClient_WapPay(t *testing.T) {
2024-02-18 23:47:58 +08:00
cli := GetDefaultAlipayClient()
2024-02-12 23:41:41 +08:00
paramStr, err := cli.WapPay(context.Background(), &WapPayParam{
2023-12-21 22:17:40 +08:00
OutTradeNo: idgenerator.GenOrderId(),
Subject: "哈哈",
TotalAmount: 1,
TimeOutSeconds: 0,
})
if err != nil {
fmt.Println(err)
return
}
fmt.Println(paramStr)
}
2024-02-03 17:23:08 +08:00
func TestAlipayClient_QueryOrder(t *testing.T) {
2024-02-18 23:47:58 +08:00
cli := GetDefaultAlipayClient()
2024-02-03 17:23:08 +08:00
resp, err := cli.QueryOrder(context.Background(), &QueryOrderParam{
OutTradeNo: "1750539072771731456",
})
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(util.ToJson(resp))
}
2024-02-18 23:47:58 +08:00
func TestAlipayClient_RefundOne(t *testing.T) {
cli := GetAlipayClientByAppId(AppIdXinYiDaoLe)
resp, err := cli.RefundOne(context.Background(), &RefundOneParam{
OutTradeNo: "1750539072771731456",
RefundAmount: 0,
RefundReason: "测试退款",
})
if err != nil {
fmt.Println(err.Error())
return
}
fmt.Println(util.ToJson(resp))
}