www.gusucode.com > ShopEx481 & PHPWind 整合版码程序 > plugins/payment/pay.udpay.server.php
<?php require('paymentPlugin.php'); class pay_udpay extends paymentPlugin{ function pay_udpay_callback($in,&$paymentId,&$money,&$message,&$tradeno){ $txCode = trim($in['?txCode']); //商家ID $merchantId = trim($in['merchantId']); //商家ID $transDate = trim($in['transDate']); //交易日期 $tradeno = $transFlow = trim($in['transFlow']); //交易号 $orderId = trim($in['orderId']); //交易号 $curCode = trim($in['curCode']); //交易金额 $money = $amount = trim($in['amount']); //交易金额 $orderInfo = trim($in['orderInfo']); //交易金额 $whtFlow = trim($in['whtFlow']); //交易金额 $success = trim($in['success']); //交易结果,"Y"表示成功,"N"表示失败 $errorType = trim($in['errorType']); //交易结果,"Y"表示成功,"N"表示失败 $sign = trim($in['sign']); $money = $amount; $key = $this->getConf($orderId, 'PrivateKey'); $msg = "txCode=".$txCode."&merchantId=".$merchantId."&transDate=".$transDate ."&transFlow=".$transFlow."&orderId=".$orderId."&curCode=".$curCode."&amount=".$amount ."&orderInfo=".$orderInfo."&comment=&whtFlow=".$whtFlow."&success=".$success."&errorType=".$errorType; if (!$this->getConf($orderId, 'udpay')){ echo("read key file error!"); exit; } $arr_key = file(dirname(__FILE__)."/../plugin/paykey/udpay/udpay.key"); $privatekey = substr(trim($arr_key[1]), 19); $privateModulus = substr(trim($arr_key[2]), 23); $privateExponent = substr(trim($arr_key[3]), 24); $publicKey = substr(trim($arr_key[4]), 14); $publicModulus = substr(trim($arr_key[5]), 18); $publicExponent = substr(trim($arr_key[6]), 19); $verifySigature = verifySigature($msg, $sign, $privateExponent, $privateModulus); if ($verifySigature == 0){ switch ($success){ //成功支付 case "Y": return PAY_SUCCESS; break; //支付失败 case "N": return PAY_ERROR; break; } }else{ return PAY_FAILED; } } } function pay_UDPAY_relay($status){ switch ($status){ case PAY_FAILED: echo "fail"; break; case PAY_SUCCESS: echo "received"; break; case PAY_ERROR: echo "fail"; break; } } function generateSigature($message, $exponent, $modulus){ $md5Message = md5($message); $fillStr = "01ffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffffff003020300c06082a864886f70d020505000410"; $md5Message = $fillStr.$md5Message; $intMessage = bin2int(hex2bin($md5Message)); $intE = bin2int(hex2bin($exponent)); $intM = bin2int(hex2bin($modulus)); $intResult = powmod($intMessage, $intE, $intM); $hexResult = bin2hex(int2bin($intResult)); return $hexResult; } function verifySigature($message, $sign, $exponent, $modulus){ $intSign = bin2int(hex2bin($sign)); $intExponent = bin2int(hex2bin($exponent)); $intModulus = bin2int(hex2bin($modulus)); $intResult = powmod($intSign, $intExponent, $intModulus); $hexResult = bin2hex(int2bin($intResult)); $md5Message = md5($message); if ($md5Message == substr($hexResult, -32)) { return "1"; } else return "0"; } function hex2bin($hexdata){ for ($i=0;$i<strlen($hexdata);$i+=2) { $bindata=chr(hexdec(substr($hexdata,$i,2))).$bindata; } return $bindata; } function bin2int($str){ $result = '0'; $n = strlen($str); do { $result = bcadd(bcmul($result, '256'), ord($str{--$n})); } while ($n > 0); return $result; } function int2bin($num){ $result = ''; do { $result= chr(bcmod($num, '256')).$result; $num = bcdiv($num, '256'); } while (bccomp($num, '0')); return $result; } function powmod($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; } ?>