php 使用soap 协议, client 无法传递参数到server

firethesky
  • 1
新手上路,请多包涵

问题描述

最近在对接马来西亚的移动支付ipay88,ipay88支付平台使用的是soap+xml协议, 这个协议有点难懂,试了很久,都无法用php调试通过,用client 发出请求后,无法收到server的回复。

问题出现的环境背景及自己尝试过哪些方法

背景

开发语言: php
soap库文件: php官方的soap扩展包。
支付接口的调用地址: https://payment.ipay88.com.my/ePayment/WebService/MHGatewayService/GatewayService.svc

尝试过的内容

  1. 平台无法提供任何开发语言的demo,没有代码可以参考。
  2. 可以使用soapUI 来发出请求和返回。在这个工具中,发出请求是成功的。因此可以判断server端是正常工作的。
  3. 客户端尝试使用SoapClient的实例,调用了__getFunctions, 可以得到正常的函数返回值,因此可以判断php的soapclient的构造没有问题.测试结果如下:
request请求
$client = new SoapClient($location,$options);
$client->__getFunctions();
response返回
[
"EntryPageFunctionalityResponse EntryPageFunctionality(EntryPageFunctionality $parameters)",
"EntryPageFunctionalityResponse EntryPageFunctionality(EntryPageFunctionality $parameters)"
]

4.但是调用server端的函数时,失败了,php代码运行超时。我理解是__soapCall的调用参数没有写对,导致服务器接口没有返回导致的。

$result = $client->__soapCall(
                'EntryPageFunctionality',$params,
                [
                    'soapaction'=>'https://www.mobile88.com/IGatewayService/EntryPageFunctionality',
                ]
                );
            echo json_encode($result);

请求失败的原因,目前猜测,有两个可能的原因

  1. 这个支付接口使用的是wsdl文件, 但是这个wsdl下有两个web service, 一个webservice是http协议,还有一个webservice是https协议。我可能调用到了http协议的那个webservice。但是不知道应该如何设置__soapCall方法的参数,来调用到https协议的webservice。
  2. 传递过去的参数中,key值的格式有问题。不是我代码中'requestModelObj'这样的格式,而是其他的形式。

image.png

相关代码

平台给的示例数据

#raw data:
POST https://payment.ipay88.com.my/ePayment/WebService/MHGatewayService/GatewayService.svc HTTP/1.1
Accept-Encoding: gzip,deflate
Content-Type: text/xml;charset=UTF-8
SOAPAction: "https://www.mobile88.com/IGatewayService/EntryPageFunctionality"
Content-Length: 2313
Host: payment.ipay88.com.my
Connection: Keep-Alive
User-Agent: Apache-HttpClient/4.1.1 (java 1.5)

#request data xml:
<soapenv:Envelope xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/" xmlns:mob="https://www.mobile88.com" xmlns:mhp="http://schemas.datacontract.org/2004/07/MHPHGatewayService.Model">
<soapenv:Header/>
<soapenv:Body>
<mob:EntryPageFunctionality>
<mob:requestModelObj>
<mhp:ActionType></mhp:ActionType>
<mhp:Amount>0.01</mhp:Amount>
<mhp:BackendURL></mhp:BackendURL>
<mhp:BarcodeNo>281001023704034671047838</mhp:BarcodeNo>
<mhp:CCCId></mhp:CCCId>
<mhp:CCCOriTokenId></mhp:CCCOriTokenId>
<mhp:CCMonth></mhp:CCMonth>
<mhp:CCName></mhp:CCName>
<mhp:CCNo></mhp:CCNo>
<mhp:CCYear></mhp:CCYear>
<mhp:CVV2></mhp:CVV2>
<mhp:Currency>MYR</mhp:Currency>
<mhp:DiscountedAmount></mhp:DiscountedAmount>
<mhp:MTLogId></mhp:MTLogId>
<mhp:MTVersion></mhp:MTVersion>
<mhp:MerchantCode>M15137</mhp:MerchantCode>
<mhp:PaymentId>0</mhp:PaymentId>
<mhp:ProdDesc>ali</mhp:ProdDesc>
<mhp:PromoCode></mhp:PromoCode>
<mhp:RefNo>alipay129</mhp:RefNo>
<mhp:Remark></mhp:Remark>
<mhp:Signature>50a44ae179468a94b092a7ed90bdfd40927de61c380bc019987d7055ec86259d</mhp:Signature>
<mhp:SignatureType>SHA256</mhp:SignatureType>
<mhp:TerminalID></mhp:TerminalID>
<mhp:TokenId></mhp:TokenId>
<mhp:UserContact>01234567890</mhp:UserContact>
<mhp:UserEmail>ss@email.com</mhp:UserEmail>
<mhp:UserName>SS</mhp:UserName>
<mhp:forexRate></mhp:forexRate>
<mhp:lang>UTF-8</mhp:lang>
<mhp:xfield1></mhp:xfield1>
<mhp:xfield2></mhp:xfield2>
</mob:requestModelObj>
</mob:EntryPageFunctionality>
</soapenv:Body>
</soapenv:Envelope>


​#response data xml:
<s:Envelope xmlns:s="http://schemas.xmlsoap.org/soap/envelope/">
<s:Header>
<ActivityId CorrelationId="16cf0175-1a76-4a82-8881-dd0560c53063" xmlns="http://schemas.microsoft.com/2004/09/ServiceModel/Diagnostics">00000000-0000-0000-0000-000000000000</ActivityId>
</s:Header>
<s:Body>
<EntryPageFunctionalityResponse xmlns="https://www.mobile88.com">
<EntryPageFunctionalityResult xmlns:a="http://schemas.datacontract.org/2004/07/MHPHGatewayService.Model" xmlns:i="http://www.w3.org/2001/XMLSchema-instance">
<a:ActionType/>
<a:Amount>0.01</a:Amount>
<a:AmountBeforeDiscount>0.01</a:AmountBeforeDiscount>
<a:AuthCode i:nil="true"/>
<a:BankMID i:nil="true"/>
<a:BindCardErrDescc i:nil="true"/>
<a:CCName i:nil="true"/>
<a:CCNo i:nil="true"/>
<a:CardType i:nil="true"/>
<a:Currency>MYR</a:Currency>
<a:DCCConversionRate i:nil="true"/>
<a:DCCStatus>0</a:DCCStatus>
<a:Discount>0.00</a:Discount>
<a:ErrDesc i:nil="true"/>
<a:Lang i:nil="true"/>
<a:MerchantCode>M15137</a:MerchantCode>
<a:OriginalAmount i:nil="true"/>
<a:OriginalCurrency i:nil="true"/>
<a:PaymentId>234</a:PaymentId>
<a:PaymentType i:nil="true"/>
<a:QRCode i:nil="true"/>
<a:QRValue i:nil="true"/>
<a:RefNo>alipay129</a:RefNo>
<a:Remark/>
<a:Requery i:nil="true"/>
<a:S_bankname i:nil="true"/>
<a:S_country i:nil="true"/>
<a:SettlementAmount i:nil="true"/>
<a:SettlementCurrency i:nil="true"/>
<a:Signature>de2916cbd8de8833c11febd9cb62f1aa5f6966a21ddf56df088bf1bd02e30dd5</a:Signature>
<a:Status>1</a:Status>
<a:TokenId i:nil="true"/>
<a:TransId>T007920326120</a:TransId>
<a:Xfield1/>
<a:Xfield2/>
</EntryPageFunctionalityResult>
</EntryPageFunctionalityResponse>
</s:Body>
</s:Envelope>

php测试代码

try {
            $location = 'https://payment.ipay88.com.my/ePayment/WebService/MHGatewayService/GatewayService.svc?wsdl';
            $options = array(
                'stream_context' => stream_context_create([
                    'http'=> [
                        'header' => "Accept-Encoding: gzip,deflate\r\n
                                Content-Type: text/xml;charset=UTF-8\r\n
                                Host: payment.ipay88.com.my\r\n
                                Connection: Keep-Alive\r\n
                                user_agent: PHP/SOAP client"
                             ],
                ])
            );

            $client = new SoapClient($location,$options);

            $params = [
                'requestModelObj' => [
                    'ActionType' => '',
                    'Amount' => '1.00',
                    'BackendURL' => '',
                    'BarcodeNo' => '18599882',
                    'CCCId' => '',
                    'CCCOriTokenId' => '',
                    'CCMonth' => '',
                    'CCName' => '',
                    'CCNo' => '',
                    'CCYear' => '',
                    'CVV2' => '',
                    'Currency' => 'MYR',
                    'DiscountedAmount' => '0',
                    'MTLogId' => '',
                    'MTVersion' => '',
                    'MerchantCode' => 'M15137',
                    'PaymentId' => 0,
                    'ProdDesc' => 'Product Service',
                    'PromoCode' => 'Product Service',
                    'RefNo' => 'XS-7357-2633202003123133156',
                    'Remark' => '',
                    'Signature' => 'fea2a5adcfc0298678577e34bf04793527b94e1ea045305ca43e43eaad309bb9',
                    'SignatureType' => 'SHA256',
                    'TerminalID' => '',
                    'TokenId' => '',
                    'UserContact' => '18668067622',
                    'UserEmail' => 'yiming@91laiqian.com',
                    'UserName' => 'sabao',
                    'forexRate' => '',
                    'lang' => 'UTF-8',
                    'xfield1' => '',
                    'xfield2' => '',
                ]
            ];
            $result = $client->__soapCall(
                'EntryPageFunctionality',$params,
                [
                    'soapaction'=>'https://www.mobile88.com/IGatewayService/EntryPageFunctionality',
                ]
                );
            echo json_encode($result);
        } catch (\SoapFault $e) {
            echo $e->getMessage();
        }

你期待的结果是什么?实际看到的错误信息又是什么?

期待结果: response 返回xml格式的字符串。
实际情况: php代码运行超时, 应该是接口迟迟没有返回,导致超时。

评论
阅读 898
撰写回答

登录后参与交流、获取后续更新提醒

宣传栏