예제 #1
0
 public function genSignature($aMerchantNo)
 {
     $tRequestMessage = null;
     try {
         $this->iLogWriter = new LogWriter();
         $this->iLogWriter->logNewLine("TrustPayClient V3.0.0 交易开始==========================");
         MerchantConfig::getLogWriterObject($this->iLogWriter);
         //0、检查传入参数是否合法
         if ($aMerchantNo <= 0 || $aMerchantNo > MerchantConfig::getMerchantNum()) {
             throw new TrxException(TrxException::TRX_EXC_CODE_1008, TrxException::TRX_EXC_MSG_1008, '配置文件中商户数为' . MerchantConfig::getMerchantNum() . ", 但是请求指定的商户配置编号为{$aMerchantNo} !");
         }
         //1、检查交易请求是否合法
         $this->iLogWriter->logNewLine('检查交易请求是否合法:');
         $this->checkRequest();
         $this->iLogWriter->log('正确');
         //2、取得交易报文
         $tRequestMessage = $this->getRequestMessage();
         //3、组成完整交易报文
         $this->iLogWriter->log("完整交易报文:");
         $tRequestMessage = $this->composeRequestMessage($aMerchantNo, $tRequestMessage);
         $this->iLogWriter->log($tRequestMessage);
         //4、对交易报文进行签名
         $tRequestMessage = MerchantConfig::signMessage($aMerchantNo, $tRequestMessage);
         $this->iLogWriter->log("签名后的完整报文:");
         $this->iLogWriter->log($tRequestMessage);
         $tRequestMessage = str_replace('"', "&quot;", $tRequestMessage);
     } catch (TrxException $e) {
         if ($this->iLogWriter != null) {
             $this->iLogWriter->logNewLine('错误代码:[' . $e->getCode() . ']    错误信息:[' . $e->getMessage() . ']');
         }
         throw new TrxExCeption($e->getCode(), $e->getMessage() . " - " . $e->getDetailMessage());
     } catch (Exception $e) {
         if ($this->iLogWriter != null) {
             $this->iLogWriter->logNewLine('错误代码:[' . TrxException::TRX_EXC_CODE_1999 . ']    错误信息:[' . TrxException::TRX_EXC_MSG_1999 . ' - ' . $e->getMessage() . ']');
         }
         throw new TrxExCeption(rxException::TRX_EXC_CODE_1999, TrxException::TRX_EXC_MSG_1999 . ' - ' . $e->getMessage());
     }
     if ($this->iLogWriter != null) {
         $this->iLogWriter->logNewLine("交易结束==================================================\n\n\n\n");
         $this->iLogWriter->closeWriter(MerchantConfig::getTrxLogFile());
     }
     return $tRequestMessage;
 }