douyanpeng0748 2016-11-28 22:04
浏览 35
已采纳

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?

  • 写回答

2条回答 默认 最新

  • dr637349 2016-11-29 12:32
    关注

    @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.

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论
查看更多回答(1条)

报告相同问题?

悬赏问题

  • ¥15 真我手机蓝牙传输进度消息被关闭了,怎么打开?(关键词-消息通知)
  • ¥15 下图接收小电路,谁知道原理
  • ¥15 装 pytorch 的时候出了好多问题,遇到这种情况怎么处理?
  • ¥20 IOS游览器某宝手机网页版自动立即购买JavaScript脚本
  • ¥15 手机接入宽带网线,如何释放宽带全部速度
  • ¥30 关于#r语言#的问题:如何对R语言中mfgarch包中构建的garch-midas模型进行样本内长期波动率预测和样本外长期波动率预测
  • ¥15 ETLCloud 处理json多层级问题
  • ¥15 matlab中使用gurobi时报错
  • ¥15 这个主板怎么能扩出一两个sata口
  • ¥15 不是,这到底错哪儿了😭