示例#1
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;
 }