李帅

1.todo paypal

......@@ -95,6 +95,7 @@ class AdminMakeVideoController extends AdminController
->when(1,function (Form $form){
$form->file('video_url','上传视频')
// ->accept('mp4,mov')
->chunked()
->autoUpload()
->uniqueName()
->maxSize('128000')
......
......@@ -5,6 +5,7 @@ namespace App\Http\Controllers\V1;
use App\Http\Controllers\Controller;
use App\Models\PackPoem;
use Illuminate\Http\Request;
use Illuminate\Support\Facades\Validator;
use Jiannei\Response\Laravel\Support\Facades\Response;
class HomeController extends Controller
......@@ -23,7 +24,9 @@ class HomeController extends Controller
public function packpoem(Request $request)
{
$packpoems = PackPoem::query()->where('state',0)->paginate(0);
$packpoems = PackPoem::query()->where('state',0)
->orderByDesc('id')
->simplePaginate(intval($request->per_page));
return Response::success($packpoems);
}
......
......@@ -22,7 +22,7 @@ class UserController extends Controller
public function login(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => 'required|max:255',
'email' => 'required|email|max:255',
'password' => 'required',
]);
......@@ -51,7 +51,7 @@ class UserController extends Controller
public function register(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => 'required|unique:users|max:255',
'email' => 'required|email|unique:users|max:255',
'password' => 'required',
'verify_code' => 'required'
]);
......@@ -84,7 +84,7 @@ class UserController extends Controller
public function verify(Request $request)
{
$validator = Validator::make($request->all(), [
'email' => 'required|max:255',
'email' => 'required|email|max:255',
]);
if ($validator->fails()){
......
......@@ -17,6 +17,8 @@ class PaymentFactory
return new AliPayment();
case 'wechat':
return new WechatPayment();
case 'paypal':
return new PayPalPayment();
default:
throw new \Exception('未知的支付方式');
}
......
<?php
/**
* Created by PhpStorm.
* User: lishuai
* Date: 2022/2/15
* Time: 4:23 PM
*/
namespace App\Payment;
use App\Models\Order;
use GuzzleHttp\Client;
use Illuminate\Support\Facades\Redis;
class PaypalPayment implements PaymentInterface
{
const IS_SANDBOX = true;
public $authUrl = 'https://api-m.sandbox.paypal.com/v1/oauth2/token';
public $paySandboxUrl = 'https://api-m.sandbox.paypal.com';
public $payUrl = 'https://api-m.paypal.com';
public $clientId = 'AdDRE91WSp5q1fYLODpJduc2mRjA_v6E205SvkfVSOgvr98xLeyDCHY4OPAaSFMK1SHYOfJ4TksHSX1-';
public $secret = 'EDoy_PVrFyobWt9DzAMRMikJwWCXenkWSx9CGFz0MxHt3a8fs6v-LnORMilIbftb2GwBKxOoTVZNBHNR';
/** 访问令牌*/
public $accessToken;
public function __construct()
{
// 初始化时做一些准备工作
$redis = Redis::connection();
$access_token = $redis->get('paypal:access_token');
if ($access_token){
$this->accessToken = $access_token;
}else{
$client = new Client([
'headers'=>[
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept'=>'application/json',
]
]);
$response = $client->post($this->authUrl,[
'form_params'=>['grant_type' => 'client_credentials'],
'auth' => [$this->clientId, $this->secret],
]);
$body = $response->getBody();
$content = json_decode($body->getContents(),true);
$this->accessToken = $content['access_token'];
$redis->setex('paypal:access_token',$content['expires_in'],$content['access_token']);
}
}
public function prepare(Order $order)
{
// 在PayPal上创建一个订单,它会返回一个订单对象,它有一个订单id
return $this->accessToken;
}
}
\ No newline at end of file
......@@ -81,10 +81,10 @@ return [
'count' => ['alias' => 'count', 'show' => true],
'per_page' => ['alias' => 'per_page', 'show' => true],
'current_page' => ['alias' => 'current_page', 'show' => true],
'total_pages' => ['alias' => 'total_pages', 'show' => true],
'total_pages' => ['alias' => 'total_pages', 'show' => false],
'links' => [
'alias' => 'links',
'show' => true,
'show' => false,
'fields' => [
'previous' => ['alias' => 'previous', 'show' => true],
......