李帅

1.打印paypal token

......@@ -20,7 +20,7 @@ class PayController extends Controller
$order = Order::query()->where('order_sn', $order_sn)->first();
if ($order->status !== Order::UNPAID) return false;
if ($order->status != Order::UNPAID) return Response::fail('订单错误!');
// if ($order->pay_amount <= 0) return $this->paid($order_sn); 0元购应该单独写一套
......
......@@ -35,33 +35,27 @@ class PaypalPayment implements PaymentInterface
public function __construct()
{
try{
// 初始化时做一些准备工作
$redis = Redis::connection();
$access_token = $redis->get('paypal:access_token');
if ($access_token){
Log::channel('daily')->debug($access_token);
$this->accessToken = $access_token;
}else{
$client = new Client([
'base_uri' => $this->baseUrlSandbox,
'headers'=>[
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept'=>'application/json',
]
]);
$response = $client->post('/v1/oauth2/token',[
'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'];
Log::channel('daily')->debug($content['access_token']);
$redis->setex('paypal:access_token',$content['expires_in'],$content['access_token']);
}
}catch (\Exception $exception){
Log::channel('daily')->error($exception->getMessage());
// 初始化时做一些准备工作
$redis = Redis::connection();
$access_token = $redis->get('paypal:access_token');
if ($access_token){
$this->accessToken = $access_token;
}else{
$client = new Client([
'base_uri' => $this->baseUrlSandbox,
'headers'=>[
'Content-Type' => 'application/x-www-form-urlencoded',
'Accept'=>'application/json',
]
]);
$response = $client->post('/v1/oauth2/token',[
'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']);
}
}
......