-
Notifications
You must be signed in to change notification settings - Fork 101
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
Fix transformRequest for GET requests #146
Merged
TheNorthMemory
merged 6 commits into
wechatpay-apiv3:main
from
saber-x:fix-transform-request
Jan 26, 2025
Merged
Fix transformRequest for GET requests #146
TheNorthMemory
merged 6 commits into
wechatpay-apiv3:main
from
saber-x:fix-transform-request
Jan 26, 2025
Conversation
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
saber-x
force-pushed
the
fix-transform-request
branch
from
January 25, 2025 10:44
8393eb4
to
072ba66
Compare
PHP7.1下校验未通过:
|
@TheNorthMemory 已修改重新提交。 |
TheNorthMemory
approved these changes
Jan 26, 2025
Eric-Lee-Handyman
approved these changes
Jan 26, 2025
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM
* Fix transformRequest for GET requests * Refactored to use if statement for parsing queryParams * optimize request parameter parsing and handling * sample tests on `v2/papay/h5entrustweb` request
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
问题描述
在使用微信支付APIv2的PHP库时,发现H5纯签约接口(
/v2/papay/h5entrustweb
)在进行GET请求时,代码错误地将请求参数转换为XML格式,导致请求失败。具体错误信息为:PHP Fatal error: Uncaught WeChatPay\Exception\InvalidArgumentException: The xml's structure[mch_id()] doesn't matched the init one mchid(**********).
根据微信支付APIv2的文档,H5纯签约接口的GET请求仅需要通过queryString传递参数,而当前代码在处理GET请求时,错误地将参数转换为XML格式,这与API的要求不符。
修复方案
transformRequest
方法进行了修复。修复后的代码逻辑如下:区分GET请求与非GET请求:
对于GET请求,直接返回请求,不进行XML转换。
对于非GET请求,保留原有的XML转换和签名逻辑。
使用GuzzleHttp\Psr7\Query::parse解析GET请求的查询字符串,确保参数正确传递。
对于非GET请求,继续按照原有逻辑生成XML格式的请求体。