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.
200 lines
6.5 KiB
200 lines
6.5 KiB
<?php
|
|
|
|
namespace app\service\pay;
|
|
|
|
use app\admin\controller\Base;
|
|
|
|
//base64方法
|
|
class Base64Method
|
|
{
|
|
|
|
public function encode($str)
|
|
{
|
|
$base64str = base64_encode($str);
|
|
$base64str = str_replace("+", "-", $base64str);
|
|
$base64str = str_replace("/", "_", $base64str);
|
|
return $base64str;
|
|
}
|
|
|
|
public function decode($str)
|
|
{
|
|
|
|
$str = str_replace("-", "+", $str);
|
|
$str = str_replace("_", "/", $str);
|
|
$unbase64str = base64_decode($str);
|
|
return $unbase64str;
|
|
}
|
|
}
|
|
|
|
//aes 加解密
|
|
class security
|
|
{
|
|
public function encrypt($privateKey, $iv, $data)
|
|
{
|
|
|
|
//$encrypted = mcrypt_encrypt (MCRYPT_RIJNDAEL_128, $privateKey, $data, MCRYPT_MODE_CBC, $iv);
|
|
$encrypted = openssl_encrypt($data, 'aes-128-cbc', $privateKey, true, $iv);
|
|
$base64method = new Base64Method();
|
|
|
|
return $base64method->encode($encrypted);;
|
|
// return $encrypted;
|
|
// $base64method->encode($encrypted);
|
|
// dd($base64method->encode($encrypted));
|
|
}
|
|
|
|
public function decrypt($privateKey, $iv, $data)
|
|
{
|
|
|
|
$base64method = new Base64Method();
|
|
$encryptedData = $base64method->decode($data);
|
|
// echo $encryptedData;dd();
|
|
// $decrypted = mcrypt_decrypt(MCRYPT_RIJNDAEL_128, $privateKey, $encryptedData, MCRYPT_MODE_CBC, $iv);
|
|
$decrypted = openssl_decrypt($encryptedData, 'aes-128-cbc', $privateKey, OPENSSL_RAW_DATA | OPENSSL_ZERO_PADDING, $iv);
|
|
return $decrypted;
|
|
}
|
|
}
|
|
|
|
//http get方法
|
|
class HttpHelper
|
|
{
|
|
|
|
public function getHttp($url)
|
|
{
|
|
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
$data = curl_exec($curl);
|
|
curl_close($curl);
|
|
return $data;
|
|
|
|
}
|
|
|
|
public function getSSLHttp($url)
|
|
{
|
|
$curl = curl_init();
|
|
curl_setopt($curl, CURLOPT_URL, $url);
|
|
curl_setopt($curl, CURLOPT_HEADER, 0);
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, FALSE); // https请求 不验证证书和hosts
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, FALSE);
|
|
$data = curl_exec($curl);
|
|
$httpCode = curl_getinfo($curl, CURLINFO_HTTP_CODE);
|
|
|
|
if ($httpCode != 200) {
|
|
$data = "https connect timeout";
|
|
}
|
|
curl_close($curl);
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 发送post请求
|
|
* @param string $url 请求地址
|
|
* @param array $post_data post键值对数据
|
|
* @return string
|
|
*/
|
|
|
|
function send_post($url, $post_data, $header = null)
|
|
{
|
|
$postData = http_build_query($post_data);
|
|
|
|
$options = array(
|
|
'http' => array(
|
|
'method' => 'POST',
|
|
'header' => 'Content-type:application/x-www-form-urlencoded',
|
|
'content' => $postData,
|
|
'timeout' => 15 * 60,// 超时时间(单位:s)
|
|
|
|
),
|
|
);
|
|
if ($header) {
|
|
//数组追加
|
|
$options['http'] = array_merge($header, $options['http']);
|
|
}
|
|
$context = stream_context_create($options);
|
|
$result = file_get_contents($url, false, $context);
|
|
|
|
return $result;
|
|
}
|
|
|
|
/**
|
|
* 发送post请求数据
|
|
* @param string $url 请求地址
|
|
* @param array $post_data post键值对数据
|
|
* @return string
|
|
*/
|
|
public function send_post_info($url, $data, $refererUrl = '', $method = 'GET', $contentType = 'application/json', $timeout = 30, $proxy = false)
|
|
{
|
|
$ch = null;
|
|
// $data = '{"buyerName":"\u6df1\u5733\u4ebf\u8d77\u878d\u7f51\u7edc\u79d1\u6280\u6709\u9650\u516c\u53f8","buyerType":"01","totalAmountTax":"100.00","manualOrderDetails":[{"amount":"100.00","invoiceNature":"01","itemName":"\u6d4b\u8bd5","itemTaxCode":"3049900000000000000","taxIncluded":"1","taxRate":"0.06","yhzcbs":"0"}]}';
|
|
if ('POST' === strtoupper($method)) {
|
|
$ch = curl_init($url);
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
if ($refererUrl) {
|
|
curl_setopt($ch, CURLOPT_REFERER, $refererUrl);
|
|
}
|
|
if ($contentType) {
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Accept:application/json;charset=UTF-8'));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:application/json;charset=UTF-8'));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('Authorization:' . $contentType['Authorization']));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('taxNo:' . $contentType['taxNo']));
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array('machineNo:' . $contentType['machineNo']));
|
|
|
|
|
|
}
|
|
if (is_string($data)) {
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
|
|
} else {
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($data));
|
|
}
|
|
} else if ('GET' === strtoupper($method)) {
|
|
// if (is_string($data)) {
|
|
// $real_url = $url . (strpos($url, '?') === false ? '?' : '') . $data;
|
|
// } else {
|
|
// $real_url = $url . (strpos($url, '?') === false ? '?' : '') . http_build_query($data);
|
|
// }
|
|
//
|
|
// $ch = curl_init($real_url);
|
|
// curl_setopt($ch, CURLOPT_HEADER, 0);
|
|
// curl_setopt($ch, CURLOPT_HTTPHEADER, array('Content-Type:' . $contentType));
|
|
// curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
// curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
// if ($refererUrl) {
|
|
// curl_setopt($ch, CURLOPT_REFERER, $refererUrl);
|
|
// }
|
|
} else {
|
|
$args = func_get_args();
|
|
return false;
|
|
}
|
|
|
|
if ($proxy) {
|
|
curl_setopt($ch, CURLOPT_PROXY, $proxy);
|
|
}
|
|
$ret = curl_exec($ch);
|
|
$info = curl_getinfo($ch);
|
|
$contents = array(
|
|
'httpInfo' => array(
|
|
'send' => $data,
|
|
'url' => $url,
|
|
'ret' => $ret,
|
|
'http' => $info,
|
|
),
|
|
);
|
|
|
|
curl_close($ch);
|
|
echo $ret;
|
|
dd();
|
|
return $ret;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
?>
|