curl with x-www-form-urlencoded

public function get_access_token($code){
	$params = [];
	$params['grant_type'] = 'authorization_code';
	$params['code'] = $code;
	$params['redirect_uri'] = $this->redirect_uri;
	$params['client_id'] = $this->client_id;
	$params['client_secret'] = $this->client_secret;

	$log = new ApiLog();
	$log->title = 'Line login listener';
	$log->request = json_encode($params);
	$log->save();

	$curl = curl_init();

	curl_setopt_array($curl, array(
		CURLOPT_URL => 'https://api.line.me/oauth2/v2.1/token',
		CURLOPT_RETURNTRANSFER => true,
		CURLOPT_ENCODING => '',
		CURLOPT_MAXREDIRS => 10,
		CURLOPT_TIMEOUT => 0,
		CURLOPT_FOLLOWLOCATION => true,
		CURLOPT_HTTP_VERSION => CURL_HTTP_VERSION_1_1,
		CURLOPT_SSL_VERIFYHOST => false, 
		CURLOPT_SSL_VERIFYPEER => false, 
		CURLOPT_CUSTOMREQUEST => 'POST',
		CURLOPT_POST => true, 
		CURLOPT_POSTFIELDS => http_build_query($params),
		CURLOPT_HTTPHEADER => array(
			'Content-Type: application/x-www-form-urlencoded'
		),
	));

	// 回傳的是JSON String, 所以需要json_decode()
	$response = curl_exec($curl);
	//logg($response);

	$log->response = $response;
	$log->save();

	curl_close($curl);
	$res = json_decode($response);
	$token = $res->access_token;

	return $token;
}