wxpay to wxpayapi
This commit is contained in:
94
platformapi/wxpayapi/wxpayapi_test.go
Normal file
94
platformapi/wxpayapi/wxpayapi_test.go
Normal file
@@ -0,0 +1,94 @@
|
||||
package wxpayapi
|
||||
|
||||
import (
|
||||
"io/ioutil"
|
||||
"strings"
|
||||
"testing"
|
||||
|
||||
"git.rosy.net.cn/baseapi"
|
||||
"git.rosy.net.cn/baseapi/utils"
|
||||
"github.com/clbanning/mxj"
|
||||
|
||||
"go.uber.org/zap"
|
||||
)
|
||||
|
||||
var (
|
||||
api *API
|
||||
sugarLogger *zap.SugaredLogger
|
||||
)
|
||||
|
||||
func init() {
|
||||
logger, _ := zap.NewDevelopment()
|
||||
sugarLogger = logger.Sugar()
|
||||
baseapi.Init(sugarLogger)
|
||||
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) {
|
||||
result, err := api.OrderQuery("4200000411201910186159598703", "")
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(result, false))
|
||||
}
|
||||
|
||||
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: orderNo,
|
||||
SpbillCreateIP: "114.114.114.114",
|
||||
TradeType: TradeTypeNative,
|
||||
TotalFee: 1,
|
||||
})
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
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>
|
||||
<out_refund_no><![CDATA[131811191610442717309]]></out_refund_no>
|
||||
<out_trade_no><![CDATA[71106718111915575302817]]></out_trade_no>
|
||||
<refund_account><![CDATA[REFUND_SOURCE_RECHARGE_FUNDS]]></refund_account>
|
||||
<refund_fee><![CDATA[3960]]></refund_fee>
|
||||
<refund_id><![CDATA[50000408942018111907145868882]]></refund_id>
|
||||
<refund_recv_accout><![CDATA[支付用户零钱]]></refund_recv_accout>
|
||||
<refund_request_source><![CDATA[API]]></refund_request_source>
|
||||
<refund_status><![CDATA[SUCCESS]]></refund_status>
|
||||
<settlement_refund_fee><![CDATA[3960]]></settlement_refund_fee>
|
||||
<settlement_total_fee><![CDATA[3960]]></settlement_total_fee>
|
||||
<success_time><![CDATA[2018-11-19 16:24:13]]></success_time>
|
||||
<total_fee><![CDATA[3960]]></total_fee>
|
||||
<transaction_id><![CDATA[4200000215201811190261405420]]></transaction_id>
|
||||
</root>
|
||||
|
||||
`, "\\n", "\n", -1)
|
||||
mv, err := mxj.NewMapXml([]byte(xmlStr))
|
||||
if err != nil {
|
||||
t.Fatal(err)
|
||||
}
|
||||
t.Log(utils.Format4Output(mv, false))
|
||||
}
|
||||
Reference in New Issue
Block a user