Непонятная ситуация с CWebServiceAction

Общие вопросы по использованию фреймворка. Если не знаете как что-то сделать и это про Yii, вам сюда.
Ответить
poohbinar
Сообщения: 28
Зарегистрирован: 2012.12.26, 16:58

Непонятная ситуация с CWebServiceAction

Сообщение poohbinar »

Проблема заключается в следующем:
public function getMerchantInfo($hzParam)
если убрать аргумент $hzParam, естественно подправим phpDoc, сервис выдает ошибку

Код: Выделить всё

SoapFault Object
(
    [message:protected] => Error cannot find parameter
Зачем нужен этот параметр? Если его возвращаешь то выдает эксепшн Could not open service!

Сервер

Код: Выделить всё

<?php
class SoapController extends Api
{
    public function actions()
    {
        return array(
            'wsdl'=>array(
                'class'=>'CWebServiceAction',
                // Use classMap for complex data types
                'classMap'=>array(
                ),
            ),
        );
    }

    /**
     * @param null $auth
     * @throws SoapFault
     */
    public function authHeader($auth = null)
    {
        $this->merchantId = intval($auth->merchantId);
        $this->secretHash = $auth->secretHash;

        $this->merchantInfo = Merchant::model()->getMerchantById($this->merchantId);

        if($auth->secretHash != $this->cryptSecretKey('XXXXXXXX')){
            throw new SoapFault("Server", "Incorrect key");
        }
    }

    /**
     * @param array
     * @return array
     * @soap
     */
    public function getMerchantInfo($hzParam)
    {        
        return $this->filterMerchantInfo();
    }
}
Клиент:

Код: Выделить всё

try {
            $client=new SoapClient($this->wsdl, array('cache_wsdl' => 0, 'exceptions' => 0,
                'trace' => 0
            ));
            // Create the header
            $auth  = new auth($this->merchantId, hash('sha256', md5($this->secret)));
            $header = new SoapHeader($this->wsdl, 'authHeader', $auth, false);
            $client->__setSoapHeaders($header);

            $soapRes = $client->__soapCall("getMerchantInfo", array('encoding'=>'utf-8'));
            if (! $soapRes)
                throw new Exception("Could not open service!");
        }
        catch (Exception $e) {
            $soapRes = "Error (File: ".$e->getFile().", line ".
                $e->getLine()."): ".$e->getMessage();
        }

Код: Выделить всё

class auth
{
    public $secretHash;
    public $merchantId;
    public function __construct($merchantId, $hash)
    {
        $this->secretHash = $hash;
        $this->merchantId = $merchantId;
    }
}
poohbinar
Сообщения: 28
Зарегистрирован: 2012.12.26, 16:58

Re: Непонятная ситуация с CWebServiceAction

Сообщение poohbinar »

Разобрался!
Ответить