Toggle navigation
Toggle navigation
This project
Loading...
Sign in
fe
/
YOHOBUYPC
·
Commits
Go to a project
GitLab
Go to group
Project
Activity
Files
Commits
Pipelines
0
Builds
0
Graphs
Milestones
Issues
0
Merge Requests
2
Members
Labels
Wiki
Forks
Network
Create a new issue
Download as
Email Patches
Plain Diff
Browse Files
Authored by
郝肖肖
9 years ago
Commit
e590ac06264bd01fcbea514e02db333cae716077
1 parent
4430c844
udplog
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
9 additions
and
53 deletions
library/WebPlugin/Pay/Unionpayweb/Func/PinBlock.php
library/WebPlugin/Pay/Unionpayweb/Func/PublicEncrypte.php
library/WebPlugin/Pay/Unionpayweb/Func/common.php
library/WebPlugin/Pay/Unionpayweb/Func/secureUtil.php
library/WebPlugin/Pay/Unionpayweb/Func/PinBlock.php
View file @
e590ac0
...
...
@@ -91,10 +91,8 @@
function
Pin2PinBlockWithCardNO
(
&
$sPin
,
&
$sCardNO
)
{
global
$log
;
$sPinBuf
=
Pin2PinBlock
(
$sPin
);
$iCardLen
=
strlen
(
$sCardNO
);
// $log->LogInfo("CardNO length : " . $iCardLen);
if
(
$iCardLen
<=
10
)
{
return
(
1
);
...
...
library/WebPlugin/Pay/Unionpayweb/Func/PublicEncrypte.php
View file @
e590ac0
...
...
@@ -2,13 +2,11 @@
include_once
'PinBlock.php'
;
function
EncryptedPin
(
$sPin
,
$sCardNo
,
$sPubKeyURL
)
{
global
$log
;
$sPubKeyURL
=
trim
(
dirname
(
__FILE__
)
.
'/../'
.
SDK_ENCRYPT_CERT_PATH
,
" "
);
$fp
=
fopen
(
$sPubKeyURL
,
"r"
);
if
(
$fp
!=
NULL
)
{
$sCrt
=
fread
(
$fp
,
8192
);
// $log->LogInfo("fread PubKeyURL : " . $sCrt);
fclose
(
$fp
);
}
$sPubCrt
=
openssl_x509_read
(
$sCrt
);
...
...
@@ -17,13 +15,8 @@
print
(
"openssl_x509_read in false!"
);
return
(
-
1
);
}
// $log->LogInfo($sPubCrt);
// $sPubKeyId = openssl_x509_parse($sCrt);
// $log->LogInfo($sPubKeyId);
$sPubKey
=
openssl_x509_parse
(
$sPubCrt
);
// $log->LogInfo($sPubKey);
// openssl_x509_free($sPubCrt);
// print_r(openssl_get_publickey($sCrt));
$sInput
=
Pin2PinBlockWithCardNO
(
$sPin
,
$sCardNo
);
if
(
$sInput
==
1
)
...
...
@@ -34,9 +27,7 @@
$iRet
=
openssl_public_encrypt
(
$sInput
,
$sOutData
,
$sCrt
,
OPENSSL_PKCS1_PADDING
);
if
(
$iRet
===
TRUE
)
{
// $log->LogInfo($sOutData);
$sBase64EncodeOutData
=
base64_encode
(
$sOutData
);
//print("PayerPin : " . $sBase64EncodeOutData);
return
$sBase64EncodeOutData
;
}
else
...
...
library/WebPlugin/Pay/Unionpayweb/Func/common.php
View file @
e590ac0
<?php
// 初始化日志
use
WebPlugin\PhpLog
;
use
WebPlugin\UdpLog
;
$log
=
new
PhpLog
(
SDK_LOG_FILE_PATH
,
"PRC"
,
SDK_LOG_LEVEL
);
/**
* 数组 排序后转化为字体串
*
...
...
@@ -77,9 +75,7 @@ function deal_params(&$params)
*/
function
deflate_file
(
&
$params
)
{
global
$log
;
foreach
(
$_FILES
as
$file
)
{
$log
->
LogInfo
(
"---------处理文件---------"
);
if
(
file_exists
(
$file
[
'tmp_name'
]))
{
$params
[
'fileName'
]
=
$file
[
'name'
];
...
...
@@ -87,9 +83,6 @@ function deflate_file(&$params)
$file_content_deflate
=
gzcompress
(
$file_content
);
$params
[
'fileContent'
]
=
base64_encode
(
$file_content_deflate
);
$log
->
LogInfo
(
"压缩后文件内容为>"
.
base64_encode
(
$file_content_deflate
));
}
else
{
$log
->
LogInfo
(
">>>>文件上传失败<<<<<"
);
}
}
}
...
...
@@ -101,30 +94,27 @@ function deflate_file(&$params)
*/
function
deal_file
(
$params
)
{
global
$log
;
if
(
isset
(
$params
[
'fileContent'
]))
{
$log
->
LogInfo
(
"---------处理后台报文返回的文件---------"
);
$fileContent
=
$params
[
'fileContent'
];
if
(
empty
(
$fileContent
))
{
$log
->
LogInfo
(
'文件内容为空'
)
;
continue
;
}
else
{
// 文件内容 解压缩
$content
=
gzuncompress
(
base64_decode
(
$fileContent
));
$root
=
SDK_FILE_DOWN_PATH
;
$filePath
=
null
;
if
(
empty
(
$params
[
'fileName'
]))
{
$log
->
LogInfo
(
"文件名为空"
);
if
(
empty
(
$params
[
'fileName'
]))
{
$filePath
=
$root
.
$params
[
'merId'
]
.
'_'
.
$params
[
'batchNo'
]
.
'_'
.
$params
[
'txnTime'
]
.
'txt'
;
}
else
{
$filePath
=
$root
.
$params
[
'fileName'
];
}
$handle
=
fopen
(
$filePath
,
"w+"
);
if
(
!
is_writable
(
$filePath
))
{
$log
->
LogInfo
(
"文件:"
.
$filePath
.
"不可写,请检查!"
);
UdpLog
::
info
(
"【处理报文中的文件】,function:deal_file,不可写,请检查"
,
$filePath
);
}
else
{
file_put_contents
(
$filePath
,
$content
);
$log
->
LogInfo
(
"文件位置 >:"
.
$filePath
);
UdpLog
::
info
(
"【文件位置】,function:deal_file,"
,
$filePath
);
}
fclose
(
$handle
);
}
...
...
library/WebPlugin/Pay/Unionpayweb/Func/secureUtil.php
View file @
e590ac0
<?php
use
WebPlugin\PhpLog
;
use
WebPlugin\UdpLog
;
include_once
'PublicEncrypte.php'
;
...
...
@@ -11,31 +10,23 @@ include_once 'PublicEncrypte.php';
*/
function
sign
(
&
$params
)
{
$log
=
new
PhpLog
(
SDK_LOG_FILE_PATH
,
"PRC"
,
SDK_LOG_LEVEL
);
$log
->
LogInfo
(
'=====签名报文开始======'
);
if
(
isset
(
$params
[
'transTempUrl'
]))
{
unset
(
$params
[
'transTempUrl'
]);
}
// 转换成key=val&串
$params_str
=
coverParamsToString
(
$params
);
$log
->
LogInfo
(
"签名key=val&...串 >"
.
$params_str
);
$params_sha1x16
=
sha1
(
$params_str
,
FALSE
);
$log
->
LogInfo
(
"摘要sha1x16 >"
.
$params_sha1x16
);
// 签名证书路径
$cert_path
=
dirname
(
__FILE__
)
.
'/../'
.
SDK_SIGN_CERT_PATH
;
$log
->
LogInfo
(
$cert_path
);
$private_key
=
getPrivateKey
(
$cert_path
);
// 签名
$sign_falg
=
openssl_sign
(
$params_sha1x16
,
$signature
,
$private_key
,
OPENSSL_ALGO_SHA1
);
if
(
$sign_falg
)
{
$signature_base64
=
base64_encode
(
$signature
);
$log
->
LogInfo
(
"签名串为 >"
.
$signature_base64
);
$params
[
'signature'
]
=
$signature_base64
;
}
else
{
$log
->
LogInfo
(
">>>>>签名失败<<<<<<<"
);
}
$log
->
LogInfo
(
'=====签名报文结束======'
);
UdpLog
::
info
(
"【Unionpayweb-签名】,function:sign,参数,"
,
$params
);
}
/**
...
...
@@ -46,23 +37,16 @@ function sign(&$params)
*/
function
verify
(
$params
)
{
$log
=
new
PhpLog
(
SDK_LOG_FILE_PATH
,
"PRC"
,
SDK_LOG_LEVEL
);
$log
->
LogInfo
(
'=====返回参数===='
);
$log
->
LogInfo
(
var_export
(
$params
,
true
));
// 公钥
$public_key
=
getPulbicKeyByCertId
(
$params
[
'certId'
]);
// 签名串
$signature_str
=
$params
[
'signature'
];
unset
(
$params
[
'signature'
]);
$params_str
=
coverParamsToString
(
$params
);
$log
->
LogInfo
(
'报文去[signature] key=val&串>'
.
$params_str
);
$signature
=
base64_decode
(
$signature_str
);
$params_sha1x16
=
sha1
(
$params_str
,
FALSE
);
$log
->
LogInfo
(
'摘要shax16>'
.
$params_sha1x16
);
$isSuccess
=
openssl_verify
(
$params_sha1x16
,
$signature
,
$public_key
,
OPENSSL_ALGO_SHA1
);
$log
->
LogInfo
(
$isSuccess
?
'验签成功'
:
'验签失败'
);
UdpLog
::
info
(
"【Unionpayweb-验签,function:verify,参数,"
,
$params
);
return
$isSuccess
;
}
...
...
@@ -74,11 +58,8 @@ function verify($params)
*/
function
getPulbicKeyByCertId
(
$certId
)
{
$log
=
new
PhpLog
(
SDK_LOG_FILE_PATH
,
"PRC"
,
SDK_LOG_LEVEL
);
$log
->
LogInfo
(
'报文返回的证书ID>'
.
$certId
);
// 证书目录
$cert_dir
=
dirname
(
__FILE__
)
.
'/../'
.
SDK_VERIFY_CERT_DIR
;
$log
->
LogInfo
(
'验证签名证书目录 :>'
.
$cert_dir
);
$handle
=
opendir
(
$cert_dir
);
if
(
$handle
)
{
while
(
$file
=
readdir
(
$handle
))
{
...
...
@@ -88,15 +69,11 @@ function getPulbicKeyByCertId($certId)
if
(
pathinfo
(
$file
,
PATHINFO_EXTENSION
)
==
'cer'
)
{
if
(
getCertIdByCerPath
(
$filePath
)
==
$certId
)
{
closedir
(
$handle
);
$log
->
LogInfo
(
'加载验签证书成功'
);
return
getPublicKey
(
$filePath
);
}
}
}
}
$log
->
LogInfo
(
'没有找到证书ID为['
.
$certId
.
']的证书'
);
}
else
{
$log
->
LogInfo
(
'证书目录 '
.
$cert_dir
.
'不正确'
);
}
closedir
(
$handle
);
return
null
;
...
...
Please
register
or
login
to post a comment