Skip to content

Commit

Permalink
使用 Ngrok
Browse files Browse the repository at this point in the history
summerblue committed May 15, 2021
1 parent 6192b8e commit c36922b
Showing 5 changed files with 19 additions and 4 deletions.
3 changes: 3 additions & 0 deletions .env.example
Original file line number Diff line number Diff line change
@@ -57,3 +57,6 @@ ALIPAY_PRIVATE_KEY=
WECHAT_PAY_APP_ID=
WECHAT_PAY_MCH_ID=
WECHAT_PAY_KEY=

# 内网穿刺,用于支付回调
NGROK_URL=http://{分配给你的域名}.ngrok.io
3 changes: 1 addition & 2 deletions app/Admin/Controllers/OrdersController.php
Original file line number Diff line number Diff line change
@@ -131,8 +131,7 @@ protected function _refundOrder(Order $order)
'refund_fee' => $order->total_amount * 100, // 要退款的订单金额,单位分
'out_refund_no' => $refundNo, // 退款订单号
// 微信支付的退款结果并不是实时返回的,而是通过退款回调来通知,因此这里需要配上退款回调接口地址
// 'notify_url' => 'http://requestbin.fullcontact.com/******' // 由于是开发环境,需要配成 requestbin 地址
'notify_url' => route('payment.wechat.refund_notify'),
'notify_url' => ngrok_url('payment.alipay.notify'),
]);
// 将订单状态改成退款中
$order->update([
4 changes: 2 additions & 2 deletions app/Providers/AppServiceProvider.php
Original file line number Diff line number Diff line change
@@ -19,7 +19,7 @@ public function register()
$this->app->singleton('alipay', function () {

$config = config('pay.alipay');
$config['notify_url'] = route('payment.alipay.notify');
$config['notify_url'] = ngrok_url('payment.alipay.notify');
$config['return_url'] = route('payment.alipay.return');

// 判断当前项目运行环境是否为线上环境
@@ -36,7 +36,7 @@ public function register()
$this->app->singleton('wechat_pay', function () {

$config = config('pay.wechat');
$config['notify_url'] = route('payment.wechat.notify');
$config['notify_url'] = ngrok_url('payment.wechat.notify');

if (app()->environment() !== 'production') {
$config['log']['level'] = Logger::DEBUG;
11 changes: 11 additions & 0 deletions app/helpers.php
Original file line number Diff line number Diff line change
@@ -8,3 +8,14 @@ function route_class()
{
return str_replace('.', '-', Route::currentRouteName());
}

function ngrok_url($routeName, $parameters = [])
{
// 开发环境,并且配置了 NGROK_URL
if(app()->environment('local') && $url = config('app.ngrok_url')) {
// route() 函数第三个参数代表是否绝对路径
return $url.route($routeName, $parameters, false);
}

return route($routeName, $parameters);
}
2 changes: 2 additions & 0 deletions config/app.php
Original file line number Diff line number Diff line change
@@ -231,4 +231,6 @@

],

'ngrok_url' => env('NGROK_URL'),

];

0 comments on commit c36922b

Please sign in to comment.