新增微信支付类

This commit is contained in:
2023-03-02 18:24:40 +08:00
parent 186f92c4ea
commit bdcbd26a8d
6 changed files with 60 additions and 13 deletions
+3 -2
View File
@@ -53,7 +53,7 @@ class Wechat
* @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface
*/
public function createApp(string $appId, string $appSecret)
public function createApp(string $appId, string $appSecret): void
{
$config = array(
"app_id" => $appId,
@@ -229,7 +229,8 @@ class Wechat
* @throws TransportExceptionInterface
* @throws ServerExceptionInterface
*/
public function getUnlimitedQRCode(array $options){
public function getUnlimitedQRCode(array $options): array|string
{
try {
$this->createApp($this->config['app_id'], $this->config['secret']);
+45
View File
@@ -0,0 +1,45 @@
<?php
namespace Extend\Wechat;
/**
* 微信支付类
*/
class WechatPay
{
protected $app;
// 创建工厂类
public function createApp(){
$config = [
'mch_id' => config("we_chat.pay.mch_id"),
// 商户证书
'private_key' => __DIR__ . '/certs/1636644248/apiclient_key.pem',
'certificate' => __DIR__ . '/certs/1636644248/apiclient_cert.pem',
// v3 API 秘钥
'secret_key' => config("we_chat.pay.v3_api_secret"),
// v2 API 秘钥
'v2_secret_key' => '',
// 平台证书:微信支付 APIv3 平台证书,需要使用工具下载
// 下载工具:https://github.com/wechatpay-apiv3/CertificateDownloader
'platform_certs' => [
// 请使用绝对路径
__DIR__ . '/certs/wechatpay_112FCCD1B9ECC8292703AB7363C73D74B6AFDC1A.pem',
],
/**
* 接口请求相关配置,超时时间等,具体可用参数请参考:
* https://github.com/symfony/symfony/blob/5.3/src/Symfony/Contracts/HttpClient/HttpClientInterface.php
*/
'http' => [
'throw' => false, // 状态码非 200、300 时是否抛出异常,默认为开启
'timeout' => 5.0,
// 'base_uri' => 'https://api.mch.weixin.qq.com/', // 如果你在国外想要覆盖默认的 url 的时候才使用,根据不同的模块配置不同的 uri
],
];
}
}