I
I
Ivan Khimich2017-12-22 14:33:07
WordPress
Ivan Khimich, 2017-12-22 14:33:07

How to send xml as parameter using php soap?

Colleagues, tell me, please, it is necessary to transfer xml as one of the parameters of the SOAP request (getTariff method).
All methods, including authorization and getting a dictionary, work with a bang (all query parameters are strings), but there is a problem with getTariff. Tell me what to do with the xml parameter, how to pass it correctly?
When making a request with a SOAP action: getTariff the following response:
[ErrorCode] => -20001
[ErrorMessage] => Empty XML file in transformation.
The working class code that is used to make requests to the web service.

class IngosApi { 
  public $soapClient;
  public $token;
        
        // сразу авторизуемся и получаем токен с помощью запроса Login
  public function __construct($apiUser, $apiPassword, $soapWsdlUri) 
  {
    $this->soapClient = new SoapClient($soapWsdlUri, array('trace' => true, 'encoding'=>'UTF-8'));
    
    $requestData = [
      'User' => $apiUser,
      'Password' => $apiPassword
    ];
    $response = $this->soapClient->Login($requestData);
    $this->token = $response->ResponseData->SessionToken;
  }

  // set on cron (every day 05:00)
        // получаем словарь с помощью запроса getDicty
  public function getDicty() 
  {
    $requestData = [
      'SessionToken' => $this->token,
      'Product' => 753518300
    ];
    $response = $this->soapClient->GetDicti($requestData);
    $dictionary = $response->ResponseData->any;
    file_put_contents('dictionaty.xml', $dictionary);
    // insert data шт DB
  }

  public function getTariff() 
  {
        $requestData = [
      'SessionToken' => $this->token,
                        // пока тестируем, получаем просто из файла запрос
      'TariffParameters' => file_get_contents('agreement-test.xml'),
      'NeedList' => 1
    ];
    $response = $this->soapClient->GetTariff($requestData);
    $this->printPre($response);
  }

  public function getSoapClient()
    {
        return $this->soapClient;
    }
    
    public function getLastRequestXml()
    {
        return $this->soapClient->__getLastRequest();
    }

    public function getLastResponseXml()
    {
        return $this->soapClient->__getLastResponse();
    }

  // delete before production
  public function printPre($var) {
    echo '<pre>';
    print_r($var);
    echo '</pre>';
  }
}

Answer the question

In order to leave comments, you need to log in

2 answer(s)
G
Gleb Varganov, 2019-10-14
@kores

Paste in the template, replace in advance all the variables that I wrote that need to be replaced ($taxonomy_prefix, $term_id, $field_name)

<?php
// Задаешь префикс твоей таксономии (рубрики)
// Заменять NULL на название твоей таксономии, например 'category'
$taxonomy_prefix = NULL;

// Задаешь ID термина
// Замени NULL на ID термина, который ты ловишь в момент вывода, например '123' 
$term_id = NULL;

// Создаем из этого префикс
$term_id_prefixed = $taxonomy_prefix .'_'. $term_id;

// Замени на название своего поля
$field_name = 'photo';
if ( get_field( $field_name, $term_id_prefixed ) ) { ?>
  <img src="<?php the_field( $field_name, $term_id_prefixed ); ?>" />
<?php } ?>

B
Boris Korobkov, 2017-12-22
@BorisKorobkov

XML is a regular string, it must be passed in the same way.
Why a particular method does not work - read the documentation on it (what parameters and in what format) or contact its developers.

Didn't find what you were looking for?

Ask your question

Ask a Question

731 491 924 answers to any question