我正在将基于订阅的api集成到我的laravel项目中,并且该api调用使用callback_url
https://example.com/api/callback-handler
发送异步响应并且已经在回调函数中被接收,但是如何在接收到响应时在另一个名为startSubcription()
的函数中传递响应?
我尝试使用GLOBAL
数组,session
变量cookie
,但在该函数中不起作用。
在startSubcription()函数中使用时,会话变量包含null函数,但在callback()函数中打印
$req_details = (object) array(
'action' => 'subscription',
'merchant' => 'xxxxx',
'order' => 'xxxxxx',
'request_id' => 'zxxxxx',
'service_name' => $service_name,
'url_callback' => 'https://example.com/api/callback-handler',
'url_return' => 'https://example.com/start-subscription',
);
API调用::
$url = "https://services.exmple.at/smart/payment?action&merchant=$req_details->merchant&digest=$digest&order=$req_details->order&request_id=$req_details->request_id&service_name=$service_name&url_callback=$req_details->url_callback&url_return=$req_details->url_return";
public function callback(HttpRequest $request)
{
$callback_response = file_get_contents('php://input');
$callback_response = urldecode($callback_response);
$callback_response_xml = simplexml_load_string($callback_response_xml);
$json_callback_response = json_encode($callback_response_xml);
$callback_array_response = json_decode($json_callback_response, true);
$channel = $callback_array_response['payment_parameters']
['channel'];
}
现在我想使用$channel
中的startSubscription()
,该函数在url_return中提到的回调之后执行
我想在同一控制器中存在的此函数内使用$channel
public function startSubscription(HttpRequest $request)
{
if ($channel == something){
//some task
}
}
请帮帮我
谢谢