如果你用的 php,并且是 laravel 框架,可以尝试一下下边的代码: public function test_receipt_query() { $res = $this->getApi()->receiptQuery('xxx4d0fb9fd745de8d1dff937755x xx', 'xxxf925a72b740e5ba943e7f40efdxxx'); if ($res->isSuccess()) { // 商户号 $merchantId = 'xxx27xxxxx'; // 商户序列号 $serialNo = 'xxxxxBA3B465F51D1F5B4CF825580F1409xxxxxx'; $nonceStr = unsigned_uuid(); $time = time(); // 下载地址拆分,取路径和参数去签名 $url_parts = parse_url($res->getDownloadUrl()); $canonical_url = ($url_parts['path'] . (!empty($url_parts['query']) ? "?${url_parts['query']}" : "")); $sign = $this->sign($canonical_url, $nonceStr, $time); $res = Http::withHeaders([ 'Authorization' => 'WECHATPAY2-SHA256-RSA2048 mchid="' . $merchantId . '",serial_no="' . $serialNo . '",nonce_str="' . $nonceStr . '",timestamp="' . $time . '",signature="' . $sign . '"' ])->get($res->getDownloadUrl()); if (!is_dir(storage_path('app/public/test'))) { Storage::makeDirectory('public/test'); } file_put_contents(storage_path('app/public/test/' . $time . '.pdf'), $res->body()); } } public function sign($url, $nonceStr, $time) { $str = "GET" . "\n" . $url . "\n" . $time . "\n" . $nonceStr . "\n"; if (!openssl_sign($str, $signature, $this->merchantPrivateKeyInstance, OPENSSL_ALGO_SHA256)) { throw new \Exception('Signing the input $message failed, please checking your $privateKey whether or nor correct.'); } } 写的时候折腾了半天,不想吐槽了,👋
下载电子回单接口调用问题[以解决]最近对接这个批量转账到零钱的文档,其他的接口都对接好了卡在了这个 下载电子回单接口 问题描述: 我对接的这些接口都是通过一样的签名方式,但是就是这个接口一直返回 "code":"INVALID REQUEST","message":"错误的签名,导致验签失败" 我仔细看了这个接口的签名方式是正确的 文档描述这个接口的GET请求的URL是通过 查询转账电子回单 查询过来的down_url后面有带token参数 我签名的时候也是把这个参数都加上了的 就是过不了签名 请问有人之前碰到过一样的问题吗!!!
2022-03-24