微信支付支持退款

This commit is contained in:
gazebo
2019-11-21 09:36:37 +08:00
parent 12fda0dd48
commit 39c5845b2f
4 changed files with 164 additions and 38 deletions

View File

@@ -1,6 +1,7 @@
package wxpay
import (
"io/ioutil"
"strings"
"testing"
@@ -20,8 +21,10 @@ func init() {
logger, _ := zap.NewDevelopment()
sugarLogger = logger.Sugar()
baseapi.Init(sugarLogger)
api = New("wx4b5930c13f8b1170", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1390686702")
certPEMBlock, _ := ioutil.ReadFile("1390686702_20190115_cert/apiclient_cert.pem")
keyPEMBlock, _ := ioutil.ReadFile("1390686702_20190115_cert/apiclient_key.pem")
api = NewWithCertificate("wx4b5930c13f8b1170", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1390686702", certPEMBlock, keyPEMBlock)
// api = New("wx4b5930c13f8b1170", "XKJPOIHJ233adf01KJIXlIeQDSDKFJAD", "1390686702")
}
func TestOrderQuery(t *testing.T) {
@@ -33,10 +36,12 @@ func TestOrderQuery(t *testing.T) {
}
func TestCreateUnifiedOrder(t *testing.T) {
orderNo := "367609100BA711EAAA20186590E02977" // utils.GetUUID()
// t.Log(orderNo)
result, err := api.CreateUnifiedOrder(&CreateOrderParam{
Body: "这里一个测试商品",
NotifyURL: "http://callback.test.jxc4.com/wxpay/msg/",
OutTradeNo: utils.GetUUID(),
OutTradeNo: orderNo,
SpbillCreateIP: "114.114.114.114",
TradeType: TradeTypeNative,
TotalFee: 1,
@@ -47,6 +52,21 @@ func TestCreateUnifiedOrder(t *testing.T) {
t.Log(utils.Format4Output(result, false))
}
func TestPayRefund(t *testing.T) {
result, err := api.PayRefund(&PayRefundParam{
TransactionID: "",
OutTradeNo: "8E0DD6260B7511EA908C186590E02977",
NotifyURL: "http://callback.test.jxc4.com/wxpay/msg/",
OutRefundNo: utils.GetUUID(),
TotalFee: 1,
RefundFee: 1,
})
if err != nil {
t.Fatal(err)
}
t.Log(utils.Format4Output(result, false))
}
func TestXml2Json(t *testing.T) {
xmlStr := strings.Replace(`
<root>