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

创建退款失败,微信响应Http头Authorization值格式错误 #263

Closed
FourLeafTec opened this issue Mar 1, 2023 · 10 comments
Closed
Labels
good first issue Good for newcomers

Comments

@FourLeafTec
Copy link
Contributor

SDK版本:3.0.10

Debug 日志:

2023/03/01 06:31:12 POST https://api.mch.weixin.qq.com/v3/refund/domestic/refunds 
request header: { 
        Content-Type:application/json
        Accept:*/*
} 
request body:{"amount":{"currency":"CNY","refund":1,"total":1},"body":"{\"amount\":{\"currency\":\"CNY\",\"refund\":1,\"total\":1},\"notify_url\":\"${notify_url}\",\"out_refund_no\":\"${out_refund_no}\",\"reason\":\"取消订单\",\"transaction_id\":\"${transaction_id}\"}","headers":{"Authorization":"WECHATPAY2-SHA256-RSA2048 mchid=\"1630225703\",nonce_str=\"WhN6IQEbEQo88t5oDNE2btVFRK2iFMDV\",timestamp=\"1677652272\",serial_no=\"6B57A53207B7B6EF3FA9F9E9D632AFC744510DB4\",signature=\"C7thxkndkJbQTNwkF8DAgxhFoHFILLvDwYhnbJp6OT3RTUSj1s/N3Sd+6YwKRuMzaRqJya9DAxsIPvxvK5DdZscWVp29UU+RehfBJ8ziW5I+DACy/PxDduU4IjwHivCmc0C4oSO+SG8OeaKqrYn37BfFANXMYu3H73UVitTvenKZuI20aDOoLQaWVocoOfQUCE21wQWphFyxTimG0OlUwzL+Vfz5S7qEiEDFP8qrj8tO6o5aJrtEdK+WONHjFGeyRjbDV9LHtIiltYTFgGrMYpqc6vIi20EMI3zyyE7f1sP6oE4GUwPxFfhNQNEd3M7grUWo5oMqdupK9C95zp0wgg==\""},"notify_url":"${notify_url}","out_refund_no":"${out_refund_no}","reason":"取消订单","transaction_id":"${transaction_id}"}

------------------
response content:
HTTP/1.1 401 Unauthorized
Content-Length: 125
Cache-Control: no-cache, must-revalidate
Connection: keep-alive
Content-Language: zh-CN
Content-Type: application/json; charset=utf-8
Date: Wed, 01 Mar 2023 06:31:12 GMT
Keep-Alive: timeout=8
Request-Id: 08B0E2FB9F0610880618C6B5C05520D7900128C2C305-270924346
Server: nginx
X-Content-Type-Options: nosniff

{"code":"SIGN_ERROR","message":"Http头Authorization值格式错误,请参考《微信支付商户REST API签名规则》"}

调用代码:

options := &rRequest.RequestRefund{
	TransactionID: refund.TransactionId,
	OutRefundNo:   refund.OutRefundNo,
	Reason:        reason,
	NotifyUrl:     global.Conf.Payment.RefundNotifyURL, // 异步接收微信支付退款结果通知的回调地址
	// FundsAccount: "",
	Amount: &rRequest.RefundAmount{
		Refund:   refund.Refund,                  // 退款金额,单位:分
		Total:    *refund.Total,                  // 订单总金额,单位:分
		Currency: "CNY",                          // 货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
		From:     []*rRequest.RefundAmountFrom{}, // 退款出资账户及金额。不传仍然需要这个空数组防止微信报错
	},
	GoodsDetail: nil,
}
res, err := global.Payment.Refund.Refund(options)
@FourLeafTec
Copy link
Contributor Author

看上去是把header+body又插入进了一次body,header并没放到http header里

@Matrix-X
Copy link
Contributor

Matrix-X commented Mar 1, 2023

Thx for your issue, pls check this version v3.0.11

@FourLeafTec
Copy link
Contributor Author

FourLeafTec commented Mar 1, 2023

更新3.0.11,微信响应

{"code":"PARAM_ERROR","detail":{"location":null,"value":["/body/appid","/body/mchid"]},"message":"请求中含有未在API文档中定义的参数"}

日志中body部分多了appid和mchid两个节点:

request body:{"amount":{"currency":"CNY","refund":1,"total":1},"appid":"${appid}","mchid":"${mchid}","notify_url":"${notify_url}","out_refund_no":"${out_refund_no}","reason":"取消订单","transaction_id":"${transaction_id}"}

@Matrix-X
Copy link
Contributor

Matrix-X commented Mar 1, 2023

这个有点奇怪了
居然不需要这两个字的

@Matrix-X
Copy link
Contributor

Matrix-X commented Mar 1, 2023

看来要区别对待了,大部分v3的接口,需要传这三个参数

@FourLeafTec
Copy link
Contributor Author

微信支付这块比较麻烦,每个口都不一样

小程序和jsapi这块的情况是:
JSAPI下单:两个都要
查询订单:mchid,但是都传似乎也不报错
关闭订单:mchid,但是都传似乎也不报错
调起支付:appid
申请退款:都不能传
查询退款:都不能传
账单那几个接口我还没做到

接口规则的统一情况来说,也算腾讯老传统了,内部都是不一致的

@Matrix-X
Copy link
Contributor

Matrix-X commented Mar 1, 2023

我提交了到dev分支
你能不能先用dev分支测试一下刚才那个退款的接口?

没问题的话,我打版本

@Matrix-X
Copy link
Contributor

Matrix-X commented Mar 1, 2023

强烈要求你这位专业人士,加入我们微信群 ;-)

@FourLeafTec
Copy link
Contributor Author

develop版本检出v3.0.0-beta9.0.20230301083122-e2df9327a3ed
退款成功了

目前知道这个版本下订单,接收支付通知,查询支付结果,退款,接收退款通知,查询退款结果,微信统一消息推送是没问题的
我项目还没到整体测试阶段,没有完整的自动测试用例

我也不常做微信支付这块,正好这个活用到了而已,抽空我从前面的issue里找下贵公司的微信群加一下吧

@Matrix-X
Copy link
Contributor

Matrix-X commented Mar 1, 2023

最新版本更新到:

v3.0.12


非常欢迎你的加入

image

@Matrix-X Matrix-X closed this as completed Mar 1, 2023
@Matrix-X Matrix-X added the good first issue Good for newcomers label Mar 9, 2023
@Matrix-X Matrix-X pinned this issue Mar 9, 2023
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
good first issue Good for newcomers
Projects
None yet
Development

No branches or pull requests

2 participants