This commit is contained in:
李子铭 2024-12-10 16:02:57 +08:00
parent b597b9e664
commit c3c84f4519
2 changed files with 13 additions and 4 deletions

View File

@ -29,23 +29,27 @@ func (s *AlipayCpnService) Order(ctx context.Context, request *proto.OrderReques
if err != nil {
return nil, err
}
poReq, err := orderReq(request.Order, request.Product)
if err != nil {
return nil, proto.ErrorParamFail(err.Error())
}
param, err := c.paramReq(poReq, orderMethod)
if err != nil {
return nil, proto.ErrorParamFail(err.Error())
}
uv, err := req(c, param)
if err != nil {
return nil, err
}
bodyBytes, _, err := Post(ctx, uv)
_, bodyBytes, err := Post(ctx, uv)
if err != nil {
return nil, err
}
var response *po.OrderResp
if err = json.Unmarshal(bodyBytes, &response); err != nil {
return nil, proto.ErrorResponseFail(err.Error())
@ -59,20 +63,23 @@ func (s *AlipayCpnService) Query(ctx context.Context, request *proto.QueryReques
if err != nil {
return nil, err
}
poReq, err := queryReq(request.Order)
if err != nil {
return nil, proto.ErrorParamFail(err.Error())
}
param, err := c.paramReq(poReq, queryMethod)
if err != nil {
return nil, proto.ErrorParamFail(err.Error())
}
uv, err := req(c, param)
if err != nil {
return nil, err
}
bodyBytes, _, err := Post(ctx, uv)
_, bodyBytes, err := Post(ctx, uv)
if err != nil {
return nil, err
}
@ -90,6 +97,7 @@ func (s *AlipayCpnService) Notify(_ context.Context, request *proto.NotifyReques
if err != nil {
return nil, err
}
n := notifyReq(request)
b, err := Verify(n, c.Npk)
@ -99,5 +107,6 @@ func (s *AlipayCpnService) Notify(_ context.Context, request *proto.NotifyReques
if !b {
return nil, proto.ErrorSignFail("验签失败")
}
return notifyResp(n)
}

View File

@ -43,7 +43,7 @@ func req(config *Config, req *po.Param) (url.Values, error) {
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{
"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 {
return nil, nil, proto.ErrorRequestFail(err.Error())
}
return respBody, respHeader, nil
return respHeader, respBody, nil
}
func Sign(data string, privateKeyPEM []byte) (string, error) {