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-19 09:05:49 +08:00
|
|
|
err := configcenter.LoadConfig("/Users/erwin/wishpalv2/service/etc/mix/mix-local.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{
|
2024-02-19 09:05:49 +08:00
|
|
|
OutTradeNo: "1744218982338015232",
|
|
|
|
RefundAmount: 100,
|
2024-02-18 23:47:58 +08:00
|
|
|
RefundReason: "测试退款",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(util.ToJson(resp))
|
|
|
|
}
|
2024-02-19 09:05:49 +08:00
|
|
|
|
|
|
|
func TestAlipayClient_UniTransfer(t *testing.T) {
|
|
|
|
cli := GetAlipayClientByAppId(AppIdXinYiDaoLe)
|
|
|
|
resp, err := cli.UniTransfer(context.Background(), &UniTransferParam{
|
|
|
|
OutBizNo: idgenerator.GenWithdrawOrderId(),
|
|
|
|
Amount: 10,
|
|
|
|
Title: "提现测试",
|
|
|
|
AlipayLoginId: "lwl0608@foxmail.com",
|
|
|
|
AlipayName: "李旺林",
|
|
|
|
})
|
|
|
|
if err != nil {
|
|
|
|
fmt.Println(err.Error())
|
|
|
|
return
|
|
|
|
}
|
|
|
|
fmt.Println(util.ToJson(resp))
|
|
|
|
}
|