Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

微信支付下单返回err=nil但是原始数据StatusCode=400错误 #514

Closed
lisgroup opened this issue Jul 11, 2024 · 5 comments
Closed

Comments

@lisgroup
Copy link

lisgroup commented Jul 11, 2024

微信支付下单的代码:

response, err := payment.Order.JSAPITransaction(ctx, options)

如果直接判断 err 为nil,但是微信返回的原始错误为:

{"code":"PARAM_ERROR","message":"appid和openid不匹配"}

type ResponseUnitfy struct {
response.ResponsePayment

PrepayID string `json:"prepay_id"`

}
结构体都是空。

err = client.HttpHelper.ParseResponseBodyContent(returnResponse, outBody) 封装的时候没有判断具体数据错误问题。

@Matrix-X
Copy link
Contributor

你这个不能判断error为依据,因为请求没有出错。

这里的err是请求过程中异常报错。

而微信返回的内容是正常的,给了业务code的错误信息, 你要通过判断code如果不等于0的情况,然后做相应处理

@lisgroup
Copy link
Author

你这个不能判断error为依据,因为请求没有出错。

这里的err是请求过程中异常报错。

而微信返回的内容是正常的,给了业务code的错误信息, 你要通过判断code如果不等于0的情况,然后做相应处理

要加上这样处理吗:

response, err := payment.Order.JSAPITransaction(ctx, options)

if err != nil {
    return nil, err
}
if response.Code != "" {
   return nil, errors.New(response.Message)
}

@Matrix-X
Copy link
Contributor

是的,官网返回的code,正常应该是0

@lisgroup
Copy link
Author

我看请求的 src/payment/kernel/baseClient.go 295行代码:

returnResponse, err := df.Request()
	if err != nil {
		return returnResponse, err
	}

发送http请求后,没有找到close的地方,这个会导致内存泄漏吗?

@Matrix-X
Copy link
Contributor

这个封装的层,还在看底层的请求层
你也可以内存工具看看。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants