You cannot select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

43 lines
1.4 KiB
PHP

<?php
namespace Org\QzlPay;
use Exception;
class Client
{
public static function request($url, $params): Response
{
try {
$response = self::post($url, $params);
Log::write('REQUEST_RESPONSE: ' . $response);
} catch (Exception $e) {
Log::write('REQUEST_ERROR: ' . $e->getMessage());
$response = json_encode([
'result' => -99,
'errorMsg' => '网络异常',
'signature' => true,
]);
}
return new Response($response);
}
public static function post($url, $params): string
{
Log::write('REQUEST_URL: ' . $url);
Log::write('REQUEST_DATA: ' . json_encode($params));
$curl = curl_init();
if (stripos($url, 'https://') !== false){
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, false);
}
curl_setopt($curl, CURLOPT_URL, $url);
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($curl, CURLOPT_POST, true);
$headers = ['Content-Type: application/x-www-form-urlencoded'];
curl_setopt($curl, CURLOPT_HTTPHEADER, $headers);
curl_setopt($curl, CURLOPT_POSTFIELDS, http_build_query($params));
$response = curl_exec($curl);
curl_close($curl);
return $response;
}
}