* * @author JD Data Security Team (tenma.lin, wei.gao, mozhiyan, xuyina) * @version 1.0 * */ final class HttpsClient { private static $CAPath = ''; public static function loadCACert($isProd){ $prodCaPath = __DIR__ . Constants::PROD_CA_RELATIVE_PATH; $betaCaPath = __DIR__ . Constants::BETA_CA_RELATIVE_PATH; self::$CAPath = $isProd ? $prodCaPath : $betaCaPath; } public static function postForm($requestURL, $params) { // confige log $log = new Logger('httpsClient'); $formatter = new LineFormatter("[%datetime%] %channel%.%level_name%: %message%\r\n"); $handle = new StreamHandler(LOGCONSOLE, LOGLEVEL); $handle->setFormatter($formatter); $log->pushHandler($handle); $response = ''; $rootCause = ''; $hasConn = False; for($retry=0;$retryinfo("Https postJson error: " . $e->getMessage()); } } if(!$hasConn){ $log->error("HTTPS Client cannot establish connection:".$rootCause); throw new RuntimeException("HTTPS Client cannot establish connection:".$rootCause); } return $response; } public static function postJson($requestURL, $payload) { // confige log $log = new Logger('httpsClient'); $formatter = new LineFormatter("[%datetime%] %channel%.%level_name%: %message%\r\n"); $handle = new StreamHandler(LOGCONSOLE, LOGLEVEL); $handle->setFormatter($formatter); $log->pushHandler($handle); $response = ''; $rootCause = ''; $hasConn = False; for($retry=0;$retryinfo("Https postJson error: " . $e->getMessage()); } } if(!$hasConn){ $log->error("HTTPS Client cannot establish connection:".$rootCause); throw new RuntimeException("HTTPS Client cannot establish connection:".$rootCause); } return $response; } public static function httpJsonHeader() { $header = array( "Accept:application/json", "Content-Type:application/json;charset=UTF-8", "Connection:keep-alive" ); return $header; } public static function httpFormHeader() { $header = array( "Accept:application/json", "Content-Type:application/x-www-form-urlencoded;charset=UTF-8", "Connection:keep-alive" ); return $header; } }