简体   繁体   English

带有 wsdl 和 2-way SSL 的 PHP SOAP

[英]PHP SOAP with wsdl and 2-way SSL

This is my first time doing SOAP on PHP (Im a rookie actually), and im stuck in this problem for months.这是我第一次在 PHP 上做 SOAP(实际上我是一个菜鸟),我在这个问题上困了几个月。

https://wstest.oriongateway.com:22837/willani/services/oglws?wsdl

This is the webservice URL, they request 2-way SSL on production, and they have provide me a set of private key and public cert to install on my server.这是 webservice URL,他们在生产中请求 2-way SSL,他们为我提供了一组私钥和公共证书以安装在我的服务器上。

I able to view the URL by install a private key on my browser.我可以通过在浏览器上安装私钥来查看 URL。

At this moment, I've successfully get the respond from webservice by no-way SSL and one-way SSL, but two-way SSL just cant work.此刻,我已经通过无向 SSL 和单向 SSL 成功获得了来自 webservice 的响应,但是双向 SSL 无法正常工作。

Error message when I submit a two-way SSL by SOAP.当我通过 SOAP 提交双向 SSL 时出现错误消息。

Warning: SoapClient::__doRequest(): SSL operation failed with code 1. OpenSSL Error messages: error:14094412:SSL routines:SSL3_READ_BYTES:sslv3 alert bad certificate in /home/loadme/domains/loadme.my/public_html/system/OglWsService_noservice.php on line 124警告:SoapClient::__doRequest():SSL 操作失败,代码为 1。OpenSSL 错误消息:错误:14094412:SSL 例程:SSL3_READ_BYTES:sslv3 警告 /home/loadme/domains/loadme.my/public_html/system/OglWsService_noservice 中的错误证书第 124 行的 .php
Warning: SoapClient::__doRequest(): Failed to enable crypto in /home/loadme/domains/loadme.my/public_html/system/OglWsService_noservice.php on line 124警告:SoapClient::__doRequest():无法在第 124 行的 /home/loadme/domains/loadme.my/public_html/system/OglWsService_noservice.php 中启用加密
Warning: SoapClient::__doRequest(): connect() failed: Unspecified error in /home/loadme/domains/loadme.my/public_html/system/OglWsService_noservice.php on line 124警告:SoapClient::__doRequest():connect() 失败:第 124 行 /home/loadme/domains/loadme.my/public_html/system/OglWsService_noservice.php 中的未指定错误

My SOAP request file我的 SOAP 请求文件

<?php
require_once 'OglWsService.php';

$requestMsg = new RequestMsg;

$requestMsg->amount="1000";
$requestMsg->merchantId="620055";
$requestMsg->operatorId="IBS";
$requestMsg->retTransRef="102182ABCqw1238";
$requestMsg->terminalId="10000102";
$requestMsg->productCode="DIGI";
$requestMsg->transDateTime=date("YmdHis");
$requestMsg->transTraceId = (int)"123212321";


$in0 = new onlinePIN();
$in0->in0=$requestMsg;

$oglWsService = new OglWsService();

$reponseMsg = $oglWsService->onlinePIN($in0);
$arr=get_object_vars($reponseMsg);
print_r($arr);
echo $arr['onlinePINReturn']->transRef;
?>

My Webservice class我的网络服务类

<?php
class RequestMsg {
  public $amount; // string
  public $merchantId; // string
  public $operatorId; // string
  public $orgTransRef; // string
  public $retTransRef; // string
  public $terminalId; // string
  public $productCode; // string
  public $msisdn; // string
  public $transDateTime; // string
  public $transTraceId; // int
  public $customField1; // string
  public $customField2; // string
  public $customField3; // string
  public $customField4; // string
  public $customField5; // string
}

class ResponseMsg {
  public $amount; // string
  public $pin; // string
  public $pinExpiryDate; // string
  public $productCode; // string
  public $responseCode; // string
  public $responseMsg; // string
  public $retTransRef; // string
  public $terminalId; // string
  public $transRef; // string
  public $customField1; // string
  public $customField2; // string
  public $customField3; // string
  public $customField4; // string
  public $customField5; // string
}

class onlinePIN {
  public $in0; // RequestMsg
}

class onlinePINResponse {
  public $onlinePINReturn; // ResponseMsg
}

class onlinePINReversal {
  public $in0; // RequestMsg
}

class onlinePINReversalResponse {
  public $onlinePINReversalReturn; // ResponseMsg
}

class etopup {
  public $in0; // RequestMsg
}

class etopupResponse {
  public $etopupReturn; // ResponseMsg
}

class etopupReversal {
  public $in0; // RequestMsg
}

class etopupReversalResponse {
  public $etopupReversalReturn; // ResponseMsg
}

class networkCheck {
  public $in0; // RequestMsg
}

class networkCheckResponse {
  public $networkCheck; // ResponseMsg
}


/**
 * OglWsService class
 * 
 *  
 * 
 * @author    {author}
 * @copyright {copyright}
 * @package   {package}
 */
class OglWsService extends SoapClient {

  private static $classmap = array(
                                    'RequestMsg' => 'RequestMsg',
                                    'ResponseMsg' => 'ResponseMsg',
                                    'onlinePIN' => 'onlinePIN',
                                    'onlinePINResponse' => 'onlinePINResponse',
                                    'onlinePINReversal' => 'onlinePINReversal',
                                    'onlinePINReversalResponse' => 'onlinePINReversalResponse',
                                    'etopup' => 'etopup',
                                    'etopupResponse' => 'etopupResponse',
                                    'etopupReversal' => 'etopupReversal',
                                    'etopupReversalResponse' => 'etopupReversalResponse',
                                    'networkCheck' => 'networkCheck',
                                    'networkCheckResponse' => 'networkCheckResponse',
                                   );

  public function OglWsService($wsdl = "oglws_ver2_4_doc_literal.wsdl", $options = array()) {
    foreach(self::$classmap as $key => $value) {
      if(!isset($options['classmap'][$key])) {
        $options['classmap'][$key] = $value;
      }
    }
    parent::__construct($wsdl, $options);
  }

  /**
   *  
   *
   * @param onlinePIN $parameters
   * @return onlinePINResponse
   */
  public function onlinePIN(onlinePIN $parameters) {
    return $this->__soapCall('onlinePIN', array($parameters),       array(
            'uri' => 'urn:EPAYIBWS',
            'soapaction' => ''
           )
      );
  }

  /**
   *  
   *
   * @param onlinePINReversal $parameters
   * @return onlinePINReversalResponse
   */
  public function onlinePINReversal(onlinePINReversal $parameters) {
    return $this->__soapCall('onlinePINReversal', array($parameters),       array(
            'uri' => 'urn:EPAYIBWS',
            'soapaction' => ''
           )
      );
  }

  /**
   *  
   *
   * @param etopup $parameters
   * @return etopupResponse
   */
  public function etopup(etopup $parameters) {
    return $this->__soapCall('etopup', array($parameters),       array(
            'uri' => 'urn:EPAYIBWS',
            'soapaction' => ''
           )
      );
  }

  /**
   *  
   *
   * @param etopupReversal $parameters
   * @return etopupReversalResponse
   */
  public function etopupReversal(etopupReversal $parameters) {
    return $this->__soapCall('etopupReversal', array($parameters),       array(
            'uri' => 'urn:EPAYIBWS',
            'soapaction' => ''
           )
      );
  }

  /**
   *  
   *
   * @param networkCheck $parameters
   * @return networkCheckResponse
   */
  public function networkCheck(networkCheck $parameters) {
    return $this->__soapCall('networkCheck', array($parameters),       array(
            'uri' => 'urn:EPAYIBWS',
            'soapaction' => ''
           )
      );
  }

}

?>

My WSDL file我的 WSDL 文件

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions
        targetNamespace="urn:EPAYIBWS"
        xmlns:apachesoap="http://xml.apache.org/xml-soap"
        xmlns:impl="urn:EPAYIBWS"
        xmlns:intf="urn:EPAYIBWS"
        xmlns:tns1="http://schemas.xmlsoap.org/soap/encoding/"
        xmlns:tns2="http://axis.apache.org"
        xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/"
        xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/"
        xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <wsdl:types>
  <schema elementFormDefault="qualified" targetNamespace="urn:EPAYIBWS" xmlns="http://www.w3.org/2001/XMLSchema">
   <complexType name="RequestMsg">
    <sequence>
     <element name="amount" nillable="true" type="tns1:string"/>
     <element name="merchantId" nillable="true" type="tns1:string"/>
     <element name="operatorId" nillable="true" type="tns1:string"/>
     <element name="orgTransRef" nillable="true" type="tns1:string"/>
     <element name="retTransRef" nillable="true" type="tns1:string"/>
     <element name="terminalId" nillable="true" type="tns1:string"/>
     <element name="productCode" nillable="true" type="tns1:string"/>
     <element name="msisdn" nillable="true" type="tns1:string"/>
     <element name="transDateTime" nillable="true" type="tns1:string"/>
     <element name="transTraceId" type="xsd:int"/>
     <element name="customField1" nillable="true" type="tns1:string"/>
     <element name="customField2" nillable="true" type="tns1:string"/>
     <element name="customField3" nillable="true" type="tns1:string"/>
     <element name="customField4" nillable="true" type="tns1:string"/>
     <element name="customField5" nillable="true" type="tns1:string"/>
    </sequence>
   </complexType>
   <complexType name="ResponseMsg">
    <sequence>
     <element name="amount" nillable="true" type="tns1:string"/>
     <element name="pin" nillable="true" type="tns1:string"/>
     <element name="pinExpiryDate" nillable="true" type="tns1:string"/>
     <element name="productCode" nillable="true" type="tns1:string"/>
     <element name="responseCode" nillable="true" type="tns1:string"/>
     <element name="responseMsg" nillable="true" type="tns1:string"/>
     <element name="retTransRef" nillable="true" type="tns1:string"/>
     <element name="terminalId" nillable="true" type="tns1:string"/>
     <element name="transRef" nillable="true" type="tns1:string"/>
     <element maxOccurs="1" minOccurs="0" name="customField1" nillable="true" type="tns1:string"/>
     <element maxOccurs="1" minOccurs="0" name="customField2" nillable="true" type="tns1:string"/>
     <element maxOccurs="1" minOccurs="0" name="customField3" nillable="true" type="tns1:string"/>
     <element maxOccurs="1" minOccurs="0" name="customField4" nillable="true" type="tns1:string"/>
     <element maxOccurs="1" minOccurs="0" name="customField5" nillable="true" type="tns1:string"/>
    </sequence>
   </complexType>
   <element name="fault" type="xsd:anyType"/>

   <element name="onlinePIN">
    <complexType>
     <sequence>
      <element name="in0" type="impl:RequestMsg"/>
     </sequence>
    </complexType>
   </element>
   <element name="onlinePINResponse">
    <complexType>
     <sequence>
      <element name="onlinePINReturn" type="impl:ResponseMsg"/>
     </sequence>
    </complexType>
   </element>
   <element name="onlinePINReversal">
    <complexType>
     <sequence>
      <element name="in0" type="impl:RequestMsg"/>
     </sequence>
    </complexType>
   </element>
   <element name="onlinePINReversalResponse">
    <complexType>
     <sequence>
      <element name="onlinePINReversalReturn" type="impl:ResponseMsg"/>
     </sequence>
    </complexType>
   </element>
   <element name="etopup">
    <complexType>
     <sequence>
      <element name="in0" type="impl:RequestMsg"/>
     </sequence>
    </complexType>
   </element>
   <element name="etopupResponse">
    <complexType>
     <sequence>
      <element name="etopupReturn" type="impl:ResponseMsg"/>
     </sequence>
    </complexType>
   </element>
   <element name="etopupReversal">
    <complexType>
     <sequence>
      <element name="in0" type="impl:RequestMsg"/>
     </sequence>
    </complexType>
   </element>
   <element name="etopupReversalResponse">
    <complexType>
     <sequence>
      <element name="etopupReversalReturn" type="impl:ResponseMsg"/>
     </sequence>
    </complexType>
   </element>
   <element name="networkCheck">
    <complexType>
     <sequence>
      <element name="in0" type="impl:RequestMsg"/>
     </sequence>
    </complexType>
   </element>
   <element name="networkCheckResponse">
    <complexType>
     <sequence>
      <element name="networkCheck" type="impl:ResponseMsg"/>
     </sequence>
    </complexType>
   </element>
  </schema>
 </wsdl:types>
   <wsdl:message name="etopupRequest">
      <wsdl:part element="impl:etopup" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="networkCheckResponse">
      <wsdl:part element="impl:networkCheckResponse" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="etopupReversalRequest">
      <wsdl:part element="impl:etopupReversal" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="etopupResponse">
      <wsdl:part element="impl:etopupResponse" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="networkCheckRequest">
      <wsdl:part element="impl:networkCheck" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="onlinePINReversalResponse">
      <wsdl:part element="impl:onlinePINReversalResponse" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="onlinePINReversalRequest">
      <wsdl:part element="impl:onlinePINReversal" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="onlinePINRequest">
      <wsdl:part element="impl:onlinePIN" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="onlinePINResponse">
      <wsdl:part element="impl:onlinePINResponse" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="etopupReversalResponse">
      <wsdl:part element="impl:etopupReversalResponse" name="parameters"/>
   </wsdl:message>

   <wsdl:message name="ConfigurationException">
      <wsdl:part element="impl:fault" name="fault"/>
   </wsdl:message>

   <wsdl:portType name="oglws">

      <wsdl:operation name="onlinePIN">
         <wsdl:input message="impl:onlinePINRequest" name="onlinePINRequest"/>
         <wsdl:output message="impl:onlinePINResponse" name="onlinePINResponse"/>
         <wsdl:fault message="impl:ConfigurationException" name="ConfigurationException"/>
      </wsdl:operation>

      <wsdl:operation name="onlinePINReversal">
         <wsdl:input message="impl:onlinePINReversalRequest" name="onlinePINReversalRequest"/>
         <wsdl:output message="impl:onlinePINReversalResponse" name="onlinePINReversalResponse"/>
         <wsdl:fault message="impl:ConfigurationException" name="ConfigurationException"/>
      </wsdl:operation>

      <wsdl:operation name="etopup">
         <wsdl:input message="impl:etopupRequest" name="etopupRequest"/>
         <wsdl:output message="impl:etopupResponse" name="etopupResponse"/>
         <wsdl:fault message="impl:ConfigurationException" name="ConfigurationException"/>
      </wsdl:operation>

      <wsdl:operation name="etopupReversal">
         <wsdl:input message="impl:etopupReversalRequest" name="etopupReversalRequest"/>
         <wsdl:output message="impl:etopupReversalResponse" name="etopupReversalResponse"/>
         <wsdl:fault message="impl:ConfigurationException" name="ConfigurationException"/>
      </wsdl:operation>

      <wsdl:operation name="networkCheck">
         <wsdl:input message="impl:networkCheckRequest" name="networkCheckRequest"/>
         <wsdl:output message="impl:networkCheckResponse" name="networkCheckResponse"/>
         <wsdl:fault message="impl:ConfigurationException" name="ConfigurationException"/>
      </wsdl:operation>

   </wsdl:portType>

   <wsdl:binding name="oglwsSoapBinding" type="impl:oglws">
      <wsdlsoap:binding style="document" transport="http://schemas.xmlsoap.org/soap/http"/>

      <wsdl:operation name="onlinePIN">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="onlinePINRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="onlinePINResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

         <wsdl:fault name="ConfigurationException">

            <wsdlsoap:fault name="ConfigurationException" use="literal"/>

         </wsdl:fault>

      </wsdl:operation>

      <wsdl:operation name="onlinePINReversal">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="onlinePINReversalRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="onlinePINReversalResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

         <wsdl:fault name="ConfigurationException">

            <wsdlsoap:fault name="ConfigurationException" use="literal"/>

         </wsdl:fault>

      </wsdl:operation>

      <wsdl:operation name="etopup">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="etopupRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="etopupResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

         <wsdl:fault name="ConfigurationException">

            <wsdlsoap:fault name="ConfigurationException" use="literal"/>

         </wsdl:fault>

      </wsdl:operation>

      <wsdl:operation name="etopupReversal">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="etopupReversalRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="etopupReversalResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

         <wsdl:fault name="ConfigurationException">

            <wsdlsoap:fault name="ConfigurationException" use="literal"/>

         </wsdl:fault>

      </wsdl:operation>

      <wsdl:operation name="networkCheck">

         <wsdlsoap:operation soapAction=""/>

         <wsdl:input name="networkCheckRequest">

            <wsdlsoap:body use="literal"/>

         </wsdl:input>

         <wsdl:output name="networkCheckResponse">

            <wsdlsoap:body use="literal"/>

         </wsdl:output>

         <wsdl:fault name="ConfigurationException">

            <wsdlsoap:fault name="ConfigurationException" use="literal"/>

         </wsdl:fault>

      </wsdl:operation>

   </wsdl:binding>

   <wsdl:service name="OglWsService">

      <wsdl:port binding="impl:oglwsSoapBinding" name="oglws">

         <wsdlsoap:address location="https://wstest.oriongateway.com:22837/willani/services/oglws"/>

      </wsdl:port>

   </wsdl:service>

</wsdl:definitions>

Any comment will be useful for me.任何评论都会对我有用。

you can follow these steps to generate what you need:您可以按照以下步骤生成您需要的内容:

openssl genrsa -out client.key 2048  
openssl req -new -key client.key -out something.p10  
openssl pkcs7 -in file.p7b -inform PEM -out result.pem -print_certsopenssl pkcs12 -export -inkey client.key -in result.pem -name anyName -out finalCert.p12  
keytool -v -importkeystore -srckeystore finalCert.p12 -srcstoretype PKCS12 -destkeystore name.jks -deststoretype JKS  

then you can use .jks file for SOAPUI, .p12 file for browser.那么您可以将 .jks 文件用于 SOAPUI,将 .p12 文件用于浏览器。 I hope this helps.我希望这有帮助。

As i can see your are not creating SoapClient with SSL, I suggest to follow this general exemple :正如我所看到的,您没有使用 SSL 创建 SoapClient,我建议遵循以下一般示例:

$context = stream_context_create(
    array(
        "ssl" => array(
            "verify_peer" => true,
            "cafile" => $certsServeur
        )
    )
);

$client = new SoapClient(
    $wsdl,
    array(
        "trace" => 1,
        "soap_version" => SOAP_1_1
        "local_cert" => $certsClient
        "stream_context" => $context
    )
);

for more details see [here][1]有关更多详细信息,请参阅[此处][1]

Note that注意

$local_cert & certsClient ( FULL_PATH_TO_MY_CERT ) $local_cert & certsClient ( FULL_PATH_TO_MY_CERT )

When the client needs to be verified with a certificate you can use the following.当客户端需要使用证书进行验证时,您可以使用以下方法。 First create the certificates on the server:首先在服务器上创建证书:

openssl req -x509  -days 3650 -newkey rsa:2048 -keyout <cerfificatename>-VZ-private.pem -out <certificatename>-public.pem -nodes

Replace < certificatename > with a name of your own choice.将 <certificatename> 替换为您自己选择的名称。

$context = stream_context_create(
        array(
            "ssl" => array(
                "verify_peer" => true,
                "cafile" => $fullPathToServerCa,
                "local_cert" => $fullPathToLocalPublicCert,
                "local_pk" =>$fullPathToLocalPrivateCert,
            )
        )
    );
$client = new SoapClient(
    $wsdl,
    array(
        "trace" => 1,
        "stream_context" => $context
    )
);

The version with local_cert in the SoapClient was not working for me. SoapClient 中带有 local_cert 的版本对我不起作用。 This one is.这个是。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM