bingyu-duanxinwangzhan/message-code/message-admin/application/common/WeChatPay/index.php

80 lines
2.8 KiB
PHP
Executable File
Raw Blame History

This file contains ambiguous Unicode characters!

This file contains ambiguous Unicode characters that may be confused with others in your current locale. If your use case is intentional and legitimate, you can safely ignore this warning. Use the Escape button to highlight these characters.

<?php
/**
* Created by PhpStorm.
* User: lock
* Date: 2021/7/23
* Time: 9:58 AM
*/
use WeChatPay\Builder;
use WeChatPay\Util\MediaUtil;
require_once 'src/Util/PemUtil.php';
ini_set("display_errors","On");
error_reporting(E_ALL);
// 商户号,假定为`1000100`
$merchantId = '1609669563';
// 商户私钥,文件路径假定为 `/path/to/merchant/apiclient_key.pem`
$merchantPrivateKeyFilePath = '/var/www/ysfzmmp1/ThinkPHP/Extend/Vendor/Wechat3/cert/apiclient_key.pem';
// 加载商户私钥
//$merchantPrivateKeyInstance = PemUtil::loadPrivateKey($merchantPrivateKeyFilePath);
$pemutil_model = new PemUtil();
$merchantPrivateKeyInstance = $pemutil_model::loadPrivateKey($merchantPrivateKeyFilePath);
echo 222;
exit();
$merchantCertificateSerial = '4929BF5BD31D96D752EA8BAE6F3B62B2C5114A2E';// API证书不重置商户证书序列号就是个常量
// // 或者从以下代码也可以直接加载
// // 商户证书,文件路径假定为 `/path/to/merchant/apiclient_cert.pem`
// $merchantCertificateFilePath = '/path/to/merchant/apiclient_cert.pem';
// // 加载商户证书
// $merchantCertificateInstance = PemUtil::loadCertificate($merchantCertificateFilePath);
// // 解析商户证书序列号
// $merchantCertificateSerial = PemUtil::parseCertificateSerialNo($merchantCertificateInstance);
// 平台证书,可由下载器 `./bin/CertificateDownloader.php` 生成并假定保存为 `/path/to/wechatpay/cert.pem`
$platformCertificateFilePath = '/var/www/ysfzmmp1/ThinkPHP/Extend/Vendor/Wechat3/cert/wxpay_cert.pem';
// 加载平台证书
$platformCertificateInstance = PemUtil::loadCertificate($platformCertificateFilePath);
// 解析平台证书序列号
$platformCertificateSerial = PemUtil::parseCertificateSerialNo($platformCertificateInstance);
echo "ok";
exit();
// 工厂方法构造一个实例
$instance = Builder::factory([
'mchid' => $merchantId,
'serial' => $merchantCertificateSerial,
'privateKey' => $merchantPrivateKeyInstance,
'certs' => [
$platformCertificateSerial => $platformCertificateInstance,
],
]);
$media = new MediaUtil('/your/file/path/image.jpg');
$resp = $instance->v3->marketing->favor->media->imageUpload
->postAsync([
'body' => $media->getStream(),
'headers' => [
'content-type' => $media->getContentType(),
]
])
->then(static function($response) {
echo $response->getBody()->getContents(), PHP_EOL;
return $response;
})
->otherwise(static function($exception) {
if ($exception instanceof \Psr\Http\Message\ResponseInterface) {
$body = $exception->getResponse()->getBody();
echo $body->getContents(), PHP_EOL, PHP_EOL, PHP_EOL;
}
echo $exception->getTraceAsString(), PHP_EOL;
})
->wait();