www.gusucode.com > ShopEx481 & PHPWind 整合版码程序 > plugins/payment/pay.udpay.php
<?php require('paymentPlugin.php'); class pay_udpay extends paymentPlugin{ var $name = '网汇通在线支付';//网汇通在线支付 var $logo = 'UDPAY'; var $version = 20070902; var $charset = 'gb2312'; var $submitUrl = 'https://www.udpay.com.cn/gateway/transForward.jsp'; // var $submitButton = 'http://img.alipay.com/pimg/button_alipaybutton_o_a.gif'; ##需要完善的地方 var $supportCurrency = array("CNY"=>"156"); var $supportArea = array("AREA_CNY"); var $desc = '网汇通在线支付'; var $orderby = 27; function toSubmit($payment){ $merId = $this->getConf($payment["M_OrderId"], 'member_id'); $ikey = $this->getConf($payment["M_OrderId"], 'PrivateKey'); $ordAmount = floor($payment["M_Amount"] * 100); //$msg = "txCode=TP001&merchantId=".$merId."&transDate=".date("Ymd",$order->M_Time) //."&transFlow=".$order->M_OrderNO."&orderId=".$order->M_OrderId."&curCode=156&amount=".$ordAmount //."&orderInfo=".$this->getConf('system.shopname')."&comment=&merURL=".$this->callbackUrl."&interfaceType=5"; $msg = "txCode=TP001&merchantId=".$merId."&transDate=".date("Ymd",$payment["M_Time"]) ."&transFlow=".$payment["M_OrderNO"]."&orderId=".$payment["M_OrderId"]."&curCode=156&amount=".$ordAmount ."&orderInfo=".$this->getConf('system.shopname')."&comment=&merURL=".$this->callbackUrl."&interfaceType=5"; if (!$this->getConf($payment["M_OrderId"], 'udpay')){ echo("read key file error!"); exit; } $arr_key = file($this->getConf($payment["M_OrderId"], 'udpay')); $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); $testRsaDecrypt = $this->generateSigature($msg, $privateExponent, $privateModulus); // $verifySigature = $this->verifySigature($msg, $testRsaDecrypt, $publicExponent, $publicModulus); $return["txCode"] = "TP001"; $return["merchantId"] = $merId; $return["transDate"] = date("Ymd",$payment["M_Time"]);//date("Ymd",$order->M_Time); $return["transFlow"] = $payment["M_OrderNO"];//$order->M_OrderNO; $return["orderId"] = $payment["M_OrderId"];//$order->M_OrderId; $return["curCode"] = "156"; $return["amount"] = $ordAmount; $return["orderInfo"] = $this->getConf('system.shopname'); $return["comment"] = ""; $return["interfaceType"] = "5"; $return["sign"] = $testRsaDecrypt; $return["merURL"] = $this->callbackUrl; return $return; } function callback($in,&$paymentId,&$money,&$message){ $txCode = trim($in['?txCode']); //商家ID $merchantId = trim($in['merchantId']); //商家ID $transDate = trim($in['transDate']); //交易日期 $transFlow = trim($in['transFlow']); //交易号 $orderId = trim($in['orderId']); //交易号 $curCode = trim($in['curCode']); //交易金额 $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']); $paymentId = $orderId; $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')){ $message = "read key file error!"; return PAY_FAILED; } $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 = $this->verifySigature($msg, $sign, $privateExponent, $privateModulus); if ($verifySigature == 0){ switch ($success){ //成功支付 case "Y": return PAY_SUCCESS; break; //支付失败 case "N": $message = '支付失败,请立即与商店管理员联系'; return PAY_FAILED; break; } }else{ $message = '签名认证失败,请立即与商店管理员联系'; return PAY_ERROR; } //mt_srand((double)microtime()*1000000); //$randval = mt_rand(10000000,99999999); //$signstr = substr(hexdec(md5($tmp_orderno.$state.mktime().$randval)), 0, 10); //$Order->updateOrderSign($tmp_orderno, $signstr); } function getfields(){ return array( 'member_id'=>array( 'label'=>'客户号', 'type'=>'string' ), 'PrivateKey'=>array( 'label'=>'私钥', 'type'=>'string' ), 'udpay'=>array( 'label'=>'私钥文件', 'type'=>'file' ) ); } } ?>