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

预支付下单 response body 为空 #488

Closed
Hitmanv opened this issue Aug 16, 2016 · 4 comments
Closed

预支付下单 response body 为空 #488

Hitmanv opened this issue Aug 16, 2016 · 4 comments

Comments

@Hitmanv
Copy link

Hitmanv commented Aug 16, 2016

我用的环境

laravel 5.2
PHP 版本:
overtrue/wechat 版本:3.1

问题及现象

调用 $payment->prepare() 打断点发现请求的response里面的body为空,get body dump出来的是stream, 跟这个有关系吗
描述你的问题现象,报错贴截图粘贴或者贴具体信息,提供必要的代码段

image

@Hitmanv Hitmanv changed the title response body 为空 预支付下单 response body 为空 Aug 16, 2016
@tianyong90
Copy link
Contributor

@Hitmanv 最好贴出你的代码,支付这部分相关的参数和配置本来就多,引起错误的因素也多。光一个报错截图很难确定问题。

@Hitmanv
Copy link
Author

Hitmanv commented Aug 16, 2016

@tianyong90 嗯 谢谢 因为用的是实例的代码 依赖的代码页都看了 参数方面没什么问题 所以就没贴 主要是请求结果空没办法分析比较麻烦 我先自己请求试试

@Hitmanv Hitmanv closed this as completed Aug 16, 2016
@mytharcher
Copy link

@Hitmanv ,我也遇到这个问题了,debug 日志和你的一模一样,状态码200但是body为空,后来怎么解决的?

  • PHP 5.5.9
  • overtrue/wechat 3.1.5
        $wechat = new EasyWeChat\Foundation\Application($wechatConfig);

        $payOrder = new EasyWeChat\Payment\Order([
            'trade_type' => 'JSAPI',
            'out_trade_no' => $order['id'],
            'body' => $order['category']['name'],
            'detail' => $order['category']['name'],
            'total_fee' => $order['price'] * 100,
            'time_start' => date('YmdHis'),
            'time_expire' => date('YmdHis', time() + $this->setting['paymentTimeout']),
            'openid' => $_SESSION['oauth']['userId']
        ]);

        $result = $wechat->payment->prepare($payOrder);

        log_message('debug', json_encode($result)); // 这里出来的结果是 [false]

Debug 日志:

[2016-10-24 18:22:48] easywechat.DEBUG: Client Request: {"url":"https://api.mch.weixin.qq.com/pay/unifiedorder","method":"POST","options":{"timeout":5,"body":"<xml><trade_type><![CDATA[JSAPI]]></trade_type><out_trade_no><![CDATA[580c5f42a063d0-50489148]]></out_trade_no><body><![CDATA[商品]]></body><detail><![CDATA[商品]]></detail><total_fee>1</total_fee><time_start>20161024182248</time_start><time_expire>20161024202248</time_expire><openid><![CDATA[oSsBlwrl7094jEZH9p17L1TopgLs]]></openid><notify_url><![CDATA[http://mysite.com/order/callback_wechat/notify]]></notify_url><spbill_create_ip><![CDATA[MY_IP]]></spbill_create_ip><mch_id>MCH_ID</mch_id><nonce_str><![CDATA[580de0f8a0430]]></nonce_str><sign><![CDATA[E9A1BDDC6634E5DB0B065093188754B2]]></sign></xml>"}} []
[2016-10-24 18:22:48] easywechat.DEBUG: Request: POST https://api.mch.weixin.qq.com/pay/unifiedorder {"timeout":5,"handler":{},"synchronous":true,"allow_redirects":{"max":5,"protocols":["http","https"],"strict":false,"referer":false,"track_redirects":false},"http_errors":true,"decode_content":true,"verify":true,"cookies":false} [] []
[2016-10-24 18:22:48] easywechat.DEBUG: Request headers:{"Content-Length":["633"],"User-Agent":["GuzzleHttp\/6.2.1 curl\/7.35.0 PHP\/5.5.9-1ubuntu4.7"],"Host":["api.mch.weixin.qq.com"]} [] []
[2016-10-24 18:22:48] easywechat.DEBUG: API response: {"Status":200,"Reason":"OK","Headers":{"Server":["nginx"],"Date":["Mon, 24 Oct 2016 10:22:48 GMT"],"Content-Type":["text/html; charset=gbk"],"Content-Length":["0"],"Connection":["keep-alive"],"Keep-Alive":["timeout=8"],"Cache-Control":["no-cache, must-revalidate"]},"Body":""} []

@mytharcher
Copy link

问题解决了,发送的请求里少了app_id,是之前配置里的变量写错了。但是微信服务器返回 200 和空的 body 也导致很难定位。所以建议发送请求前加上一些接口必填项的校验。

另外还有个问题,当我单独写一个文件测试 SDK 时,发现由于请求超时设置回影响返回结果。具体在 vendor/overtrue/wechat/src/Payment/API.php 文件里 request 函数的 $options 变量,如果加入 timeout => 15(15 秒)的设置,基本都能收到正常的结果,但设置小于 5 的值,大多数情况都是超时收不到结果,默认设置 5 有 70% 左右的概率会收不到。建议调整这个参数的值以降低无法收到正常请求结果的概率。

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

3 participants