2016-11-28 1 views
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>"; 

아무도 제대로 인코딩되지 않은 것에 대한 통찰력을 제공 할 수 있습니까?

+0

'$ txnRequest'를 에코하여 최종 데이터를 검사하십시오. 나는 당신이 그것을 게시하기 전에 XML을 인코딩해야 할 수도 있습니다 같아요. – aynber

+1

'.urlencode ($ ch)'거기서 무슨 일이 일어 났습니까? – Steve

답변

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); 

희망이 도움이됩니다.

-2

@ 스티브가 올바른 방향이라고 생각합니다. 아마도 당신은 urlencode ($ txnRequest)을 의미했습니다.

또한 xml을 전송하기 전에 유효성을 검사하십시오.

+1

이것은 대답이 아닌 주석입니다. –

관련 문제