service/library/payclients/wxpaycli/client_test.go

77 lines
1.6 KiB
Go

package wxpaycli
import (
"context"
"fmt"
"os"
"service/app/mix/conf"
"service/bizcommon/util"
"service/library/configcenter"
"service/library/idgenerator"
"testing"
)
func TestMain(m *testing.M) {
cfg := new(conf.ConfigSt)
err := configcenter.LoadConfig("/Users/erwin/wishpalv2/service/etc/mix/mix-local.yaml", cfg)
if err != nil {
fmt.Printf("%v\n", err)
}
err = Init(cfg.Wxpay)
if err != nil {
fmt.Println(err)
os.Exit(1)
}
m.Run()
}
func TestWxpayClient_NativePay(t *testing.T) {
cli := GetDefaultWxpayClient()
resp, err := cli.NativePay(context.Background(), &NativePayParam{
Description: "测试哈哈",
OutTradeNo: idgenerator.GenOrderId(),
TotalAmount: 1,
TimeOutSeconds: 3600 * 24,
})
if err != nil {
fmt.Println(err.Error())
return
}
t.Log(fmt.Sprintf("%#v", resp))
return
}
func TestWxpayClient_GetOpenIdByAuthCode(t *testing.T) {
cli := GetDefaultWxpayClient()
openid, _ := cli.GetOpenIdByAuthCode(context.Background(), "091dpIGa1VNiWG0RnnIa1wgqrW1dpIG6")
t.Log(openid)
return
}
func TestWxpayClient_JsapiPay(t *testing.T) {
cli := GetDefaultWxpayClient()
// 先获取openId
openid, err := cli.GetOpenIdByAuthCode(context.Background(), "091hyXFa1SDJXG0lBBGa1qSnw52hyXFZ")
if err != nil {
t.Log(err.Error())
return
}
// jsapi pay
p := &JsapiPayParam{
Description: "测试哈哈",
OutTradeNo: idgenerator.GenOrderId(),
TotalAmount: 1,
TimeOutSeconds: 3600 * 24,
OpenId: openid,
}
r, err := cli.JsapiPay(context.Background(), p)
if err != nil {
t.Log(err.Error())
return
}
t.Log(util.ToJson(r))
}