新增微信支付类

This commit is contained in:
wucongxing 2023-03-02 18:24:40 +08:00
parent 186f92c4ea
commit bdcbd26a8d
6 changed files with 60 additions and 13 deletions

2
.gitignore vendored
View File

@ -11,3 +11,5 @@ vendor/
.DS_Store .DS_Store
.phpunit* .phpunit*
*.cache *.cache
*.pem
*.p12

View File

@ -48,6 +48,7 @@ WORKDIR /opt/www
# RUN composer install --no-dev --no-scripts # RUN composer install --no-dev --no-scripts
COPY . /opt/www 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 RUN composer install --no-dev -o && php bin/hyperf.php
EXPOSE 9501 EXPOSE 9501

12
composer.lock generated
View File

@ -6467,16 +6467,16 @@
}, },
{ {
"name": "w7corp/easywechat", "name": "w7corp/easywechat",
"version": "6.10.0", "version": "6.11.1",
"source": { "source": {
"type": "git", "type": "git",
"url": "https://github.com/w7corp/easywechat.git", "url": "https://github.com/w7corp/easywechat.git",
"reference": "558a58fd37e961027a5f81164feddc13b60362a3" "reference": "a0eead024a96c2158884cf36761941e95a7b1073"
}, },
"dist": { "dist": {
"type": "zip", "type": "zip",
"url": "https://mirrors.huaweicloud.com/repository/php/w7corp/easywechat/6.10.0/w7corp-easywechat-6.10.0.zip", "url": "https://mirrors.huaweicloud.com/repository/php/w7corp/easywechat/6.11.1/w7corp-easywechat-6.11.1.zip",
"reference": "558a58fd37e961027a5f81164feddc13b60362a3", "reference": "a0eead024a96c2158884cf36761941e95a7b1073",
"shasum": "" "shasum": ""
}, },
"require": { "require": {
@ -6486,7 +6486,7 @@
"ext-openssl": "*", "ext-openssl": "*",
"ext-simplexml": "*", "ext-simplexml": "*",
"ext-sodium": "*", "ext-sodium": "*",
"monolog/monolog": "^2.2", "monolog/monolog": "^2.2|^3.0",
"nyholm/psr7": "^1.5", "nyholm/psr7": "^1.5",
"nyholm/psr7-server": "^1.0", "nyholm/psr7-server": "^1.0",
"overtrue/socialite": "^3.5.4|^4.0.1", "overtrue/socialite": "^3.5.4|^4.0.1",
@ -6558,7 +6558,7 @@
"type": "github" "type": "github"
} }
], ],
"time": "2022-11-28T14:35:59+00:00" "time": "2023-02-17T10:13:40+00:00"
} }
], ],
"packages-dev": [ "packages-dev": [

View File

@ -44,11 +44,9 @@ return [
] ]
], ],
"pay" => [ "pay" => [
"patient" => [ "mch_id" => env('PATIENT_WECHAT_MCH_ID', '1636644248'),
"app_id" => env('PATIENT_WECHAT_APP_ID', 'wx70a196902e0841b6'), "app_id" => env('PATIENT_WECHAT_APP_ID', 'wx70a196902e0841b6'),
"mchid" => env('PATIENT_WECHAT_MCH_ID', '1636644248'), "v3_api_secret" => env('PATIENT_WECHAT_APIv3_SECRET', 'gdxz292sjSOadN3m2pCda03NfCsmNadY'),
"apiv3_secret" => env('PATIENT_WECHAT_APIv3_SECRET', 'gdxz292sjSOadN3m2pCda03NfCsmNadY'),
],
] ]
], ],
"alibaba" => [// 阿里 "alibaba" => [// 阿里

View File

@ -53,7 +53,7 @@ class Wechat
* @throws ContainerExceptionInterface * @throws ContainerExceptionInterface
* @throws NotFoundExceptionInterface * @throws NotFoundExceptionInterface
*/ */
public function createApp(string $appId, string $appSecret) public function createApp(string $appId, string $appSecret): void
{ {
$config = array( $config = array(
"app_id" => $appId, "app_id" => $appId,
@ -229,7 +229,8 @@ class Wechat
* @throws TransportExceptionInterface * @throws TransportExceptionInterface
* @throws ServerExceptionInterface * @throws ServerExceptionInterface
*/ */
public function getUnlimitedQRCode(array $options){ public function getUnlimitedQRCode(array $options): array|string
{
try { try {
$this->createApp($this->config['app_id'], $this->config['secret']); $this->createApp($this->config['app_id'], $this->config['secret']);

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
],
];
}
}