Esempio n. 1
0
 function toSubmit($payment)
 {
     $merId = $this->getConf($payment["M_OrderId"], 'member_id');
     $keyfile = $this->getConf($payment['M_OrderId'], 'udpay');
     $charset = $this->system->loadModel('utility/charset');
     $ordAmount = floor($payment["M_Amount"] * 100);
     $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 (file_exists(dirname(__FILE__) . "/../../home/upload/udpay/" . $keyfile)) {
         $arr_key = file(dirname(__FILE__) . "/../../home/upload/udpay/" . $keyfile);
     } elseif (file_exists(dirname(__FILE__) . "/../../cert/udpay/" . $keyfile)) {
         $arr_key = file(dirname(__FILE__) . "/../../cert/udpay/" . $keyfile);
     } else {
         echo '<br><br>read key file error!';
         $this->_succ = true;
         exit;
     }
     preg_match("/=([^=]*)/", trim($arr_key[2]), $private);
     $privateModulus = $private[1];
     preg_match("/=([^=]*)/", trim($arr_key[3]), $private);
     $privateExponent = $private[1];
     $testRsaDecrypt = generateSigature($msg, $privateExponent, $privateModulus);
     $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;
 }
Esempio n. 2
0
 function callback($in, &$paymentId, &$money, &$message, &$tradeno)
 {
     $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"表示失败
     $comment = trim($in['comment']);
     $sign = trim($in['sign']);
     $paymentId = $orderId;
     $money = $amount / 100;
     $tradeno = $in['whtFlow'];
     $msg = "txCode=" . $txCode . "&merchantId=" . $merchantId . "&transDate=" . $transDate . "&transFlow=" . $transFlow . "&orderId=" . $orderId . "&curCode=" . $curCode . "&amount=" . $amount . "&orderInfo=" . $orderInfo . "&comment=" . $comment . "&whtFlow=" . $whtFlow . "&success=" . $success . "&errorType=" . $errorType;
     if (!($keyfile = $this->getConf($orderId, 'udpay'))) {
         $message = "read key file error!";
         return PAY_FAILED;
     }
     if (file_exists(dirname(__FILE__) . "/../../home/upload/udpay/" . $keyfile)) {
         $arr_key = file(dirname(__FILE__) . "/../../home/upload/udpay/" . $keyfile);
     } elseif (file_exists(dirname(__FILE__) . "/../../cert/udpay/" . $keyfile)) {
         $arr_key = file(dirname(__FILE__) . "/../../cert/udpay/" . $keyfile);
     }
     $privateModulus = substr(trim($arr_key[2]), 23);
     $privateExponent = substr(trim($arr_key[3]), 24);
     $publicModulus = substr(trim($arr_key[5]), 17);
     $publicExponent = substr(trim($arr_key[6]), 18);
     $testRsaDecrypt = generateSigature($msg, $privateExponent, $privateModulus);
     $verifySigature = verifySigature($msg, $testRsaDecrypt, $publicExponent, $publicModulus);
     if ($sign == $testRsaDecrypt && $verifySigature) {
         switch ($success) {
             //成功支付
             case "Y":
                 $message = "支付成功!";
                 return PAY_SUCCESS;
                 break;
                 //支付失败
             //支付失败
             case "N":
                 $message = '支付失败,请立即与商店管理员联系';
                 return PAY_FAILED;
                 break;
         }
     } else {
         $message = '签名认证失败,请立即与商店管理员联系';
         return PAY_ERROR;
     }
 }