1

我一直在尝试调试它。我的想法不多了。我有以下简单的 PHP 代码。

$url = "https://webservices.test.optimalpayments.com/creditcardWS/CreditCardServlet/v1";          
                $ch = curl_init();
                curl_setopt($ch, CURLOPT_POST,1);
                curl_setopt($ch, CURLOPT_POSTFIELDS,"&txnMode=".$txnMode."&txnRequest=".urlencode($ch));
                curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
                curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
                $result = curl_exec($ch);

不幸的是,每次我尝试运行它时,我都会遇到 XML 请求的问题。这是请求。

$txnRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>\n";
                $txnRequest .= "<ccAuthRequestV1 xmlns=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://www.optimalpayments.com/creditcard/xmlschema/v1\">\n";
                $txnRequest .= "<merchantAccount>\n";
                $txnRequest .= "<accountNum>".$account."</accountNum>\n";
                $txnRequest .= "<storeID>".$merchantId."</storeID>\n";
                $txnRequest .= "<storePwd>".$merchantPwd."</storePwd>\n";
                $txnRequest .= "</merchantAccount>\n";
                $txnRequest .= "<merchantRefNum>".$merchantRefNum."</merchantRefNum>\n";
                $txnRequest .= "<amount>".$amount."</amount>\n";
                $txnRequest .= "<card>\n";
                $txnRequest .= "<cardNum>".$cardNum."</cardNum>\n";
                $txnRequest .= "<cardExpiry>\n<month>".$eMonth."</month>\n<year>".$eYear."</year>\n</cardExpiry>\n";
                $txnRequest .= "<cardType>".$cardType."</cardType>\n";
                $txnRequest .= "<cvdIndicator>".$cvdIndicator."</cvdIndicator>\n";
                $txnRequest .= "<cvd>".$cvd."</cvd>\n";
                $txnRequest .= "</card>\n";
                $txnRequest .= "<billingDetails>\n";
                $txnRequest .= "<cardPayMethod>WEB</cardPayMethod>\n";
                $txnRequest .= "<firstName>".$firstName."</firstName>\n";
                $txnRequest .= "<lastName>".$lastName."</lastName>\n";
                $txnRequest .= "<street>".$bStreet."</street>\n";
                $txnRequest .= "<city>".$bCity."</city>\n";
                $txnRequest .= "<state>".$bState."</state>\n";
                $txnRequest .= "<country>".$bCountry."</country>\n";
                $txnRequest .= "<zip>".$bZip."</zip>\n";
                $txnRequest .= "<phone>".$bPhone."</phone>\n";
                $txnRequest .= "<email>".$bEmail."</email>\n";
                $txnRequest .= "</billingDetails>\n";
                $txnRequest .= "</ccAuthRequestV1>";

任何人都可以提供一些关于没有正确编码的见解吗?

4

2 回答 2

1

@aynber 是正确的,看起来您没有对请求的正确部分进行编码。

我相信这样做的正确方法是这样的。

    $url = "https://webservices.test.optimalpayments.com/creditcardWS/CreditCardServlet/v1";           
    $ch = curl_init();
    curl_setopt($ch, CURLOPT_POST,1);
    curl_setopt($ch, CURLOPT_POSTFIELDS,"&txnMode=".$txnMode."&txnRequest=".urlencode($txnRequest));
    curl_setopt($ch, CURLOPT_URL,$url);
    curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 2);
    curl_setopt($ch, CURLOPT_RETURNTRANSFER,1);
    curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, FALSE);

    $result = curl_exec($ch); 

希望这会有所帮助。

于 2016-11-29T12:32:31.550 回答
-2

我认为@Steve 是在正确的轨道上。也许你的意思是 urlencode($txnRequest))

此外,在发送之前验证您的 xml。

于 2016-11-28T22:23:49.020 回答