|
|
|
@ -1,527 +1,84 @@
|
|
|
|
|
<?php
|
|
|
|
|
header('Content-type:text/html;charset=UTF-8');
|
|
|
|
|
class Efalipay {
|
|
|
|
|
//测试环境主扫接口路径
|
|
|
|
|
protected $gateway = 'http://test-efps.epaylinks.cn/api/txs/pay/NativePayment';
|
|
|
|
|
|
|
|
|
|
protected $gateway1 = 'http://test-efps.epaylinks.cn/api/txs/pay/UnifiedPayment';
|
|
|
|
|
|
|
|
|
|
protected $gateway2 = 'http://test-efps.epaylinks.cn//api/txs/pay/unionPayMent';
|
|
|
|
|
|
|
|
|
|
protected $bindCardUrl = 'https://efps.epaylinks.cn/api/txs/protocol/bindCard';
|
|
|
|
|
|
|
|
|
|
// protected $bindCardUrl = 'http://test-efps.epaylinks.cn/api/txs/protocol/bindCard';
|
|
|
|
|
|
|
|
|
|
//测试环境单笔提现接口路径
|
|
|
|
|
protected $withdrawalToCard = 'https://efps.epaylinks.cn/api/txs/pay/withdrawalToCard';
|
|
|
|
|
//进件
|
|
|
|
|
protected $apply_url = 'http://test-efps.epaylinks.cn/api/cust/SP/Merchant/apply';
|
|
|
|
|
//生产环境接口路径
|
|
|
|
|
//protected $gateway = 'https://efps.epaylinks.cn/api/txs/pay/NativePayment';
|
|
|
|
|
//私钥文件路径
|
|
|
|
|
public $rsaPrivateKeyFilePath = "/Users/liaojinling/Projects/php/payment/certs/prod/user.pfx";
|
|
|
|
|
//易票联公钥
|
|
|
|
|
public $publicKeyFilePath = "/Users/liaojinling/Projects/php/payment/certs/prod/efps.cer";
|
|
|
|
|
|
|
|
|
|
// public $rsaPrivateKeyFilePath = "/Users/liaojinling/Projects/php/payment/certs/dev/user.pfx";
|
|
|
|
|
//易票联公钥
|
|
|
|
|
// public $publicKeyFilePath = "/Users/liaojinling/Projects/php/payment/certs/dev/efps.cer";
|
|
|
|
|
|
|
|
|
|
//证书序列号
|
|
|
|
|
// public $sign_no='562265003122220003';
|
|
|
|
|
public $sign_no = '562276004021027002';
|
|
|
|
|
//证书密码
|
|
|
|
|
// public $password='123456';
|
|
|
|
|
|
|
|
|
|
public $password='iUixTxtl8N2Ntlx1LqZ';
|
|
|
|
|
|
|
|
|
|
//编码格式
|
|
|
|
|
public $charset = "UTF-8";
|
|
|
|
|
public $signType = "RSA2";
|
|
|
|
|
//商户号
|
|
|
|
|
protected $config = array(
|
|
|
|
|
// 'customer_code' => '562265003122220',
|
|
|
|
|
'customer_code' => '562276004021027',
|
|
|
|
|
'notify_url' => 'http://www.baidu.com',
|
|
|
|
|
'return_url' => 'http://www.baidu.com'
|
|
|
|
|
$params = [
|
|
|
|
|
'app_id' => '202306140000001',
|
|
|
|
|
'timestamp' => time(),
|
|
|
|
|
'nonce_str' => getRandomString(32),
|
|
|
|
|
'data' => json_encode([
|
|
|
|
|
'outOrderNo' => time().rand(1000, 9999),
|
|
|
|
|
'outMemberId' => 'T001',
|
|
|
|
|
'amount' => 100,
|
|
|
|
|
'notifyUrl' => 'https://www.baidu.com',
|
|
|
|
|
]),
|
|
|
|
|
];
|
|
|
|
|
$params['sign'] = sign($params, 'nM2bUJT89njQGzoeDyK8cLmEYJloUsJX');
|
|
|
|
|
$response = post('http://66.42.38.42:9501/payment/pay', json_encode($params));
|
|
|
|
|
var_dump(json_decode($response, true));die();
|
|
|
|
|
// select * from `orders` where `app_id` = '202306140000001' and `out_order_no` = '16869297292619' limit 1
|
|
|
|
|
$params = [
|
|
|
|
|
'app_id' => '202306140000001',
|
|
|
|
|
'timestamp' => time(),
|
|
|
|
|
'nonce_str' => getRandomString(32),
|
|
|
|
|
'data' => json_encode([
|
|
|
|
|
'outOrderNo' => '16869297292619',
|
|
|
|
|
]),
|
|
|
|
|
];
|
|
|
|
|
$params['sign'] = sign($params, 'nM2bUJT89njQGzoeDyK8cLmEYJloUsJX');
|
|
|
|
|
$response = post('http://146.70.113.165:9501/payment/query', json_encode($params));
|
|
|
|
|
var_dump(json_decode($response, true));
|
|
|
|
|
|
|
|
|
|
function post($url, $jsonStr) {
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, array(
|
|
|
|
|
'Content-Type: application/json; charset=utf-8',
|
|
|
|
|
'Content-Length: ' . strlen($jsonStr)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
|
curl_close($ch);
|
|
|
|
|
return $response;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
function sign($params, $secretKey) {
|
|
|
|
|
$signString = $params['app_id'] . '&'
|
|
|
|
|
. $params['timestamp'] . '&'
|
|
|
|
|
. $params['nonce_str'] . '&'
|
|
|
|
|
. $params['data'] . '&'
|
|
|
|
|
. $secretKey;
|
|
|
|
|
return md5($signString);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function check() {
|
|
|
|
|
if (!$this->config['customer_code'] ) {
|
|
|
|
|
E("支付设置有误!");
|
|
|
|
|
}
|
|
|
|
|
return true;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
// 测试主扫
|
|
|
|
|
public function buildRequestForm() {
|
|
|
|
|
$orderNo = "123456".date('YmdHis');
|
|
|
|
|
|
|
|
|
|
echo 'orderNo: '.$orderNo;
|
|
|
|
|
echo PHP_EOL;
|
|
|
|
|
$client_ip = "127.0.0.1";
|
|
|
|
|
if (getenv('HTTP_CLIENT_IP')) {
|
|
|
|
|
$client_ip = getenv('HTTP_CLIENT_IP');
|
|
|
|
|
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
|
|
|
|
|
$client_ip = getenv('HTTP_X_FORWARDED_FOR');
|
|
|
|
|
} elseif (getenv('REMOTE_ADDR')) {
|
|
|
|
|
$client_ip = getenv('REMOTE_ADDR');
|
|
|
|
|
} else {
|
|
|
|
|
$client_ip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$orderInfo=array();
|
|
|
|
|
$orderInfo['Id'] = $orderNo;
|
|
|
|
|
$orderInfo['businessType'] = '130001';
|
|
|
|
|
$orderInfo['goodsList'] = array(array('name'=>'pay','number'=>'one','amount'=>1));
|
|
|
|
|
|
|
|
|
|
$param = array(
|
|
|
|
|
'outTradeNo' => $orderNo,
|
|
|
|
|
'customerCode' => $this->config['customer_code'],
|
|
|
|
|
'clientIp' => $client_ip,
|
|
|
|
|
'orderInfo' => $orderInfo,
|
|
|
|
|
'payMethod' => 7,
|
|
|
|
|
'payAmount' => 10,
|
|
|
|
|
'payCurrency' => 'CNY',
|
|
|
|
|
'channelType' =>'02',
|
|
|
|
|
'notifyUrl' =>$this->config['notify_url'],
|
|
|
|
|
'redirectUrl' =>$this->config['return_url'],
|
|
|
|
|
'transactionStartTime' =>date('YmdHis'),
|
|
|
|
|
'nonceStr' => 'pay'.rand(100,999),
|
|
|
|
|
'version' => '3.0'
|
|
|
|
|
);
|
|
|
|
|
$sign = $this->sign(json_encode($param));
|
|
|
|
|
|
|
|
|
|
echo 'request: '.json_encode($param);
|
|
|
|
|
echo PHP_EOL .'sign: '.$sign;
|
|
|
|
|
|
|
|
|
|
$request = $this->http_post_json($this->gateway,json_encode($param),$sign);
|
|
|
|
|
if($request && $request[0] == 200){
|
|
|
|
|
echo PHP_EOL . 'response: ';
|
|
|
|
|
return $request[1];
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
print_r($request);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 统一下单
|
|
|
|
|
public function buildRequestForm1() {
|
|
|
|
|
$orderNo = "123456".date('YmdHis');
|
|
|
|
|
|
|
|
|
|
echo 'orderNo: '.$orderNo;
|
|
|
|
|
echo PHP_EOL;
|
|
|
|
|
$client_ip = "127.0.0.1";
|
|
|
|
|
if (getenv('HTTP_CLIENT_IP')) {
|
|
|
|
|
$client_ip = getenv('HTTP_CLIENT_IP');
|
|
|
|
|
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
|
|
|
|
|
$client_ip = getenv('HTTP_X_FORWARDED_FOR');
|
|
|
|
|
} elseif (getenv('REMOTE_ADDR')) {
|
|
|
|
|
$client_ip = getenv('REMOTE_ADDR');
|
|
|
|
|
} else {
|
|
|
|
|
$client_ip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$orderInfo = array();
|
|
|
|
|
$orderInfo['Id'] = $orderNo;
|
|
|
|
|
$orderInfo['businessType'] = '130001';
|
|
|
|
|
$orderInfo['goodsList'] = array(array('name'=>'pay','number'=>'one','amount'=>1));
|
|
|
|
|
|
|
|
|
|
$param = array(
|
|
|
|
|
'outTradeNo' => $orderNo,
|
|
|
|
|
'customerCode' => $this->config['customer_code'],
|
|
|
|
|
'clientIp' => $client_ip,
|
|
|
|
|
'orderInfo' => $orderInfo,
|
|
|
|
|
'payCurrency' => 'CNY',
|
|
|
|
|
|
|
|
|
|
// 'payMethod' => 7,
|
|
|
|
|
|
|
|
|
|
'payAmount' => 10,
|
|
|
|
|
'payCurrency' => 'CNY',
|
|
|
|
|
// 'channelType' =>'02',
|
|
|
|
|
'notifyUrl' =>$this->config['notify_url'],
|
|
|
|
|
'redirectUrl' =>$this->config['return_url'],
|
|
|
|
|
'transactionStartTime' =>date('YmdHis'),
|
|
|
|
|
'nonceStr' => 'pay'.rand(100,999),
|
|
|
|
|
'version' => '3.0'
|
|
|
|
|
);
|
|
|
|
|
$sign = $this->sign(json_encode($param));
|
|
|
|
|
|
|
|
|
|
echo 'request: '.json_encode($param);
|
|
|
|
|
echo PHP_EOL .'sign: '.$sign;
|
|
|
|
|
|
|
|
|
|
$request = $this->http_post_json($this->gateway1, json_encode($param),$sign);
|
|
|
|
|
if($request && $request[0] == 200){
|
|
|
|
|
echo PHP_EOL . 'response: ';
|
|
|
|
|
return $request[1];
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
print_r($request);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
// 统一下单
|
|
|
|
|
public function buildRequestForm2() {
|
|
|
|
|
$orderNo = "123456".date('YmdHis');
|
|
|
|
|
|
|
|
|
|
echo 'orderNo: '.$orderNo;
|
|
|
|
|
echo PHP_EOL;
|
|
|
|
|
$client_ip = "127.0.0.1";
|
|
|
|
|
if (getenv('HTTP_CLIENT_IP')) {
|
|
|
|
|
$client_ip = getenv('HTTP_CLIENT_IP');
|
|
|
|
|
} elseif (getenv('HTTP_X_FORWARDED_FOR')) {
|
|
|
|
|
$client_ip = getenv('HTTP_X_FORWARDED_FOR');
|
|
|
|
|
} elseif (getenv('REMOTE_ADDR')) {
|
|
|
|
|
$client_ip = getenv('REMOTE_ADDR');
|
|
|
|
|
} else {
|
|
|
|
|
$client_ip = $_SERVER['REMOTE_ADDR'];
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$orderInfo = array();
|
|
|
|
|
$orderInfo['Id'] = $orderNo;
|
|
|
|
|
$orderInfo['businessType'] = '130001';
|
|
|
|
|
$orderInfo['goodsList'] = array(array('name'=>'pay','number'=>'one','amount'=>1));
|
|
|
|
|
|
|
|
|
|
$param = array(
|
|
|
|
|
'outTradeNo' => $orderNo,
|
|
|
|
|
'customerCode' => $this->config['customer_code'],
|
|
|
|
|
'clientIp' => $client_ip,
|
|
|
|
|
'orderInfo' => $orderInfo,
|
|
|
|
|
'payCurrency' => 'CNY',
|
|
|
|
|
'payAmount' => 10,
|
|
|
|
|
'payCurrency' => 'CNY',
|
|
|
|
|
'bankCardType' =>'debit',
|
|
|
|
|
'notifyUrl' =>$this->config['notify_url'],
|
|
|
|
|
'frontUrl' =>$this->config['return_url'],
|
|
|
|
|
'transactionStartTime' =>date('YmdHis'),
|
|
|
|
|
'nonceStr' => 'pay'.rand(100,999),
|
|
|
|
|
'version' => '3.0'
|
|
|
|
|
);
|
|
|
|
|
$sign = $this->sign(json_encode($param));
|
|
|
|
|
|
|
|
|
|
echo 'request: '.json_encode($param);
|
|
|
|
|
echo PHP_EOL .'sign: '.$sign;
|
|
|
|
|
|
|
|
|
|
$request = $this->http_post_json($this->gateway2, json_encode($param),$sign);
|
|
|
|
|
if($request && $request[0] == 200){
|
|
|
|
|
echo PHP_EOL . 'response: ';
|
|
|
|
|
return $request[1];
|
|
|
|
|
|
|
|
|
|
}else{
|
|
|
|
|
print_r($request);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//测试单笔提现
|
|
|
|
|
public function withDraw() {
|
|
|
|
|
$orderNo = "tx123".date('YmdHis');
|
|
|
|
|
|
|
|
|
|
echo '订单号:'.$orderNo;
|
|
|
|
|
echo '<br>';
|
|
|
|
|
$param = array(
|
|
|
|
|
'outTradeNo' => $orderNo,
|
|
|
|
|
'customerCode' => $this->config['customer_code'],
|
|
|
|
|
'amount' => 10,
|
|
|
|
|
'bankUserName' =>$this->public_encrypt('张三'),
|
|
|
|
|
'bankCardNo' => $this->public_encrypt('6214858888883338'),
|
|
|
|
|
'bankName' => '招商银行',
|
|
|
|
|
'bankAccountType' =>'2',
|
|
|
|
|
'payCurrency' => 'CNY',
|
|
|
|
|
'notifyUrl' =>$this->config['notify_url'],
|
|
|
|
|
'nonceStr' => 'pay'.rand(100,999),
|
|
|
|
|
);
|
|
|
|
|
$sign = $this->sign(json_encode($param));
|
|
|
|
|
echo 'request: '.json_encode($param);
|
|
|
|
|
echo '<br>sign: '.$sign;
|
|
|
|
|
$request = $this->http_post_json($this->withdrawalToCard,json_encode($param),$sign);
|
|
|
|
|
if($request && $request[0] == 200){
|
|
|
|
|
echo '<br>'.'response: ';
|
|
|
|
|
return $request[1];
|
|
|
|
|
}else{
|
|
|
|
|
print_r($request);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function bindCard() {
|
|
|
|
|
$orderNo = "tx123".date('YmdHis');
|
|
|
|
|
|
|
|
|
|
echo '订单号:'.$orderNo;
|
|
|
|
|
echo '<br>';
|
|
|
|
|
$param = array(
|
|
|
|
|
'version' => '3.0',
|
|
|
|
|
'mchtOrderNo' => time() . rand(1000, 9999),
|
|
|
|
|
'customerCode' => $this->config['customer_code'],
|
|
|
|
|
'memberId' => $this->config['customer_code'],
|
|
|
|
|
'userName' => $this->public_encrypt('zs'),
|
|
|
|
|
'phoneNum' => $this->public_encrypt('18760419185'),
|
|
|
|
|
'bankCardNo' => $this->public_encrypt('6214835911385365'),
|
|
|
|
|
'bankCardType' => 'debit',
|
|
|
|
|
'certificatesType' => '01',
|
|
|
|
|
'certificatesNo' => $this->public_encrypt('350824199001105476'),
|
|
|
|
|
'nonceStr' => 'pay'.rand(100,999),
|
|
|
|
|
);
|
|
|
|
|
$sign = $this->sign(json_encode($param));
|
|
|
|
|
echo 'request: '.json_encode($param);
|
|
|
|
|
echo '<br>sign: '.$sign;
|
|
|
|
|
$request = $this->http_post_json($this->bindCardUrl,json_encode($param),$sign);
|
|
|
|
|
if($request && $request[0] == 200){
|
|
|
|
|
echo '<br>'.'response: ';
|
|
|
|
|
return $request[1];
|
|
|
|
|
}else{
|
|
|
|
|
print_r($request);
|
|
|
|
|
exit;
|
|
|
|
|
}
|
|
|
|
|
exit;
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
//进件
|
|
|
|
|
//发起进件
|
|
|
|
|
public function apply(){
|
|
|
|
|
$paper = '{"certificateName":"李四","contactPhone":"13531231222","email":"test1@test.cn","lawyerCertNo":"430481198104234557","lawyerCertType":"0","merchantType":"3","openBank":"中国银行","openingLicenseAccountPhoto":"https://www.epaylinks.cn/www/wimages/epl_logo.png","settleAccount":"李四","settleAccountNo":"6214830201234567","settleAccountType":"2","settleTarget":"2"}';
|
|
|
|
|
$business = array(
|
|
|
|
|
array(
|
|
|
|
|
"businessCode"=>"WITHDRAW_TO_SETTMENT_DEBIT",
|
|
|
|
|
"creditcardsEnabled"=>0,
|
|
|
|
|
"refundEnabled"=>1,
|
|
|
|
|
"refundFeePer"=>0,
|
|
|
|
|
"refundFeeRate"=>0,
|
|
|
|
|
"settleCycle"=>"D+0",
|
|
|
|
|
"stage"=>array(
|
|
|
|
|
array(
|
|
|
|
|
"amountFrom"=>0,
|
|
|
|
|
"feePer"=>50
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
)
|
|
|
|
|
);
|
|
|
|
|
$param =array(
|
|
|
|
|
'acqSpId' => $this->config['customer_code'],
|
|
|
|
|
'merchantName' => "测试商户20211202",
|
|
|
|
|
'acceptOrder' => 0,
|
|
|
|
|
'openAccount' => 1,
|
|
|
|
|
'paper' => $paper,
|
|
|
|
|
'business' =>$business
|
|
|
|
|
);
|
|
|
|
|
$sign = $this->sign(json_encode($param));
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
echo json_encode($param);
|
|
|
|
|
|
|
|
|
|
$res = $this->http_post_json($this->apply_url,json_encode($param),$sign);
|
|
|
|
|
var_dump($res);
|
|
|
|
|
die;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function generateSign($params) {
|
|
|
|
|
return $this->sign($this->getSignContent($params));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
public function rsaSign($params) {
|
|
|
|
|
return $this->sign($this->getSignContent($params));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getSignContent($params) {
|
|
|
|
|
ksort($params);
|
|
|
|
|
|
|
|
|
|
$stringToBeSigned = "";
|
|
|
|
|
$i = 0;
|
|
|
|
|
foreach ($params as $k => $v) {
|
|
|
|
|
|
|
|
|
|
if (false === $this->checkEmpty($v) && "@" != substr($v, 0, 1)) {
|
|
|
|
|
// 转换成目标字符集
|
|
|
|
|
$v = $this->characet($v, $this->charset);
|
|
|
|
|
|
|
|
|
|
if ($i == 0) {
|
|
|
|
|
$stringToBeSigned .= "$k" . "=" . "$v";
|
|
|
|
|
} else {
|
|
|
|
|
$stringToBeSigned .= "&" . "$k" . "=" . "$v";
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$i++;
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
unset ($k, $v);
|
|
|
|
|
|
|
|
|
|
return $stringToBeSigned;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function sign($data) {
|
|
|
|
|
|
|
|
|
|
$certs = array();
|
|
|
|
|
openssl_pkcs12_read(file_get_contents($this->rsaPrivateKeyFilePath), $certs, $this->password); //其中password为你的证书密码
|
|
|
|
|
|
|
|
|
|
($certs) or die('请检查RSA私钥配置');
|
|
|
|
|
|
|
|
|
|
openssl_sign($data, $sign, $certs['pkey'],OPENSSL_ALGO_SHA256);
|
|
|
|
|
|
|
|
|
|
$sign = base64_encode($sign);
|
|
|
|
|
return $sign;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 校验$value是否非空
|
|
|
|
|
* if not set ,return true;
|
|
|
|
|
* if is null , return true;
|
|
|
|
|
**/
|
|
|
|
|
protected function checkEmpty($value) {
|
|
|
|
|
if (!isset($value))
|
|
|
|
|
return true;
|
|
|
|
|
if ($value === null)
|
|
|
|
|
return true;
|
|
|
|
|
if (trim($value) === "")
|
|
|
|
|
return true;
|
|
|
|
|
|
|
|
|
|
return false;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
public function rsaCheckV2($params, $rsaPublicKeyFilePath,$sign) {
|
|
|
|
|
//$sign = $params['sign'];
|
|
|
|
|
//$params['sign'] = null;
|
|
|
|
|
|
|
|
|
|
return $this->verify($params, $sign, $rsaPublicKeyFilePath);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//使用易票联公钥验签 //返回的验签字段有中文需要加JSON_UNESCAPED_UNICODE才能验签通过
|
|
|
|
|
//$data2 = json_encode($data, JSON_UNESCAPED_UNICODE);
|
|
|
|
|
function verify($data, $sign, $rsaPublicKeyFilePath) {
|
|
|
|
|
|
|
|
|
|
//读取公钥文件
|
|
|
|
|
$pubKey = file_get_contents($this->publicKeyFilePath);
|
|
|
|
|
|
|
|
|
|
$res = openssl_get_publickey($pubKey);
|
|
|
|
|
|
|
|
|
|
($res) or die('RSA公钥错误。请检查公钥文件格式是否正确');
|
|
|
|
|
//调用openssl内置方法验签,返回bool值
|
|
|
|
|
|
|
|
|
|
$result = (bool)openssl_verify($data, base64_decode($sign), $res, OPENSSL_ALGO_SHA256);
|
|
|
|
|
|
|
|
|
|
if(!$this->checkEmpty($this->publicKeyFilePath)) {
|
|
|
|
|
//释放资源
|
|
|
|
|
openssl_free_key($res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return $result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
//使用易票联公钥加密
|
|
|
|
|
function public_encrypt($data)
|
|
|
|
|
function getRandomString($length, $withSpecialChar = false)
|
|
|
|
|
{
|
|
|
|
|
return $data;
|
|
|
|
|
//读取公钥文件
|
|
|
|
|
$pubKey = file_get_contents($this->publicKeyFilePath);
|
|
|
|
|
|
|
|
|
|
$res = openssl_get_publickey($pubKey);
|
|
|
|
|
|
|
|
|
|
($res) or die('RSA公钥错误。请检查公钥文件格式是否正确');
|
|
|
|
|
|
|
|
|
|
$crypttext = "";
|
|
|
|
|
|
|
|
|
|
openssl_public_encrypt($data,$crypttext, $res);
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if(!$this->checkEmpty($this->publicKeyFilePath)) {
|
|
|
|
|
//释放资源
|
|
|
|
|
openssl_free_key($res);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return(base64_encode($crypttext));
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 转换字符集编码
|
|
|
|
|
* @param $data
|
|
|
|
|
* @param $targetCharset
|
|
|
|
|
* @return string
|
|
|
|
|
*/
|
|
|
|
|
function characet($data, $targetCharset) {
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
if (!empty($data)) {
|
|
|
|
|
$fileType = $this->charset;
|
|
|
|
|
if (strcasecmp($fileType, $targetCharset) != 0) {
|
|
|
|
|
$chars = array(
|
|
|
|
|
'a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k',
|
|
|
|
|
'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v',
|
|
|
|
|
'w', 'x', 'y', 'z', 'A', 'B', 'C', 'D', 'E', 'F', 'G',
|
|
|
|
|
'H', 'I', 'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
|
|
|
|
|
'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z', '0', '1', '2',
|
|
|
|
|
'3', '4', '5', '6', '7', '8', '9'
|
|
|
|
|
);
|
|
|
|
|
|
|
|
|
|
$data = mb_convert_encoding($data, $targetCharset);
|
|
|
|
|
// $data = iconv($fileType, $targetCharset.'//IGNORE', $data);
|
|
|
|
|
}
|
|
|
|
|
if($withSpecialChar){
|
|
|
|
|
$chars = array_merge($chars, array(
|
|
|
|
|
'!', '@', '#', '$', '?', '|', '{', '/', ':', ';',
|
|
|
|
|
'%', '^', '&', '*', '(', ')', '-', '_', '[', ']',
|
|
|
|
|
'}', '<', '>', '~', '+', '=', ',', '.'
|
|
|
|
|
));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
$charsLen = count($chars) - 1;
|
|
|
|
|
shuffle($chars);
|
|
|
|
|
|
|
|
|
|
return $data;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function getParam($para) {
|
|
|
|
|
$arg = "";
|
|
|
|
|
while (list ($key, $val) = each($para)) {
|
|
|
|
|
$arg.=$key . "=" . $val . "&";
|
|
|
|
|
$password = '';
|
|
|
|
|
for($i=0; $i<$length; $i++){
|
|
|
|
|
$password .= $chars[mt_rand(0, $charsLen)];
|
|
|
|
|
}
|
|
|
|
|
//去掉最后一个&字符
|
|
|
|
|
$arg = substr($arg, 0, -1);
|
|
|
|
|
return $arg;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
* 获取远程服务器ATN结果,验证返回URL
|
|
|
|
|
* @param $notify_id
|
|
|
|
|
* @return
|
|
|
|
|
* 验证结果集:
|
|
|
|
|
* invalid命令参数不对 出现这个错误,请检测返回处理中partner和key是否为空
|
|
|
|
|
* true 返回正确信息
|
|
|
|
|
* false 请检查防火墙或者是服务器阻止端口问题以及验证时间是否超过一分钟
|
|
|
|
|
*/
|
|
|
|
|
protected function getResponse2($Params) {
|
|
|
|
|
$veryfy_url = $this->gateway . "?" . $Params;
|
|
|
|
|
$responseTxt = $this->fsockOpen($veryfy_url);
|
|
|
|
|
return $responseTxt;
|
|
|
|
|
return $password;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
protected function http_post_json($url, $jsonStr,$sign)
|
|
|
|
|
{
|
|
|
|
|
$ch = curl_init();
|
|
|
|
|
$headers = array(
|
|
|
|
|
'Content-Type: application/json; charset=utf-8',
|
|
|
|
|
'Content-Length: ' . strlen($jsonStr),
|
|
|
|
|
'x-efps-sign-no:'.$this->sign_no,
|
|
|
|
|
'x-efps-sign-type:SHA256withRSA',
|
|
|
|
|
'x-efps-sign:'.$sign,
|
|
|
|
|
'x-efps-timestamp:'.date('YmdHis'),
|
|
|
|
|
);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
|
|
|
curl_setopt($ch, CURLOPT_URL, $url);
|
|
|
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, $jsonStr);
|
|
|
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过检查
|
|
|
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, false); // 跳过检查
|
|
|
|
|
//curl_setopt($ch, CURLOPT_HEADER, true);
|
|
|
|
|
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
|
|
|
|
|
|
|
|
|
|
$response = curl_exec($ch);
|
|
|
|
|
|
|
|
|
|
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
|
|
|
|
|
|
|
|
|
|
return array($httpCode, $response);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
$efalipay = new Efalipay();
|
|
|
|
|
echo $efalipay->bindCard();
|
|
|
|
|