You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
106 lines
2.3 KiB
106 lines
2.3 KiB
<?php
|
|
/**
|
|
* Environment check for DataApi
|
|
* Please check your php environment by env_check() method before use DataApi Demo!
|
|
*/
|
|
require_once('Utility.inc.php');
|
|
|
|
/**
|
|
* environment check
|
|
* @return boolean
|
|
*/
|
|
function env_check()
|
|
{
|
|
//step1, shallow check : check openssl and curl extensions
|
|
|
|
$extensions = get_loaded_extensions();
|
|
if (!in_array('curl', $extensions))
|
|
{
|
|
return false;
|
|
}
|
|
if (!in_array('openssl', $extensions))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
//step2, function check : check used functions of openssl and curl
|
|
|
|
|
|
$func_openssl = get_extension_funcs("openssl");
|
|
if (!in_array('openssl_pkey_get_public', $func_openssl))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!in_array('openssl_public_encrypt', $func_openssl))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$func_curl = get_extension_funcs("curl");
|
|
if (!in_array('curl_init', $func_curl))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!in_array('curl_setopt', $func_curl))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!in_array('curl_exec', $func_curl))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!in_array('curl_error', $func_curl))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!in_array('curl_close', $func_curl))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
if (!in_array('curl_errno', $func_curl))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
|
|
//step3, deep check: test pub encrypt and curl post indeed
|
|
|
|
|
|
$rsa = new RsaPublicEncrypt('./');
|
|
if (!$rsa->pubEncrypt("test pub encrypt"))
|
|
{
|
|
return false;
|
|
}
|
|
|
|
$url = "www.baidu.com";
|
|
$heads = array('Content-Type: text/html;charset=UTF-8');
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 2);
|
|
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']);
|
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1);
|
|
curl_setopt($curl, CURLOPT_AUTOREFERER, 1);
|
|
curl_setopt($curl, CURLOPT_HTTPHEADER, $heads);
|
|
curl_setopt($curl, CURLOPT_POST, 1);
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, "test curl post");
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, 30);
|
|
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
$tmpInfo = curl_exec($curl);
|
|
if (curl_errno($curl))
|
|
{
|
|
return false;
|
|
}
|
|
curl_close($curl);
|
|
|
|
}
|
|
|
|
env_check();
|
|
|