Web Service中返回错误

I have been having a hell of a time trying to debug this. I am running out of ideas. I have the following simple PHP code.

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

Unfortunately every time I try to run this I keep getting an problem with XML request. Here is the request.

$txnRequest = "<?xml version=\"1.0\" encoding=\"UTF-8\"?>
";
                $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\">
";
                $txnRequest .= "<merchantAccount>
";
                $txnRequest .= "<accountNum>".$account."</accountNum>
";
                $txnRequest .= "<storeID>".$merchantId."</storeID>
";
                $txnRequest .= "<storePwd>".$merchantPwd."</storePwd>
";
                $txnRequest .= "</merchantAccount>
";
                $txnRequest .= "<merchantRefNum>".$merchantRefNum."</merchantRefNum>
";
                $txnRequest .= "<amount>".$amount."</amount>
";
                $txnRequest .= "<card>
";
                $txnRequest .= "<cardNum>".$cardNum."</cardNum>
";
                $txnRequest .= "<cardExpiry>
<month>".$eMonth."</month>
<year>".$eYear."</year>
</cardExpiry>
";
                $txnRequest .= "<cardType>".$cardType."</cardType>
";
                $txnRequest .= "<cvdIndicator>".$cvdIndicator."</cvdIndicator>
";
                $txnRequest .= "<cvd>".$cvd."</cvd>
";
                $txnRequest .= "</card>
";
                $txnRequest .= "<billingDetails>
";
                $txnRequest .= "<cardPayMethod>WEB</cardPayMethod>
";
                $txnRequest .= "<firstName>".$firstName."</firstName>
";
                $txnRequest .= "<lastName>".$lastName."</lastName>
";
                $txnRequest .= "<street>".$bStreet."</street>
";
                $txnRequest .= "<city>".$bCity."</city>
";
                $txnRequest .= "<state>".$bState."</state>
";
                $txnRequest .= "<country>".$bCountry."</country>
";
                $txnRequest .= "<zip>".$bZip."</zip>
";
                $txnRequest .= "<phone>".$bPhone."</phone>
";
                $txnRequest .= "<email>".$bEmail."</email>
";
                $txnRequest .= "</billingDetails>
";
                $txnRequest .= "</ccAuthRequestV1>";

Can anyone provide some insight as to what is not encoded properly?

@aynber is correct, it looks like you are not encoding the correct part of your request.

I believe the correct way of doing this would be like this.

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

Hope that this helps.

I think @Steve is on the right track. Perhaps you meant urlencode($txnRequest))

Also, validate your xml before sending it out.