diff --git a/.env.example b/.env.example index 6879583..1015720 100644 --- a/.env.example +++ b/.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 \ No newline at end of file +# [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= \ No newline at end of file diff --git a/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php b/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php new file mode 100644 index 0000000..38c1d87 --- /dev/null +++ b/app/Service/Common/Pay/Wx/WxJsRechargeBaseService.php @@ -0,0 +1,154 @@ +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()); + } + } +} \ No newline at end of file diff --git a/composer.json b/composer.json index 80eedda..5a44e66 100644 --- a/composer.json +++ b/composer.json @@ -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", diff --git a/config/autoload/ysdPay.php b/config/autoload/ysdPay.php new file mode 100644 index 0000000..81df5ce --- /dev/null +++ b/config/autoload/ysdPay.php @@ -0,0 +1,79 @@ + [ + '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) + ] +]; \ No newline at end of file