Php 在SLIM框架中创建一个全局变量以用于另一路线 我需要创建一个全局变量以用于另一条路线,我不熟悉SLIM框架,我搜索的所有内容都不起作用。 因此,基本上我在显示主屏幕的路由中获取价格,然后我需要在另一个路由中使用该价格创建一个条带API会话。见下文; $app = new Slim\App; $app->get('/pay/{price}', function (Request $request, Response $response, $args) { $response->getBody()->write(file_get_contents("../../client/index.html")); $key = "8881727727272"; $decrypted = openssl_decrypt(hex2bin($args['price']),'AES-128-CBC',$key); <---- CREATED HERE!!! return $response; }); $app->get('/success', function (Request $request, Response $response, $args) { $response->getBody()->write(file_get_contents("../../client/success.html")); return $response; }); $app->get('/cancel', function (Request $request, Response $response, $args) { $response->getBody()->write(file_get_contents("../../client/cancel.html")); return $response; }); $app->post('/create-session', function(Request $request, Response $response) use ($app) { try { $cafe = 'test'; $session = \Stripe\Checkout\Session::create([ 'payment_method_types' => ['card'], 'line_items' => [[ 'name' => $cafe, 'description' => 'ordering', 'images' => [''], 'amount' => $decrypted, <--- Needs to be used again here! 'currency' => 'aud', 'quantity' => 1, ]], 'success_url' => 'http://localhost/success?session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => 'http://localhost/cancel', ]); createSession($session->id); } catch (Exception $e) { return $response->withJson($e->getJsonBody(), 400); } return $response->withJson($session); }); $app=new Slim\app; $app->get('/pay/{price}',函数(请求$Request,响应$Response,$args){ $response->getBody()->write(文件获取内容(“../../client/index.html”); $key=“888177727272”; $decrypted=openssl_decrypt(hex2bin($args['price']),'AES-128-CBC',$key);get('/success',函数(请求$Request,响应$Response,$args){ $response->getBody()->write(文件获取内容(“../../client/success.html”); 返回$response; }); $app->get('/cancel',函数(请求$Request,响应$Response,$args){ $response->getBody()->write(文件获取内容(“../../client/cancel.html”); 返回$response; }); $app->post('/create session',函数(请求$Request,响应$Response)使用($app){ 试一试{ $cafe=‘测试’; $session=\Stripe\Checkout\session::create([ “付款方式类型”=>[“卡”], “行项目”=>[[ 'name'=>$cafe, '说明'=>'排序', '图像'=>[''], '金额'=>$decrypted,'澳元', “数量”=>1, ]], 'success_url'=>'http://localhost/success?session_id={签出会话ID}, '取消url'=>'http://localhost/cancel', ]); createSession($session->id); }捕获(例外$e){ 返回$response->withJson($e->getJsonBody(),400); } 返回$response->withJson($session); });

Php 在SLIM框架中创建一个全局变量以用于另一路线 我需要创建一个全局变量以用于另一条路线,我不熟悉SLIM框架,我搜索的所有内容都不起作用。 因此,基本上我在显示主屏幕的路由中获取价格,然后我需要在另一个路由中使用该价格创建一个条带API会话。见下文; $app = new Slim\App; $app->get('/pay/{price}', function (Request $request, Response $response, $args) { $response->getBody()->write(file_get_contents("../../client/index.html")); $key = "8881727727272"; $decrypted = openssl_decrypt(hex2bin($args['price']),'AES-128-CBC',$key); <---- CREATED HERE!!! return $response; }); $app->get('/success', function (Request $request, Response $response, $args) { $response->getBody()->write(file_get_contents("../../client/success.html")); return $response; }); $app->get('/cancel', function (Request $request, Response $response, $args) { $response->getBody()->write(file_get_contents("../../client/cancel.html")); return $response; }); $app->post('/create-session', function(Request $request, Response $response) use ($app) { try { $cafe = 'test'; $session = \Stripe\Checkout\Session::create([ 'payment_method_types' => ['card'], 'line_items' => [[ 'name' => $cafe, 'description' => 'ordering', 'images' => [''], 'amount' => $decrypted, <--- Needs to be used again here! 'currency' => 'aud', 'quantity' => 1, ]], 'success_url' => 'http://localhost/success?session_id={CHECKOUT_SESSION_ID}', 'cancel_url' => 'http://localhost/cancel', ]); createSession($session->id); } catch (Exception $e) { return $response->withJson($e->getJsonBody(), 400); } return $response->withJson($session); }); $app=new Slim\app; $app->get('/pay/{price}',函数(请求$Request,响应$Response,$args){ $response->getBody()->write(文件获取内容(“../../client/index.html”); $key=“888177727272”; $decrypted=openssl_decrypt(hex2bin($args['price']),'AES-128-CBC',$key);get('/success',函数(请求$Request,响应$Response,$args){ $response->getBody()->write(文件获取内容(“../../client/success.html”); 返回$response; }); $app->get('/cancel',函数(请求$Request,响应$Response,$args){ $response->getBody()->write(文件获取内容(“../../client/cancel.html”); 返回$response; }); $app->post('/create session',函数(请求$Request,响应$Response)使用($app){ 试一试{ $cafe=‘测试’; $session=\Stripe\Checkout\session::create([ “付款方式类型”=>[“卡”], “行项目”=>[[ 'name'=>$cafe, '说明'=>'排序', '图像'=>[''], '金额'=>$decrypted,'澳元', “数量”=>1, ]], 'success_url'=>'http://localhost/success?session_id={签出会话ID}, '取消url'=>'http://localhost/cancel', ]); createSession($session->id); }捕获(例外$e){ 返回$response->withJson($e->getJsonBody(),400); } 返回$response->withJson($session); });,php,slim,slim-3,Php,Slim,Slim 3,如果有人有什么好主意的话!!谢谢你我相信你说的不是全局变量(在一次脚本调用中,代码的所有部分都可以使用全局变量),但实际上您需要某种类型的持久性存储才能在不同的请求中使用。将值存储在会话中可能是一种选择。@尼玛,我刚刚尝试过,但无法在$app->post(“/create session”)中使用它路线为什么不将价格作为POST请求正文的一部分传递,并在/create session端点中进行解密?

如果有人有什么好主意的话!!谢谢你

我相信你说的不是全局变量(在一次脚本调用中,代码的所有部分都可以使用全局变量),但实际上您需要某种类型的持久性存储才能在不同的请求中使用。将值存储在会话中可能是一种选择。@尼玛,我刚刚尝试过,但无法在$app->post(“/create session”)中使用它路线为什么不将
价格
作为
POST
请求正文的一部分传递,并在
/create session
端点中进行解密?