我正在为使用Midtrans付款的项目工作,所以我使用来自ixudra/curl的Api curl,从我尝试实现到我的控制器我得到了这个代码
public function index()
{
$response = Curl::to('https://api.sandbox.midtrans.com/v2/token')
->withHeader('Content-Type: application/json')
->withHeader('Accept: application/json')
->withHeader('Authorization: Basic xxxxxxxxxxx')
->withData( array( 'card_number' => '4811111111111114' ) )
->withData( array( 'card_cvv' => '123' ) )
->withData( array( 'card_exp_month' => '01' ) )
->withData( array( 'card_exp_year' => '2020' ) )
->withData( array( 'client_key' => 'SB-Mid-client-xxxxxxxxxx' ) )
->asJson()
->returnResponseObject()
->get();
return response()->json($response);
}
然后我得到了这个回归json
content
status_code "400"
status_message "One or more parameters in the payload is invalid."
id "49ab5da0-6df2-4843-a1ed-cfedfea61798"
validation_messages
0 "unsupported token request parameter(s)"
status 200
contentType "application/json"
我认为我的代码存在问题,因为我尝试实施邮递员,并且它正在工作并返回令牌
答案 0 :(得分:1)
首先看一下header。
->withHeader('Content-Type: application/json')
->withHeader('Accept: application/json')
方法get
。
答案 1 :(得分:0)
问题解决了,我改变了所有 - > withData()这个
ns