ysf
This commit is contained in:
parent
b597b9e664
commit
c3c84f4519
|
@ -29,23 +29,27 @@ func (s *AlipayCpnService) Order(ctx context.Context, request *proto.OrderReques
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
poReq, err := orderReq(request.Order, request.Product)
|
poReq, err := orderReq(request.Order, request.Product)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, proto.ErrorParamFail(err.Error())
|
return nil, proto.ErrorParamFail(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
param, err := c.paramReq(poReq, orderMethod)
|
param, err := c.paramReq(poReq, orderMethod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, proto.ErrorParamFail(err.Error())
|
return nil, proto.ErrorParamFail(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
uv, err := req(c, param)
|
uv, err := req(c, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyBytes, _, err := Post(ctx, uv)
|
_, bodyBytes, err := Post(ctx, uv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
var response *po.OrderResp
|
var response *po.OrderResp
|
||||||
if err = json.Unmarshal(bodyBytes, &response); err != nil {
|
if err = json.Unmarshal(bodyBytes, &response); err != nil {
|
||||||
return nil, proto.ErrorResponseFail(err.Error())
|
return nil, proto.ErrorResponseFail(err.Error())
|
||||||
|
@ -59,20 +63,23 @@ func (s *AlipayCpnService) Query(ctx context.Context, request *proto.QueryReques
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
poReq, err := queryReq(request.Order)
|
poReq, err := queryReq(request.Order)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, proto.ErrorParamFail(err.Error())
|
return nil, proto.ErrorParamFail(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
param, err := c.paramReq(poReq, queryMethod)
|
param, err := c.paramReq(poReq, queryMethod)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, proto.ErrorParamFail(err.Error())
|
return nil, proto.ErrorParamFail(err.Error())
|
||||||
}
|
}
|
||||||
|
|
||||||
uv, err := req(c, param)
|
uv, err := req(c, param)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
bodyBytes, _, err := Post(ctx, uv)
|
_, bodyBytes, err := Post(ctx, uv)
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
@ -90,6 +97,7 @@ func (s *AlipayCpnService) Notify(_ context.Context, request *proto.NotifyReques
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, err
|
return nil, err
|
||||||
}
|
}
|
||||||
|
|
||||||
n := notifyReq(request)
|
n := notifyReq(request)
|
||||||
|
|
||||||
b, err := Verify(n, c.Npk)
|
b, err := Verify(n, c.Npk)
|
||||||
|
@ -99,5 +107,6 @@ func (s *AlipayCpnService) Notify(_ context.Context, request *proto.NotifyReques
|
||||||
if !b {
|
if !b {
|
||||||
return nil, proto.ErrorSignFail("验签失败")
|
return nil, proto.ErrorSignFail("验签失败")
|
||||||
}
|
}
|
||||||
|
|
||||||
return notifyResp(n)
|
return notifyResp(n)
|
||||||
}
|
}
|
||||||
|
|
|
@ -43,7 +43,7 @@ func req(config *Config, req *po.Param) (url.Values, error) {
|
||||||
return uv, nil
|
return uv, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Post(ctx context.Context, uv url.Values) ([]byte, http.Header, error) {
|
func Post(ctx context.Context, uv url.Values) (http.Header, []byte, error) {
|
||||||
h := http.Header{
|
h := http.Header{
|
||||||
"Content-Type": []string{"application/x-www-form-urlencoded"},
|
"Content-Type": []string{"application/x-www-form-urlencoded"},
|
||||||
}
|
}
|
||||||
|
@ -51,7 +51,7 @@ func Post(ctx context.Context, uv url.Values) ([]byte, http.Header, error) {
|
||||||
if err != nil {
|
if err != nil {
|
||||||
return nil, nil, proto.ErrorRequestFail(err.Error())
|
return nil, nil, proto.ErrorRequestFail(err.Error())
|
||||||
}
|
}
|
||||||
return respBody, respHeader, nil
|
return respHeader, respBody, nil
|
||||||
}
|
}
|
||||||
|
|
||||||
func Sign(data string, privateKeyPEM []byte) (string, error) {
|
func Sign(data string, privateKeyPEM []byte) (string, error) {
|
||||||
|
|
Loading…
Reference in New Issue