今天用ecshop时,发现了这个问题。

经过解码, 完美解决问题。

贴出解码代码,以供参考。

// This file is protected by copyright law & provided under license. Copyright(C) 2005-2009 www.chinapay.com, All rights reserved.

define("DES_KEY", "SCUBEPGW");

define("HASH_PAD", "0001ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff003021300906052b0e03021a05000414");

bcscale(0);

$private_key = array();

/*function hex2bin($hexdata) {

$bindata = '';

if (strlen($hexdata) % 2 == 1) {

$hexdata = '0' . $hexdata;

}

for ($i = 0; $i < strlen($hexdata); $i+=2) {

$bindata .= chr(hexdec(substr($hexdata, $i, 2)));

}

return $bindata;

}*/

function padstr($src, $len = 256, $chr = '0', $d = 'L') {

$ret = trim($src);

$padlen = $len - strlen($ret);

if ($padlen > 0) {

$pad = str_repeat($chr, $padlen);

if (strtoupper($d) == 'L') {

$ret = $pad . $ret;

} else {

$ret = $ret . $pad;

}

}

return $ret;

}

function bin2int($bindata) {

$hexdata = bin2hex($bindata);

return bchexdec($hexdata);

}

function bchexdec($hexdata) {

$ret = '0';

$len = strlen($hexdata);

for ($i = 0; $i < $len; $i++) {

$hex = substr($hexdata, $i, 1);

$dec = hexdec($hex);

$exp = $len - $i - 1;

$pow = bcpow('16', $exp);

$tmp = bcmul($dec, $pow);

$ret = bcadd($ret, $tmp);

}

return $ret;

}

function bcdechex($decdata) {

$s = $decdata;

$ret = '';

while ($s != '0') {

$m = bcmod($s, '16');

$s = bcdiv($s, '16');

$hex = dechex($m);

$ret = $hex . $ret;

}

return $ret;

}

function sha1_128($string) {

$hash = sha1($string);

$sha_bin = hex2bin($hash);

$sha_pad = hex2bin(HASH_PAD);

return $sha_pad . $sha_bin;

}

function mybcpowmod($num, $pow, $mod) {

if (function_exists('bcpowmod')) {

return bcpowmod($num, $pow, $mod);

}

return emubcpowmod($num, $pow, $mod);

}

function emubcpowmod($num, $pow, $mod) {

$result = '1';

do {

if (!bccomp(bcmod($pow, '2'), '1')) {

$result = bcmod(bcmul($result, $num), $mod);

}

$num = bcmod(bcpow($num, '2'), $mod);

$pow = bcdiv($pow, '2');

} while (bccomp($pow, '0'));

return $result;

}

function rsa_encrypt($private_key, $input) {

$p = bin2int($private_key["prime1"]);

$q = bin2int($private_key["prime2"]);

$u = bin2int($private_key["coefficient"]);

$dP = bin2int($private_key["prime_exponent1"]);

$dQ = bin2int($private_key["prime_exponent2"]);

$c = bin2int($input);

$cp = bcmod($c, $p);

$cq = bcmod($c, $q);

$a = mybcpowmod($cp, $dP, $p);

$b = mybcpowmod($cq, $dQ, $q);

if (bccomp($a, $b) >= 0) {

$result = bcsub($a, $b);

} else {

$result = bcsub($b, $a);

$result = bcsub($p, $result);

}

$result = bcmod($result, $p);

$result = bcmul($result, $u);

$result = bcmod($result, $p);

$result = bcmul($result, $q);

$result = bcadd($result, $b);

$ret = bcdechex($result);

$ret = strtoupper(padstr($ret));

return (strlen($ret) == 256) ? $ret : false;

}

function rsa_decrypt($input) {

global $private_key;

$check = bchexdec($input);

$modulus = bin2int($private_key["modulus"]);

$exponent = bchexdec("010001");

$result = bcpowmod($check, $exponent, $modulus);

$rb = bcdechex($result);

return strtoupper(padstr($rb));

}

function buildKey($key) {

global $private_key;

if (count($private_key) > 0) {

foreach ($private_key as $name => $value) {

unset($private_key[$name]);

}

}

$ret = false;

$key_file = parse_ini_file($key);

if (!$key_file) {

return $ret;

}

$hex = "";

if (array_key_exists("MERID", $key_file)) {

$ret = $key_file["MERID"];

$private_key["MERID"] = $ret;

$hex = substr($key_file["prikeyS"], 80);

} else

if (array_key_exists("PGID", $key_file)) {

$ret = $key_file["PGID"];

$private_key["PGID"] = $ret;

$hex = substr($key_file["pubkeyS"], 48);

} else {

return $ret;

}

$bin = hex2bin($hex);

$private_key["modulus"] = substr($bin, 0, 128);

$cipher = MCRYPT_DES;

$iv = str_repeat("\x00", 8);

$prime1 = substr($bin, 384, 64);

$enc = mcrypt_cbc($cipher, DES_KEY, $prime1, MCRYPT_DECRYPT, $iv);

$private_key["prime1"] = $enc;

$prime2 = substr($bin, 448, 64);

$enc = mcrypt_cbc($cipher, DES_KEY, $prime2, MCRYPT_DECRYPT, $iv);

$private_key["prime2"] = $enc;

$prime_exponent1 = substr($bin, 512, 64);

$enc = mcrypt_cbc($cipher, DES_KEY, $prime_exponent1, MCRYPT_DECRYPT, $iv);

$private_key["prime_exponent1"] = $enc;

$prime_exponent2 = substr($bin, 576, 64);

$enc = mcrypt_cbc($cipher, DES_KEY, $prime_exponent2, MCRYPT_DECRYPT, $iv);

$private_key["prime_exponent2"] = $enc;

$coefficient = substr($bin, 640, 64);

$enc = mcrypt_cbc($cipher, DES_KEY, $coefficient, MCRYPT_DECRYPT, $iv);

$private_key["coefficient"] = $enc;

return $ret;

}

function sign($msg) {

global $private_key;

if (!array_key_exists("MERID", $private_key)) {

return false;

}

$hb = sha1_128($msg);

return rsa_encrypt($private_key, $hb);

}

function signOrder($merid, $ordno, $amount, $curyid, $transdate, $transtype) {

if (strlen($merid) != 15)

return false;

if (strlen($ordno) != 16)

return false;

if (strlen($amount) != 12)

return false;

if (strlen($curyid) != 3)

return false;

if (strlen($transdate) != 8)

return false;

if (strlen($transtype) != 4)

return false;

$plain = $merid . $ordno . $amount . $curyid . $transdate . $transtype;

return sign($plain);

}

function verify($plain, $check) {

global $private_key;

if (!array_key_exists("PGID", $private_key)) {

return false;

}

if (strlen($check) != 256) {

return false;

}

$hb = sha1_128($plain);

$hbhex = strtoupper(bin2hex($hb));

$rbhex = rsa_decrypt($check);

return $hbhex == $rbhex ? true : false;

}

function verifyTransResponse($merid, $ordno, $amount, $curyid, $transdate, $transtype, $ordstatus, $check) {

if (strlen($merid) != 15)

return false;

if (strlen($ordno) != 16)

return false;

if (strlen($amount) != 12)

return false;

if (strlen($curyid) != 3)

return false;

if (strlen($transdate) != 8)

return false;

if (strlen($transtype) != 4)

return false;

if (strlen($ordstatus) != 4)

return false;

if (strlen($check) != 256)

return false;

$plain = $merid . $ordno . $amount . $curyid . $transdate . $transtype . $ordstatus;

return verify($plain, $check);

}

netpayclient.php,银联 chinapay php版本库文件netpayclient php在php5 4以上版本中提示hex2bin 重定义...相关推荐

  1. svn服务端删除版本库_删除SVN目录及从服务器端删除SVN版本库文件方法详解

    删除SVN目录 当使用了svn版本控制系统后每个目录下都会有一个.svn目录存在,开发完当交付产品或者上传到服务器时一般要把这些目录删除,这里总结了一下在linux和win下的办法. 一.在linux ...

  2. 项目从服务器移除,删除SVN目录及从服务器端删除SVN版本库文件方法详解

    删除SVN目录 当使用了svn版本控制系统后每个目录下都会有一个.svn目录存在,开发完当交付产品或者上传到服务器时一般要把这些目录删除,这里总结了一下在linux和win下的办法. 一.在linux ...

  3. 如何确认客户使用的Spartacus库文件是未经修改过的原始版本

    关键是使用HashCheck这个工具进行比较. In this document we describe how to use the tool to check if Spartacus libra ...

  4. Visual Studio各版本工程文件之间的转换(VS低版本打开高版本、高版本打开低版本项目问题)

    高版本的VS项目用低版本的VS编译器打开会报错: 通过修改Solution文件和Project文件,可以使低版本转换为高版本.低版本转化为高版本. 例如将VS2013工程转换为VS2010工程: 1. ...

  5. linuxSVN版本库及同步文件到WEB目录

    一 安装与配置SVN 1.安装subversion centos: yum install subversion ubuntu: apt-get install subversion 2.建立版本库, ...

  6. 【原创】Git删除暂存区或版本库中的文件

    0 基础     我们知道Git有三大区(工作区.暂存区.版本库)以及几个状态(untracked.unstaged.uncommited),下面只是简述下Git的大概工作流程,详细的可以参见本博客的 ...

  7. php chinapay,GitHub - jakehu/chinapay-for-ecshop: 上海银联(chinapay)支付插件 for ECSHOP

    chinapay-for-ecshop =================== 上海银联(chinapay)支付插件 for ECSHOP 银联支付有两个接口 upop 与 chinapay,很多 E ...

  8. chinapay支付接口php,GitHub - tension/chinapay-for-ecshop: 上海银联(chinapay)支付插件 for ECSHOP...

    chinapay-for-ecshop =================== 上海银联(chinapay)支付插件 for ECSHOP 银联支付有两个接口 upop 与 chinapay,很多 E ...

  9. linux subversion rpm,[linux笔记]在CentOS7.3中安装配置Apache2.4+Subversion1.9.*版本库

    安装Apache2.4[httpd] yum install httpd 启动httpd并设置开机启动 systemctl enable httpd.service systemctl start h ...

最新文章

  1. J0ker的CISSP之路:How CISSP(3)
  2. Surface Pro 4 和 Surface Book 使用名为 Surface UEFI(统一可扩展固件接口)的新固件接口...
  3. WPF特效-粒子动画
  4. Strust2 + Hibernate load方法出现的错误
  5. tableau度量值计算_Tableau可视化(雷达图):漫威英雄能力值
  6. 第二阶段个人总结10
  7. Cisco 3550配置DHCP中继代理
  8. postgres触发器使用
  9. 剑指offer面试题17. 打印从1到最大的n位数
  10. Python3练习题系列(03)
  11. win10蓝屏提示重新启动_Win10系统开机提示Winload.efi丢失的蓝屏问题怎么解决?
  12. vs以管理员身份运行
  13. 黑马畅购商城06-Elasticsearch
  14. 自动化测试po模式是什么?自动化测试po分层如何实现?(附详细源码)
  15. 微信公众号编辑文章发布时,弹出,图文消息中含有敏感词
  16. 130 个相见恨晚的超实用网站,一次性分享出来
  17. LLJ-300HS;LLJ-F(S)系列漏电继电器
  18. 使用U盘在虚拟机下安装双系统(windows and linux)乃至多系统
  19. UML活动图与状态图
  20. 小红书用户画像分析_用户画像分析会成为第一品牌竞争力吗?

热门文章

  1. 【设计推送】全方位科普移动端导航的七种设计模式
  2. (1)基础学习——图解pin、pad、port、IO、net 的区别
  3. span标签内使用icon图标,icon和文字位置水平对齐
  4. 小米路由hd php,小米路由器HD,附和R7800使用的对比感受
  5. 快手小程序模板_快手小程序模板平台制作
  6. 六年之后,我要离开(三)
  7. KunLun里的乾坤
  8. Corel Painter 15在Surface Pro 4下开启笔触压力感应
  9. 电力监控仪表主要分类
  10. 简搭云可视化大屏设计调研