云闪付
This commit is contained in:
parent
44780174fb
commit
686b1e54cf
|
@ -11,8 +11,6 @@ import (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AppId string `json:"app_id"`
|
AppId string `json:"app_id"`
|
||||||
BaseUri string `json:"base_uri"`
|
|
||||||
|
|
||||||
ChNlId string `json:"chnlId"` // 渠道方代码
|
ChNlId string `json:"chnlId"` // 渠道方代码
|
||||||
IV string `json:"iv"` // 加密密钥
|
IV string `json:"iv"` // 加密密钥
|
||||||
KEY string `json:"key"` // 加密密钥
|
KEY string `json:"key"` // 加密密钥
|
||||||
|
|
|
@ -16,6 +16,8 @@ const (
|
||||||
CookieValue = "union_pay_cpn"
|
CookieValue = "union_pay_cpn"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const baseUri = "https://openapi.unionpay.com"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
orderMethod = "/upapi/mkt/cpn/couponAcquire/v1"
|
orderMethod = "/upapi/mkt/cpn/couponAcquire/v1"
|
||||||
orderBizMethod = "mkt.cpn.couponAcquire.v1"
|
orderBizMethod = "mkt.cpn.couponAcquire.v1"
|
||||||
|
@ -43,7 +45,7 @@ func (p *UnionPayCpnService) Order(ctx context.Context, request *proto.OrderRequ
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response po.OrderResp
|
var response po.OrderResp
|
||||||
url := fmt.Sprintf("%s%s", c.BaseUri, orderMethod)
|
url := fmt.Sprintf("%s%s", baseUri, orderMethod)
|
||||||
err = requests.URL(url).Headers(headers(c, uv, orderBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
err = requests.URL(url).Headers(headers(c, uv, orderBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||||
|
@ -62,7 +64,7 @@ func (p *UnionPayCpnService) Query(ctx context.Context, request *proto.QueryRequ
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response po.QueryResp
|
var response po.QueryResp
|
||||||
url := fmt.Sprintf("%s%s", conf.BaseUri, queryMethod)
|
url := fmt.Sprintf("%s%s", baseUri, queryMethod)
|
||||||
err = requests.URL(url).Headers(headers(conf, uv, queryBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
err = requests.URL(url).Headers(headers(conf, uv, queryBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
func config() []byte {
|
func config() []byte {
|
||||||
c := &Config{
|
c := &Config{
|
||||||
AppId: "up_49pau3fu6latj_03h",
|
AppId: "up_49pau3fu6latj_03h",
|
||||||
BaseUri: "https://openapi.unionpay.com",
|
|
||||||
ChNlId: "8091",
|
ChNlId: "8091",
|
||||||
IV: "0123456789123456",
|
IV: "0123456789123456",
|
||||||
KEY: "16fb034dead44ff6f599b1ca373ccfd1",
|
KEY: "16fb034dead44ff6f599b1ca373ccfd1",
|
||||||
|
@ -23,6 +22,14 @@ func config() []byte {
|
||||||
return marshal
|
return marshal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfig(t *testing.T) {
|
||||||
|
t.Run("TestConfig", func(t *testing.T) {
|
||||||
|
c := config()
|
||||||
|
fmt.Printf("%+s\n", string(c))
|
||||||
|
assert.NotEmpty(t, c)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var server = &UnionPayCpnService{}
|
var server = &UnionPayCpnService{}
|
||||||
|
|
||||||
func TestOrder(t *testing.T) {
|
func TestOrder(t *testing.T) {
|
||||||
|
|
|
@ -11,8 +11,6 @@ import (
|
||||||
|
|
||||||
type Config struct {
|
type Config struct {
|
||||||
AppId string `json:"app_id"`
|
AppId string `json:"app_id"`
|
||||||
BaseUri string `json:"base_uri"`
|
|
||||||
|
|
||||||
ChNlId string `json:"chnlId"` // 渠道方代码
|
ChNlId string `json:"chnlId"` // 渠道方代码
|
||||||
IV string `json:"iv"` // 加密密钥
|
IV string `json:"iv"` // 加密密钥
|
||||||
KEY string `json:"key"` // 加密密钥
|
KEY string `json:"key"` // 加密密钥
|
||||||
|
|
|
@ -18,6 +18,8 @@ const (
|
||||||
CookieValue = "union_pay_redpack"
|
CookieValue = "union_pay_redpack"
|
||||||
)
|
)
|
||||||
|
|
||||||
|
const baseUri = "https://openapi.unionpay.com"
|
||||||
|
|
||||||
const (
|
const (
|
||||||
orderMethod = "/upapi/mkt/pnt/pntAcquire/v1"
|
orderMethod = "/upapi/mkt/pnt/pntAcquire/v1"
|
||||||
orderBizMethod = "mkt.pnt.pntAcquire.v1"
|
orderBizMethod = "mkt.pnt.pntAcquire.v1"
|
||||||
|
@ -43,7 +45,7 @@ func (p *UnionPayCpnService) Order(ctx context.Context, request *proto.OrderRequ
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response po.OrderResp
|
var response po.OrderResp
|
||||||
url := fmt.Sprintf("%s%s", c.BaseUri, orderMethod)
|
url := fmt.Sprintf("%s%s", baseUri, orderMethod)
|
||||||
err = requests.URL(url).Headers(headers(c, uv, orderBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
err = requests.URL(url).Headers(headers(c, uv, orderBizMethod)).BodyJSON(uv).ToJSON(&response).Fetch(ctx)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
return nil, fmt.Errorf("请求异常,msg:" + err.Error())
|
||||||
|
@ -65,7 +67,7 @@ func (p *UnionPayCpnService) Query(ctx context.Context, request *proto.QueryRequ
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
var response po.QueryResp
|
var response po.QueryResp
|
||||||
url := fmt.Sprintf("%s%s", c.BaseUri, queryMethod)
|
url := fmt.Sprintf("%s%s", baseUri, queryMethod)
|
||||||
|
|
||||||
h := new(http.Client)
|
h := new(http.Client)
|
||||||
h.Timeout = 20 * time.Second
|
h.Timeout = 20 * time.Second
|
||||||
|
|
|
@ -12,7 +12,6 @@ import (
|
||||||
func config() []byte {
|
func config() []byte {
|
||||||
c := &Config{
|
c := &Config{
|
||||||
AppId: "up_49pau3fu6latj_03h",
|
AppId: "up_49pau3fu6latj_03h",
|
||||||
BaseUri: "https://openapi.unionpay.com",
|
|
||||||
ChNlId: "8091",
|
ChNlId: "8091",
|
||||||
IV: "0123456789123456",
|
IV: "0123456789123456",
|
||||||
KEY: "16fb034dead44ff6f599b1ca373ccfd1",
|
KEY: "16fb034dead44ff6f599b1ca373ccfd1",
|
||||||
|
@ -26,6 +25,14 @@ func config() []byte {
|
||||||
return marshal
|
return marshal
|
||||||
}
|
}
|
||||||
|
|
||||||
|
func TestConfig(t *testing.T) {
|
||||||
|
t.Run("TestConfig", func(t *testing.T) {
|
||||||
|
c := config()
|
||||||
|
fmt.Printf("%+s\n", string(c))
|
||||||
|
assert.NotEmpty(t, c)
|
||||||
|
})
|
||||||
|
}
|
||||||
|
|
||||||
var server = &UnionPayCpnService{}
|
var server = &UnionPayCpnService{}
|
||||||
|
|
||||||
func TestOrder(t *testing.T) {
|
func TestOrder(t *testing.T) {
|
||||||
|
|
Loading…
Reference in New Issue