请我需要帮助,我不知道我做错了什么。 通过邮递员可以访问 API,但在我的 laravel 应用程序中不起作用。
//...........
Client error: `POST https://remitademo.net/remita/exapp/api/v1/send/api/echannelsvc/merchant/api/paymentinit` resulted in a `405 Method Not Allowed` response:
{"responseData":"{\"status\":null,\"responseCode\":\"405\",\"responseMsg\":\"Request method \u0027GET\u0027 not supporte (truncated...)
//.................
$client = new Client();
$headers = [
'Content-Type' => 'application/json',
'Authorization' => "remitaConsumerKey={$merchantId},remitaConsumerToken={$hash}"
];
$body = [
"serviceTypeId"=>$serviceTypeId,
"amount"=>$amount,
"orderId"=>$orderId,
"payerName"=> Auth::user()->surname.' '.Auth::user()->firstname,
"payerEmail"=> Auth::user()->email,
"payerPhone"=>Auth::user()->phone,
"description"=>"Payment for Septmeber Fees"
];
$request = new Request('POST', 'https://remitademo.net/remita/exapp/api/v1/send/api/echannelsvc/merchant/api/paymentinit', $headers, json_encode($body));
$res = $client->sendAsync($request
);
根据 Remita API
的
official-docs,API 的响应应收集为(因为它是异步请求)。
$res = $client->sendAsync($request)->wait();
echo $res->getBody();
或者,您也可以按照 Guzzle Documentation 使用此方法。
// Send an asynchronous request.
$res= $client->sendAsync($request)->then(function ($response) {
echo 'I completed! ' . $response->getBody();
});
$res->wait();
N:B :- 另请注意,apiHash 是连接
SHA-512
+ merchantId
+ serviceTypeId
+ orderId
+ totalAmount
的 apiKey
加密。
尝试一下并告诉我。