示例#1
0
 public function init($aMessage)
 {
     $this->iLogWriter = new LogWriter();
     try {
         $this->iLogWriter->logNewLine("TrustPayClient V3.0.0 交易开始==========================");
         $this->iLogWriter->logNewLine("接收到的结果通知:\n[" . $aMessage . "]");
         //1、还原经过base64编码的信息
         $tMessage = base64_decode($aMessage);
         $this->iLogWriter->logNewLine("经过Base64解码后的结果通知:\n[" . iconv("GB2312", "UTF-8", $tMessage) . "]");
         //2、取得经过签名验证的报文
         $this->iLogWriter->logNewLine("验证支付结果通知的签名:");
         MerchantConfig::verifySignXML($tMessage);
         $this->iLogWriter->logNewLine("验证通过!\n");
         $tResponse = new TrxResponse($tMessage);
     } catch (TrxException $e) {
         $tResponse = new TrxResponse();
         if ($this->iLogWriter != null) {
             $this->iLogWriter->logNewLine('错误代码:[' . $e->getCode() . ']    错误信息:[' . $e->getMessage() . " - " . $e->getDetailMessage() . ']');
         }
         $tResponse->initWithCodeMsg($e->getCode(), $e->getMessage());
     } catch (Exception $e) {
         $tResponse = new TrxResponse($tMessage);
         if ($this->iLogWriter != null) {
             $this->iLogWriter->logNewLine('错误代码:[' . TrxException::TRX_EXC_CODE_199 . ']    错误信息:[' . $e->getMessage() . ']');
         }
         $tResponse->initWithCodeMsg(TrxException::TRX_EXC_CODE_199, $e->getMessage());
     }
     if ($this->iLogWriter != null) {
         $this->iLogWriter->logNewLine("交易结束==================================================\n\n\n\n");
         $this->iLogWriter->closeWriter(MerchantConfig::getTrxLogFile());
     }
     return $tResponse;
 }
示例#2
0
//3、生成支付请求对象
$tRequest->request["PaymentType"] = $_POST['PaymentType'];
//设定支付类型
$tRequest->request["PaymentLinkType"] = $_POST['PaymentLinkType'];
//设定支付接入方式
if ($_POST['PaymentType'] === "6" && $_POST['PaymentLinkType'] === "2") {
    $tRequest->request["UnionPayLinkType"] = $_POST['UnionPayLinkType'];
    //当支付类型为6,支付接入方式为2的条件满足时,需要设置银联跨行移动支付接入方式
}
$tRequest->request["ReceiveAccount"] = $_POST['ReceiveAccount'];
//设定收款方账号
$tRequest->request["ReceiveAccName"] = $_POST['ReceiveAccName'];
//设定收款方户名
$tRequest->request["NotifyType"] = $_POST['NotifyType'];
//设定通知方式
$tRequest->request["ResultNotifyURL"] = $_POST['ResultNotifyURL'];
//设定通知URL地址
$tRequest->request["MerchantRemarks"] = $_POST['MerchantRemarks'];
//设定附言
$tRequest->request["IsBreakAccount"] = $_POST['IsBreakAccount'];
//设定交易是否分账
$tRequest->request["SplitAccTemplate"] = $_POST['SplitAccTemplate'];
//分账模版编号
try {
    $tSignature = $tRequest->genSignature(1);
    $sTrustPayIETrxURL = MerchantConfig::getTrustPayIETrxURL();
    $sErrorUrl = MerchantConfig::getMerchantErrorURL();
    $_ResponseString = "<HTML>\r\n<HEAD><TITLE>农行网上支付平台-商户接口范例-支付请求</TITLE></HEAD>\r\n<BODY BGCOLOR='#FFFFFF' TEXT='#000000' LINK='#0000FF' VLINK='#0000FF' ALINK='#FF0000'>\r\n<CENTER>支付请求<br><form name=\"form2\" method=\"post\" action=\"" . $sTrustPayIETrxURL . "\"> \r\n" . "<input type=\"hidden\" name=\"MSG\" value=\"" . $tSignature . "\"> \r\n" . "<input type=\"hidden\" name=\"errorPage\" value=\"" . $sErrorUrl . "\"> \r\n" . "<input type=\"submit\" value=\"提交\"></form><br/> \r\n" . "<a href='MerchantPaymentIE.aspx'>回商户首页</a> \r\n\r\n</BODY></HTML>";
    print $_ResponseString;
} catch (TrxExCeption $ex) {
}
示例#3
0
 /**
  * @return array
  */
 private function transformObject2Array()
 {
     $this->internalArray = array();
     $this->internalArray['MERCHANT'] = $this->merchantConfig->getMerchantCode();
     $this->internalArray['ORDER_REF'] = $this->order->getOrderRef();
     $this->internalArray['ORDER_DATE'] = $this->order->getOrderDate();
     $cnt = 0;
     /**
      * @var Product $product
      */
     foreach ($this->order->getProducts() as $product) {
         $this->internalArray['ORDER_PNAME'][$cnt] = $product->getName();
         $this->internalArray['ORDER_PGROUP'][$cnt] = $product->getProductGroup();
         $this->internalArray['ORDER_PCODE'][$cnt] = $product->getCode();
         $this->internalArray['ORDER_PINFO'][$cnt] = $product->getInfo();
         $this->internalArray['ORDER_PRICE'][$cnt] = $product->getPrice();
         $this->internalArray['ORDER_QTY'][$cnt] = $product->getQuantity();
         $this->internalArray['ORDER_MPLACE_MERCHANT'][$cnt] = $product->getMarketPlaceMerchantCode();
         $this->internalArray['ORDER_VER'][$cnt] = $product->getProductVersion();
         $cnt++;
     }
     $this->internalArray['ORDER_SHIPPING'] = $this->order->getShippingCost();
     $this->internalArray['PRICES_CURRENCY'] = $this->order->getCurrency();
     $this->internalArray['DISCOUNT'] = $this->order->getDiscount();
     $this->internalArray['PAY_METHOD'] = $this->order->getPayMethod();
     if (!is_null($this->card) && is_null($this->cardToken)) {
         $this->internalArray['CC_NUMBER'] = $this->card->getCardNumber();
         $this->internalArray['EXP_MONTH'] = $this->card->getCardExpirationMonth();
         $this->internalArray['EXP_YEAR'] = $this->card->getCardExpirationYear();
         $this->internalArray['CC_CVV'] = $this->card->getCardCVV();
         $this->internalArray['CC_OWNER'] = $this->card->getCardOwnerName();
         if ($this->card->isEnableTokenCreation()) {
             $this->internalArray['LU_ENABLE_TOKEN'] = '1';
         }
     }
     $this->internalArray['SELECTED_INSTALLMENTS_NUMBER'] = $this->order->getInstallmentsNumber();
     $this->internalArray['CARD_PROGRAM_NAME'] = $this->order->getCardProgramName();
     if (is_null($this->card) && !is_null($this->cardToken)) {
         $this->internalArray['CC_TOKEN'] = $this->cardToken->getToken();
         if ($this->cardToken->hasCvv()) {
             $this->internalArray['CC_CVV'] = $this->cardToken->getCvv();
         }
     }
     $this->internalArray['BACK_REF'] = $this->order->getBackRef();
     $this->internalArray['ALIAS'] = $this->order->getAlias();
     if (!empty($this->user)) {
         $this->internalArray['CLIENT_IP'] = $this->user->getUserIPAddress();
         $this->internalArray['CLIENT_TIME'] = $this->user->getClientTime();
     }
     $this->internalArray['BILL_LNAME'] = $this->billingData->getLastName();
     $this->internalArray['BILL_FNAME'] = $this->billingData->getFirstName();
     $this->internalArray['BILL_CISERIAL'] = $this->billingData->getIdentityCardSeries();
     $this->internalArray['BILL_CINUMBER'] = $this->billingData->getIdentityCardNumber();
     $this->internalArray['BILL_CIISSUER'] = $this->billingData->getIdentityCardIssuer();
     $this->internalArray['BILL_CNP'] = $this->billingData->getPersonalNumericCode();
     $this->internalArray['BILL_COMPANY'] = $this->billingData->getCompany();
     $this->internalArray['BILL_FISCALCODE'] = $this->billingData->getCompanyFiscalCode();
     $this->internalArray['BILL_REGNUMBER'] = $this->billingData->getCompanyRegistrationNumber();
     $this->internalArray['BILL_BANK'] = $this->billingData->getCompanyBank();
     $this->internalArray['BILL_BANKACCOUNT'] = $this->billingData->getCompanyBankAccountNumber();
     $this->internalArray['BILL_EMAIL'] = $this->billingData->getEmail();
     $this->internalArray['BILL_PHONE'] = $this->billingData->getPhoneNumber();
     $this->internalArray['BILL_FAX'] = $this->billingData->getFaxNumber();
     $this->internalArray['BILL_ADDRESS'] = $this->billingData->getAddressLine1();
     $this->internalArray['BILL_ADDRESS2'] = $this->billingData->getAddressLine2();
     $this->internalArray['BILL_ZIPCODE'] = $this->billingData->getZipCode();
     $this->internalArray['BILL_CITY'] = $this->billingData->getCity();
     $this->internalArray['BILL_STATE'] = $this->billingData->getState();
     $this->internalArray['BILL_COUNTRYCODE'] = $this->billingData->getCountryCode();
     if (!empty($this->deliveryData)) {
         $this->internalArray['DELIVERY_LNAME'] = $this->deliveryData->getLastName();
         $this->internalArray['DELIVERY_FNAME'] = $this->deliveryData->getFirstName();
         $this->internalArray['DELIVERY_COMPANY'] = $this->deliveryData->getCompany();
         $this->internalArray['DELIVERY_PHONE'] = $this->deliveryData->getPhoneNumber();
         $this->internalArray['DELIVERY_ADDRESS'] = $this->deliveryData->getAddressLine1();
         $this->internalArray['DELIVERY_ADDRESS2'] = $this->deliveryData->getAddressLine2();
         $this->internalArray['DELIVERY_ZIPCODE'] = $this->deliveryData->getZipCode();
         $this->internalArray['DELIVERY_CITY'] = $this->deliveryData->getState();
         $this->internalArray['DELIVERY_STATE'] = $this->deliveryData->getState();
         $this->internalArray['DELIVERY_COUNTRYCODE'] = $this->deliveryData->getCountryCode();
         $this->internalArray['DELIVERY_EMAIL'] = $this->deliveryData->getEmail();
     }
     $this->internalArray['CC_NUMBER_RECIPIENT'] = $this->order->getCcNumberRecipient();
     $this->internalArray['USE_LOYALTY_POINTS'] = $this->order->getUseLoyaltyPoints();
     $this->internalArray['LOYALTY_POINTS_AMOUNT'] = $this->order->getLoyaltyPointsAmount();
     $this->internalArray['CAMPAIGN_TYPE'] = $this->order->getCampaignType();
     if (is_array($this->order->getCustomParams())) {
         foreach ($this->order->getCustomParams() as $paramName => $paramValue) {
             $this->internalArray[$paramName] = $paramValue;
         }
     }
     ksort($this->internalArray);
     return $this->internalArray;
 }
示例#4
0
 private function sendMessage($aMessage)
 {
     //组成<MSG>段
     $tMessage = strval($aMessage);
     $this->iLogWriter->logNewLine("提交网上支付平台的报文:\n{$tMessage}");
     //生成URL
     $tURL = MerchantConfig::getTrustPayConnectMethod() . '://' . MerchantConfig::getTrustPayServerName();
     if (MerchantConfig::getTrustPayConnectMethod() == 'https' && MerchantConfig::getTrustPayServerPort() != 443 || MerchantConfig::getTrustPayConnectMethod() == 'http' && MerchantConfig::getTrustPayServerPort() != 80) {
         $tURL .= ':' . strval(MerchantConfig::getTrustPayServerPort());
     }
     $tURL .= MerchantConfig::getTrustPayTrxURL();
     $this->iLogWriter->logNewLine("网上支付平台URL:[{$tURL}] ");
     //生成报文
     $this->iLogWriter->logNewLine('提交交易报文:');
     $this->iLogWriter->logNewLine($tMessage);
     $opts = array('http' => array('method' => 'POST', 'user_agent' => 'TrustPayClient V3.0.0', 'protocol_version' => 1.0, 'header' => array('Content-Type: text/html', 'Accept: */*'), 'content' => $tMessage), 'ssl' => array('verify_peer' => false));
     $context = stream_context_create($opts);
     $tResponseMessage = file_get_contents($tURL, false, $context);
     if (!$tResponseMessage) {
         throw new TrxException(TrxException::TRX_EXC_CODE_1202, TrxException::TRX_EXC_MSG_1202);
     }
     $this->iLogWriter->logNewLine('返回报文:');
     $this->iLogWriter->log('\\n' . iconv("GB2312", "UTF-8", $tResponseMessage));
     $tTrxResponse = new Json($tResponseMessage);
     if (!$tTrxResponse) {
         throw new TrxException(TrxException::TRX_EXC_CODE_1205, TrxException::TRX_EXC_MSG_1205, '返回报文为空!');
     }
     return $tTrxResponse;
 }
示例#5
0
 private static function bindMerchantCertificateByFile()
 {
     $tMerchantCertFiles = self::getParameterByName('MerchantCertFile');
     $tMerchantCertPasswords = self::getParameterByName('MerchantCertPassword');
     $tMerchantCertFileArray = array_filter(array_map('trim', explode(',', $tMerchantCertFiles, 100)));
     $tMerchantCertPasswordArray = array_filter(array_map('trim', explode(',', $tMerchantCertPasswords, 100)));
     if (self::$iMerchantNum != count($tMerchantCertFileArray) || self::$iMerchantNum != count($tMerchantCertPasswordArray)) {
         throw new TrxException(TrxException::TRX_EXC_CODE_1007, TrxException::TRX_EXC_MSG_1007);
     }
     self::$iMerchantCertificates = array();
     self::$iMerchantKeys = array();
     for ($i = 0; $i < self::$iMerchantNum; $i++) {
         //1、读取证书
         $tCertificate = array();
         if (openssl_pkcs12_read(file_get_contents($tMerchantCertFileArray[$i]), $tCertificate, $tMerchantCertPasswordArray[$i])) {
             //2、验证证书是否在有效期内
             $cer = openssl_x509_parse($tCertificate['cert']);
             $t = time();
             if ($t < $cer['validFrom_time_t'] || $t > $cer['validTo_time_t']) {
                 throw new TrxException(TrxException::TRX_EXC_CODE_1005, TrxException::TRX_EXC_MSG_1005);
             }
             self::$iMerchantCertificates[] = $tCertificate;
             //3、取得密钥
             $pkey = openssl_pkey_get_private($tCertificate['pkey']);
             if ($pkey) {
                 self::$iMerchantKeys[] = $pkey;
             } else {
                 echo TrxException::TRX_EXC_CODE_1003 . TrxException::TRX_EXC_MSG_1003 . "无法生成私钥证书对象!";
                 self::$iLogWriter->logNewLine(TrxException::TRX_EXC_CODE_1003 . TrxException::TRX_EXC_MSG_1003 . "无法生成私钥证书对象!");
             }
         } else {
             echo TrxException::TRX_EXC_CODE_1002 . TrxException::TRX_EXC_MSG_1002 . '[' . $tMerchantCertFileArray[$i] . "]!";
             self::$iLogWriter->logNewLine(TrxException::TRX_EXC_CODE_1003 . TrxException::TRX_EXC_MSG_1003 . "无法生成私钥证书对象!");
         }
     }
 }