From bdcbd26a8db09004d00bea67a5e27113775e53cb Mon Sep 17 00:00:00 2001 From: wucongxing <815046773@qq.com> Date: Thu, 2 Mar 2023 18:24:40 +0800 Subject: [PATCH] =?UTF-8?q?=E6=96=B0=E5=A2=9E=E5=BE=AE=E4=BF=A1=E6=94=AF?= =?UTF-8?q?=E4=BB=98=E7=B1=BB?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .gitignore | 2 ++ Dockerfile | 1 + composer.lock | 12 +++++----- config/config.php | 8 +++---- extend/Wechat/Wechat.php | 5 +++-- extend/Wechat/WechatPay.php | 45 +++++++++++++++++++++++++++++++++++++ 6 files changed, 60 insertions(+), 13 deletions(-) create mode 100644 extend/Wechat/WechatPay.php diff --git a/.gitignore b/.gitignore index 70b4f13..5ec1ebc 100644 --- a/.gitignore +++ b/.gitignore @@ -11,3 +11,5 @@ vendor/ .DS_Store .phpunit* *.cache +*.pem +*.p12 \ No newline at end of file diff --git a/Dockerfile b/Dockerfile index 53c5cb4..73c1ae2 100644 --- a/Dockerfile +++ b/Dockerfile @@ -48,6 +48,7 @@ WORKDIR /opt/www # RUN composer install --no-dev --no-scripts COPY . /opt/www +COPY /data/www/cret/wechat/pay/1636644248 /opt/www/extend/Wechat/certs RUN composer install --no-dev -o && php bin/hyperf.php EXPOSE 9501 diff --git a/composer.lock b/composer.lock index 38832a4..218b20e 100644 --- a/composer.lock +++ b/composer.lock @@ -6467,16 +6467,16 @@ }, { "name": "w7corp/easywechat", - "version": "6.10.0", + "version": "6.11.1", "source": { "type": "git", "url": "https://github.com/w7corp/easywechat.git", - "reference": "558a58fd37e961027a5f81164feddc13b60362a3" + "reference": "a0eead024a96c2158884cf36761941e95a7b1073" }, "dist": { "type": "zip", - "url": "https://mirrors.huaweicloud.com/repository/php/w7corp/easywechat/6.10.0/w7corp-easywechat-6.10.0.zip", - "reference": "558a58fd37e961027a5f81164feddc13b60362a3", + "url": "https://mirrors.huaweicloud.com/repository/php/w7corp/easywechat/6.11.1/w7corp-easywechat-6.11.1.zip", + "reference": "a0eead024a96c2158884cf36761941e95a7b1073", "shasum": "" }, "require": { @@ -6486,7 +6486,7 @@ "ext-openssl": "*", "ext-simplexml": "*", "ext-sodium": "*", - "monolog/monolog": "^2.2", + "monolog/monolog": "^2.2|^3.0", "nyholm/psr7": "^1.5", "nyholm/psr7-server": "^1.0", "overtrue/socialite": "^3.5.4|^4.0.1", @@ -6558,7 +6558,7 @@ "type": "github" } ], - "time": "2022-11-28T14:35:59+00:00" + "time": "2023-02-17T10:13:40+00:00" } ], "packages-dev": [ diff --git a/config/config.php b/config/config.php index 8dafa19..de96028 100644 --- a/config/config.php +++ b/config/config.php @@ -44,11 +44,9 @@ return [ ] ], "pay" => [ - "patient" => [ - "app_id" => env('PATIENT_WECHAT_APP_ID', 'wx70a196902e0841b6'), - "mchid" => env('PATIENT_WECHAT_MCH_ID', '1636644248'), - "apiv3_secret" => env('PATIENT_WECHAT_APIv3_SECRET', 'gdxz292sjSOadN3m2pCda03NfCsmNadY'), - ], + "mch_id" => env('PATIENT_WECHAT_MCH_ID', '1636644248'), + "app_id" => env('PATIENT_WECHAT_APP_ID', 'wx70a196902e0841b6'), + "v3_api_secret" => env('PATIENT_WECHAT_APIv3_SECRET', 'gdxz292sjSOadN3m2pCda03NfCsmNadY'), ] ], "alibaba" => [// 阿里 diff --git a/extend/Wechat/Wechat.php b/extend/Wechat/Wechat.php index 8921e46..0c72e89 100644 --- a/extend/Wechat/Wechat.php +++ b/extend/Wechat/Wechat.php @@ -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']); diff --git a/extend/Wechat/WechatPay.php b/extend/Wechat/WechatPay.php new file mode 100644 index 0000000..e7813cb --- /dev/null +++ b/extend/Wechat/WechatPay.php @@ -0,0 +1,45 @@ + 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 + ], + ]; + } +} \ No newline at end of file