Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

增加扩展数据表 #400

Open
wants to merge 2 commits into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .env
Original file line number Diff line number Diff line change
Expand Up @@ -23,7 +23,6 @@ BROADCAST_DRIVER=log
SESSION_DRIVER=file
SESSION_LIFETIME=120


# 缓存配置
# file为磁盘文件 redis为内存级别
# redis为内存需要安装好redis服务端并配置
Expand Down
105 changes: 105 additions & 0 deletions app/Http/Controllers/Pay/XunhuController.php
Original file line number Diff line number Diff line change
@@ -0,0 +1,105 @@
<?php

namespace App\Http\Controllers\Pay;

use App\Exceptions\RuleValidationException;
use App\Http\Controllers\PayController;
use App\Models\Order;

class XunhuController extends PayController
{
/**
* 虎皮椒v3支付网关
* @return void
*/
public function gateway(string $payway, string $orderSN)
{
try {
//加载网关
$this->loadGateWay($orderSN, $payway);
$config = [
'version' => '1.1',
'appid' => $this->payGateway->merchant_id,
'trade_order_id' => $this->order->order_sn,
'total_fee' => (float)$this->order->actual_price,
'title' => $this->order->order_sn,
'time' => time(),
'notify_url' => url($this->payGateway->pay_handleroute . '/notify_url'),
'return_url' => url('detail-order-sn', ['orderSN' => $this->order->order_sn]),
'nonce_str' => $this->getNonceStr(),
];
$config['hash'] = $this->getSign($config, $this->payGateway->merchant_key);
$client = new \GuzzleHttp\Client();
$response = $client->post($this->payGateway->merchant_pem, [
'json' => $config
]);
$res = json_decode($response->getBody()->getContents(), true);
if($res['errcode'] == 0){
return redirect()->away($res['url']);
} else {
return $this->err(__('dujiaoka.prompt.abnormal_payment_channel') . $res['errmsg']);
}

} catch (RuleValidationException $e) {
return $this->err($e->getMessage());
}

}

//get nonce_str
public function getNonceStr($length = 32)
{
$chars = "abcdefghijklmnopqrstuvwxyz0123456789";
$str = "";
for ($i = 0; $i < $length; $i++) {
$str .= substr($chars, mt_rand(0, strlen($chars) - 1), 1);
}
return $str;
}

//hash
public function getSign($data, $key)
{
ksort($data);
$string = '';
foreach ($data as $k => $v) {
$string .= $k . '=' . $v . '&';
}
$string = rtrim($string, '&');
$string = $string . $key;
return md5($string);
}

//notify_url
public function notifyUrl(Request $request)
{
//验证签名
$data = $request->all();
$sign = $data['hash'];
unset($data['hash']);
$hash = $this->getSign($data, $this->payGateway->merchant_key);
if ($sign != $hash) {
return 'fail';
}
//验证订单
$order = Order::where('order_sn', $data['trade_order_id'])->first();
if (!$order) {
return 'fail';
}
//验证金额
if ($order->actual_price != $data['total_fee']) {
return 'fail';
}
$this->orderProcessService->completedOrder($order);
return 'success';
}

//return_url
public function returnUrl(Request $request)
{
$oid = $request->get('trade_order_id');
// 异步通知还没到就跳转了,所以这里休眠2秒
sleep(2);
return redirect(url('detail-order-sn', ['orderSN' => $oid]));
}
}
3 changes: 2 additions & 1 deletion composer.json
Original file line number Diff line number Diff line change
Expand Up @@ -22,7 +22,8 @@
"simplesoftwareio/simple-qrcode": "2.0.0",
"stripe/stripe-php": "^7.84",
"xhat/payjs-laravel": "^1.6",
"yansongda/pay": "^2.10"
"yansongda/pay": "^2.10",
"ext-json": "*"
},
"require-dev": {
"facade/ignition": "^1.16.15",
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,61 @@
<?php

use Illuminate\Database\Migrations\Migration;
use Illuminate\Database\Schema\Blueprint;
use Illuminate\Support\Facades\Schema;

class CreateAdminExtensionsTable extends Migration
{
public function getConnection()
{
return $this->config('database.connection') ?: config('database.default');
}

public function config($key)
{
return config('admin.'.$key);
}

/**
* Run the migrations.
*
* @return void
*/
public function up()
{
Schema::create($this->config('database.extensions_table') ?: 'admin_extensions', function (Blueprint $table) {
$table->increments('id')->unsigned();
$table->string('name', 100)->unique();
$table->string('version', 20)->default('');
$table->tinyInteger('is_enabled')->default(0);
$table->text('options')->nullable();
$table->timestamps();

$table->engine = 'InnoDB';
});

Schema::create($this->config('database.extension_histories_table') ?: 'admin_extension_histories', function (Blueprint $table) {
$table->bigIncrements('id')->unsigned();
$table->string('name', 100);
$table->tinyInteger('type')->default(1);
$table->string('version', 20)->default(0);
$table->text('detail')->nullable();

$table->index('name');
$table->timestamps();

$table->engine = 'InnoDB';
});
}

/**
* Reverse the migrations.
*
* @return void
*/
public function down()
{
Schema::dropIfExists($this->config('database.extensions_table') ?: 'admin_extensions');
Schema::dropIfExists($this->config('database.extension_histories_table') ?: 'admin_extension_histories');
}
}