卡密,直充,回调

This commit is contained in:
李子铭 2024-11-15 16:40:51 +08:00
parent b71aa93e65
commit 84a6cb208f
5 changed files with 23 additions and 17 deletions

View File

@ -3,6 +3,7 @@ package card
import (
"bytes"
"context"
"encoding/json"
"gitea.cdlsxd.cn/sdk/plugin/dctw/v1/core"
"github.com/stretchr/testify/assert"
"io/ioutil"
@ -26,7 +27,7 @@ func TestCard_Order(t *testing.T) {
req := &Order{
Number: 1,
MerchantId: "23329",
OutTradeNo: "test_card_zltx_1",
OutTradeNo: "test_card_zltx_2",
ProductId: "222",
Mobile: "18666666666",
NotifyUrl: "https://gateway.dev.cdlsxd.cn/yxh5api/v1/order/direct/notify",
@ -56,7 +57,7 @@ func TestCard_Query(t *testing.T) {
a := &Card{DctWServer: server}
req := &Query{
MerchantId: "23329",
OutTradeNo: "test_card_zltx_1",
OutTradeNo: "test_card_zltx_2",
Version: "1.0",
}
resp, cardCode, err := a.Query(context.Background(), req)
@ -84,14 +85,16 @@ func TestCard_Notify(t *testing.T) {
}
a := &Card{DctWServer: server}
body := []byte(`{"merchantId":23329,"outTradeNo":"202409111714224026320002","rechargeAccount":"18512869479","sign":"474ACB521DEE99551153B6CE108FD06D","status":"01"}`)
body := []byte(`{"merchantId":"23329","outTradeNo":"test_card_zltx_2","status":"01"}`)
httpHeaderBytes := []byte(`{"Accept-Encoding":["gzip, deflate, br"],"Authorization":["MD5 appid=1,sign=6B48E95EAEE20EE4525BEF0112493711"],"Connection":["close"],"Content-Length":["68"],"Content-Type":["application/json"],"Cookie":[""],"User-Agent":["GuzzleHttp/6.5.5 curl/7.69.1 PHP/7.2.34"],"X-Remoteaddr":["172.21.0.1"]}`)
headers := make(http.Header)
headers.Set(core.SignKeyName, "MD5 appid=101,sign=292e21f3683219369cf68dede0d45730")
headers.Set("Content-Type", core.ApplicationJSON)
httpHeaders := make(http.Header)
if err = json.Unmarshal(httpHeaderBytes, &httpHeaders); err != nil {
t.Fatal(err)
}
var httpRequest = &http.Request{
Header: headers,
Header: httpHeaders,
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
}
resp, cardCode, err := a.Notify(context.Background(), httpRequest)

View File

@ -39,7 +39,7 @@ type QueryResp struct {
}
type Notify struct {
MerchantId int `json:"merchantId"`
MerchantId string `json:"merchantId"`
OutTradeNo string `json:"outTradeNo"`
TradeNo string `json:"tradeNo"`
RechargeAccount string `json:"rechargeAccount"`

View File

@ -3,6 +3,7 @@ package direct
import (
"bytes"
"context"
"encoding/json"
"gitea.cdlsxd.cn/sdk/plugin/dctw/v1/core"
"github.com/stretchr/testify/assert"
"io/ioutil"
@ -26,7 +27,7 @@ func TestDirect_Order(t *testing.T) {
req := &Order{
Number: 1,
MerchantId: "25537",
OutTradeNo: "test_zltx_direct_1",
OutTradeNo: "test_zltx_direct_2",
ProductId: "101",
AccountType: 1,
RechargeAccount: "18666666666",
@ -57,7 +58,7 @@ func TestDirect_Query(t *testing.T) {
a := &Direct{DctWServer: server}
req := &Query{
MerchantId: "25537",
OutTradeNo: "test_zltx_direct_1",
OutTradeNo: "test_zltx_direct_2",
Version: "1.0",
}
resp, err := a.Query(context.Background(), req)
@ -84,14 +85,16 @@ func TestDirect_Notify(t *testing.T) {
}
a := &Direct{DctWServer: server}
body := []byte(`{"merchantId":23329,"outTradeNo":"202409111714224026320002","rechargeAccount":"18512869479","sign":"474ACB521DEE99551153B6CE108FD06D","status":"01"}`)
body := []byte(`{"merchantId":"25537","outTradeNo":"test_zltx_direct_2","status":"03","rechargeAccount":"18666666666"}`)
httpHeaderBytes := []byte(`{"Accept-Encoding":["gzip, deflate, br"],"Authorization":["MD5 appid=1,sign=642F82644ABB88E73C04F7881B93E6FA"],"Connection":["close"],"Content-Length":["102"],"Content-Type":["application/json"],"Cookie":[""],"User-Agent":["GuzzleHttp/6.5.5 curl/7.69.1 PHP/7.2.34"],"X-Remoteaddr":["172.21.0.1"]}`)
headers := make(http.Header)
headers.Set(core.SignKeyName, "MD5 appid=101,sign=292e21f3683219369cf68dede0d45730")
headers.Set("Content-Type", core.ApplicationJSON)
httpHeaders := make(http.Header)
if err = json.Unmarshal(httpHeaderBytes, &httpHeaders); err != nil {
t.Fatal(err)
}
var httpRequest = &http.Request{
Header: headers,
Header: httpHeaders,
Body: ioutil.NopCloser(bytes.NewBuffer(body)),
}
resp, err := a.Notify(context.Background(), httpRequest)

View File

@ -38,7 +38,7 @@ type QueryResp struct {
}
type Notify struct {
MerchantId int `json:"merchantId"`
MerchantId string `json:"merchantId"`
OutTradeNo string `json:"outTradeNo"`
RechargeAccount string `json:"rechargeAccount"`
TradeNo string `json:"tradeNo"`

View File

@ -184,7 +184,7 @@ func (c *DctWServer) Request(_ context.Context, request DctWRequest, path string
return nil, err
}
if c.DeBug {
fmt.Printf("resp.Status:%s\n", resp.Status)
fmt.Printf("resp.status:%s\n", resp.Status)
fmt.Printf("resp.body:%s\n", string(bodyBytes))
fmt.Printf("resp.headers:%+v\n", resp.Header)
}