feat: good
This commit is contained in:
50
.env.example
50
.env.example
@@ -1,17 +1,47 @@
|
||||
APP_NAME=skeleton
|
||||
# [app] -- 集群配置需一致
|
||||
APP_NAME=hhl_meal
|
||||
APP_ENV=dev
|
||||
API_RETURN_KEY=
|
||||
JWT_KEY=
|
||||
JWT_EXPIRE=
|
||||
ADMIN_JWT_EXPIRE=
|
||||
|
||||
# [crontab] -- 集群配置 仅需一台true即可 其他都是false 根据 restart_pre.sh 自动生成
|
||||
CRONTAB_ENABLE=
|
||||
|
||||
# [mysql] -- 集群配置需一致
|
||||
DB_DRIVER=mysql
|
||||
DB_HOST=localhost
|
||||
DB_PORT=3306
|
||||
DB_DATABASE=hyperf
|
||||
DB_USERNAME=root
|
||||
DB_HOST=
|
||||
DB_PORT=
|
||||
DB_DATABASE=
|
||||
DB_USERNAME=
|
||||
DB_PASSWORD=
|
||||
DB_CHARSET=utf8mb4
|
||||
DB_COLLATION=utf8mb4_unicode_ci
|
||||
DB_PREFIX=
|
||||
DB_PREFIX=app_
|
||||
|
||||
REDIS_HOST=localhost
|
||||
REDIS_AUTH=(null)
|
||||
REDIS_PORT=6379
|
||||
REDIS_DB=0
|
||||
# [redis] -- 集群配置需一致
|
||||
REDIS_HOST=
|
||||
REDIS_AUTH=
|
||||
REDIS_PORT=
|
||||
REDIS_DB=
|
||||
SYSTEM_REDIS_DB=
|
||||
LOCK_REDIS_DB=
|
||||
|
||||
# [rabbitmq] -- 集群配置需一致
|
||||
AMQP_HOST=
|
||||
AMQP_PORT=
|
||||
AMQP_USER=
|
||||
AMQP_PASSWORD=
|
||||
AMQP_VHOST=/
|
||||
|
||||
# [ali] -- 集群配置需一致
|
||||
ALI_ACCESS_KEY_ID=
|
||||
ALI_ACCESS_KEY_SECRET=
|
||||
ALI_BUCKET=
|
||||
ALI_REGION=
|
||||
ALI_CALLBACK_URL=
|
||||
ALI_OSS_URL=
|
||||
ALI_STS_ENDPOINT=
|
||||
ALI_ROLE_ARN=
|
||||
ALI_OSS_ENDPOINT=
|
||||
154
app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php
Normal file
154
app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php
Normal file
@@ -0,0 +1,154 @@
|
||||
<?php
|
||||
|
||||
namespace App\Service\Common\Pay\Wx;
|
||||
|
||||
use App\Exception\ErrException;
|
||||
use App\Lib\Log;
|
||||
use App\Service\Common\Pay\ThirdPayInterface;
|
||||
use Exception;
|
||||
use Hyperf\Di\Annotation\Inject;
|
||||
use Hyperf\HttpServer\Contract\RequestInterface;
|
||||
use Psr\Container\ContainerExceptionInterface;
|
||||
use Psr\Container\NotFoundExceptionInterface;
|
||||
use Psr\Http\Message\ResponseInterface;
|
||||
use Yansongda\Artful\Rocket;
|
||||
use Yansongda\HyperfPay\Pay;
|
||||
use Yansongda\Supports\Collection;
|
||||
use function Hyperf\Config\config;
|
||||
|
||||
abstract class WxJsRechargeBaseService implements ThirdPayInterface
|
||||
{
|
||||
/**
|
||||
* 回调地址
|
||||
* @var string
|
||||
*/
|
||||
protected string $notifyUrl = '';
|
||||
|
||||
/**
|
||||
* @var Pay $ysdPay
|
||||
*/
|
||||
#[Inject]
|
||||
protected Pay $ysdPay;
|
||||
|
||||
/**
|
||||
* @var Log
|
||||
*/
|
||||
#[Inject]
|
||||
protected Log $log;
|
||||
|
||||
/**
|
||||
* 注入
|
||||
* @var RequestInterface
|
||||
*/
|
||||
#[Inject]
|
||||
protected RequestInterface $request;
|
||||
|
||||
/**
|
||||
* 配置项
|
||||
* @var array
|
||||
*/
|
||||
protected array $config = [];
|
||||
|
||||
/**
|
||||
* 返回数据
|
||||
* @var array
|
||||
*/
|
||||
protected array $callbackData = [];
|
||||
|
||||
/**
|
||||
* 充值回调
|
||||
*/
|
||||
abstract public function callBackHandle();
|
||||
|
||||
/**
|
||||
* 设置回调地址
|
||||
*/
|
||||
abstract public function setNotify();
|
||||
|
||||
// /**
|
||||
// * 设置商户号id
|
||||
// */
|
||||
// abstract public function setMchId();
|
||||
|
||||
|
||||
// /**
|
||||
// * 获取返回数据
|
||||
// * @return void
|
||||
// * @throws ContainerExceptionInterface
|
||||
// * @throws NotFoundExceptionInterface
|
||||
// * @throws ContainerException
|
||||
// * @throws InvalidParamsException
|
||||
// */
|
||||
// public function getWechatData(): void
|
||||
// {
|
||||
// $params = $this->request->all();
|
||||
// $this->log->callbackLog(__CLASS__.'微信支付回调'.json_encode($params));
|
||||
//
|
||||
// $this->setConfig();
|
||||
// $result = $this->pay->wechat($this->config)->callback($params);
|
||||
// $this->callbackData = $result['resource']['ciphertext'];
|
||||
//
|
||||
// if (empty($this->callbackData)) {
|
||||
// $this->log->error(__CLASS__.'获取回调失败'.json_encode($params));
|
||||
// throw new ErrException('获取回调失败');
|
||||
// }
|
||||
//
|
||||
// $this->log->info(__CLASS__.'微信支付完成回调'.json_encode($this->callbackData));
|
||||
// }
|
||||
|
||||
|
||||
/**
|
||||
* 确认回调
|
||||
* @return ResponseInterface
|
||||
*/
|
||||
protected function returnSuccess(): ResponseInterface
|
||||
{
|
||||
$this->setConfig();
|
||||
return $this->ysdPay->wechat($this->config)->success();
|
||||
}
|
||||
|
||||
/**
|
||||
* @return void
|
||||
*/
|
||||
private function setConfig(): void
|
||||
{
|
||||
$this->config = config('ysdPay');
|
||||
}
|
||||
|
||||
/**
|
||||
* @param float $money
|
||||
* @param int $orderId
|
||||
* @param int $orderType
|
||||
* @param string $outTradeNo
|
||||
* @param int $userId
|
||||
* @return Collection|Rocket
|
||||
* @throws ContainerExceptionInterface
|
||||
* @throws NotFoundExceptionInterface
|
||||
*/
|
||||
public function pay(float $money, int $orderId, int $orderType, string $outTradeNo, int $userId): Collection|Rocket
|
||||
{
|
||||
if (empty($this->config)) throw new ErrException('调起支付失败-微信支付配置项不存在');
|
||||
$userOpenId = '123';
|
||||
try {
|
||||
$wxOrder = [
|
||||
'out_trade_no' => $outTradeNo,
|
||||
'description' => '测试订单',
|
||||
'amount' => [
|
||||
'total' => (int)bcmul((string)$money, "100"),
|
||||
'currency' => 'CNY'
|
||||
],
|
||||
'payer' => [
|
||||
'openid' => $userOpenId,
|
||||
]
|
||||
];
|
||||
|
||||
$result = $this->ysdPay->wechat($this->config)->mini($wxOrder);
|
||||
|
||||
$this->log->callbackLog(__CLASS__.'微信支付调起数据|回调地址:'. json_encode($this->config['wechat']['default']).'|回调数据:'.json_encode($result).'|请求数据:'.json_encode($wxOrder));
|
||||
return $result;
|
||||
} catch (Exception $e) {
|
||||
$this->log->error(__CLASS__.'微信支付调起失败。reason:'.$e->getMessage());
|
||||
throw new ErrException($e->getMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -35,7 +35,8 @@
|
||||
"hyperf/process": "~3.1.0",
|
||||
"hyperf/redis": "~3.1.0",
|
||||
"hyperf/validation": "^3.1",
|
||||
"yansongda/hyperf-pay": "^1.7"
|
||||
"yansongda/hyperf-pay": "^1.7",
|
||||
"yansongda/pay": "~3.7.0"
|
||||
},
|
||||
"require-dev": {
|
||||
"friendsofphp/php-cs-fixer": "^3.0",
|
||||
|
||||
79
config/autoload/ysdPay.php
Normal file
79
config/autoload/ysdPay.php
Normal file
@@ -0,0 +1,79 @@
|
||||
<?php
|
||||
|
||||
use function Hyperf\Support\env;
|
||||
use Yansongda\Pay\Pay;
|
||||
|
||||
return [
|
||||
'wechat' => [
|
||||
'default' => [
|
||||
// 必填-商户号,服务商模式下为服务商商户号
|
||||
'mch_id' => env('WX_PAYMENT_MCH_ID'),
|
||||
// 必填-商户秘钥
|
||||
'mch_secret_key' => env('WX_PAYMENT_MCH_SECRET_KEY'),
|
||||
// 必填-商户私钥 字符串或路径
|
||||
'mch_secret_cert' => env('WX_PAYMENT_MCH_SECRET_CERT'),
|
||||
// 必填-商户公钥证书路径
|
||||
'mch_public_cert_path' => env('WX_PAYMENT_MCH_PUBLIC_CERT_PATH'),
|
||||
// 必填
|
||||
'notify_url' => env('WX_PAYMENT_NOTIFY_URL'),
|
||||
// 选填-公众号 的 app_id
|
||||
'mp_app_id' => '',
|
||||
// 选填-小程序 的 app_id
|
||||
'mini_app_id' => '',
|
||||
// 选填-app 的 app_id
|
||||
'app_id' => env('WX_PAYMENT_APP_ID'),
|
||||
// 选填-合单 app_id
|
||||
'combine_app_id' => '',
|
||||
// 选填-合单商户号
|
||||
'combine_mch_id' => '',
|
||||
// 选填-服务商模式下,子公众号 的 app_id
|
||||
'sub_mp_app_id' => '',
|
||||
// 选填-服务商模式下,子 app 的 app_id
|
||||
'sub_app_id' => '',
|
||||
// 选填-服务商模式下,子小程序 的 app_id
|
||||
'sub_mini_app_id' => '',
|
||||
// 选填-服务商模式下,子商户id
|
||||
'sub_mch_id' => '',
|
||||
// 选填-微信公钥证书路径, optional,强烈建议 php-fpm 模式下配置此参数
|
||||
'wechat_public_cert_path' => [
|
||||
// '45F59D4DABF31918AFCEC556D5D2C6E376675D57' => __DIR__ . '/Cert/wechatPublicKey.crt',
|
||||
],
|
||||
// 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SERVICE
|
||||
'mode' => Pay::MODE_NORMAL
|
||||
]
|
||||
],
|
||||
'alipay' => [
|
||||
'default' => [
|
||||
// 必填-支付宝分配的 app_id
|
||||
'app_id' => env('ALIPAY_PAYMENT_APP_ID'),
|
||||
// 必填-应用私钥 字符串或路径
|
||||
'app_secret_cert' => env('ALIPAY_PAYMENT_APP_SECRET_CERT'),
|
||||
// 必填-应用公钥证书 路径
|
||||
'app_public_cert_path' => env('ALIPAY_PAYMENT_APP_PUBLIC_CERT_PATH'),
|
||||
// 必填-支付宝公钥证书 路径
|
||||
'alipay_public_cert_path' => env('ALIPAY_PAYMENT_ALIPAY_PUBLIC_CERT_PATH'),
|
||||
// 必填-支付宝根证书 路径
|
||||
'alipay_root_cert_path' => env('ALIPAY_PAYMENT_ALIPAY_ROOT_CERT_PATH'),
|
||||
// 支付回调同步通知
|
||||
'return_url' => env('ALIPAY_PAYMENT_RETURN_URL'),
|
||||
// 支付回调异步通知
|
||||
'notify_url' => env('ALIPAY_PAYMENT_NOTIFY_URL'),
|
||||
// 选填-服务商模式下的服务商 id,当 mode 为 Pay::MODE_SERVICE 时使用该参数
|
||||
'service_provider_id' => '',
|
||||
// 选填-默认为正常模式。可选为: MODE_NORMAL, MODE_SANDBOX, MODE_SERVICE
|
||||
'mode' => Pay::MODE_NORMAL
|
||||
]
|
||||
],
|
||||
'logger' => [ // optional
|
||||
'enable' => true,
|
||||
'file' => BASE_PATH . '/runtime/payment/ysd_pay.log',
|
||||
'level' => 'debug', // 建议生产环境等级调整为 info,开发环境为 debug
|
||||
'type' => 'single', // optional, 可选 daily.
|
||||
'max_file' => 30 // optional, 当 type 为 daily 时有效,默认 30 天
|
||||
],
|
||||
'http' => [ // optional
|
||||
'timeout' => 5.0,
|
||||
'connect_timeout' => 5.0
|
||||
// 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
|
||||
]
|
||||
];
|
||||
Reference in New Issue
Block a user