Home  >  Article  >  Backend Development  >  How to call webservice with self-created certificate in php

How to call webservice with self-created certificate in php

angryTom
angryTomforward
2019-10-15 10:02:312763browse

Someone has asked this question. There is little information on this aspect on domestic websites. Let me briefly talk about it here

1. First, use various means to make apache support https.

2. Then use SoapDiscovery.class.php (Baidu, it’s everywhere) to create a webservice

3. Then we can access https://xxx/abc.php?wsdl . Note that this is one-way authentication and does not authenticate the client.

If PHP's soapclient accesses a webservice without SSL encryption, it is too simple. Nothing much to say.

What if it is after SSL?

How to write code

$context = stream_context_create(array(
    ‘ssl’ => array(
        ‘verify_peer’ => false,
        ‘allow_self_signed’ => true     //这一步很重要,代表是否允许自建证书。因为到权威机构申请证书是要钱的
    )
));
$client  = new SoapClient(null, array( 
    ‘location’ => ‘https://xxxx/abc.php?wsdl’,    //这里写你的webservice地址 
    ‘uri’ => ‘urn:czService’,   //你的wsdl文件中会有 targetNamespace 自己找找
    ‘stream_context’ => $context
));
$client->XXX    // 这里尽情的执行你的方法吧

For more PHP related knowledge, please visit PHP Chinese website!

The above is the detailed content of How to call webservice with self-created certificate in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:www.hishenyi.com. If there is any infringement, please contact admin@php.cn delete