文档路径:https://pay.weixin.qq.com/wiki/doc/apiv3_partner/Offline/apis/chapter4_8_14.shtml
代码
不管对错,都会有错误提示:Fatal error: in /www/wwwroot/nk/framework/library/WeChatPay02/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113
参数错的时候,会有这样的提示
全部参数都对的话也会提示:Fatal error: in /www/wwwroot/nk/framework/library/WeChatPay02/vendor/guzzlehttp/guzzle/src/Exception/RequestException.php on line 113
只调用图片上传接口的话,不会报错
这一行说明你用的 $sm3->signFile 签名的摘要不对;另程序异常捕获写法参考如下:
try { $res = $instance->chain('')->post([]); } catch ($e) { var_dump((string)$e->getResponse()->getBody()); }
Sm3杂凑单文件实现参考这里: https://github.com/TheNorthMemory/wechatpay-php/blob/v1.5/src/Crypto/Sm3.php
使用上类似这里的注视示例: https://github.com/TheNorthMemory/wechatpay-openapi/blob/master/src/V3/NewTaxControlFapiao/FapiaoApplications/UploadFapiaoFile.php#L13-L36
// available since wechatpay/wechatpay:>=1.5.0 $digest = \WeChatPay\Crypto\Sm3::file('file:///path/to/fapiao.pdf'); $media = new \WeChatPay\Util\MediaUtil('file:///path/to/fapiao.pdf'); $json = [ 'sub_mchid' => 'your_sub_mchid', //服务商模式下必传 'file_type' => 'PDF', 'digest_algorithm' => 'SM3', 'digest' => $digest, ]; $media->setMeta(\json_encode($json)); $options = [ 'body' => $media->getStream(), 'headers' => ['Content-type' => $media->getContentType()] ];