Exemple PHP 5.3
Exemplele de mai jos folosesc SoapClient și o clasă helper simplă pentru autentificare, execuție operații și închiderea sesiunii.
Fragment PHP minimal
<?php
require 'ImopediaSoap.php';
$client = new ImopediaSoap('https://www.imopedia.ro/soap.wsdl', 'user', 'parola');
$client->connect();
$property = (object) [
'AGENTIA' => 0,
'ID_LOCAL' => 67654,
'TITLU' => 'Apartament 2 camere în Giurgiului',
'T_V_PRET' => '43423',
'T_V_MONEDA' => 'EUR',
'T_V_TRANZ' => 1,
];
$result = $client->execute('saveProperty', $property);
$client->disconnect();
Exemplu PHP extins
<?php
define('IMOPEDIA_USER', 'user');
define('IMOPEDIA_PASSWORD', 'parola');
include 'ImopediaSoap.php';
$imopedia = new ImopediaSoap('https://www.imopedia.ro/soap.wsdl?' . time(), IMOPEDIA_USER, IMOPEDIA_PASSWORD);
$imopedia->connect();
$agentia = 0; // ID-ul agenției, comunicat împreună cu datele de login
$run = [
'camp_pret' => 'T_V_PRET',
'camp_moneda' => 'T_V_MONEDA',
'camp_tranz' => 'T_V_TRANZ',
];
$videos = json_encode([
[
'TITLE' => 'Titlu video',
'FILE_URL' => 'https://www.youtube.com/watch?v=akotZoPsG5M',
],
]);
$options = [
'AGENTIA' => $agentia,
'ID_LOCAL' => 67654,
'DATA_MODIFICARE' => '2012-01-11',
'DATA_APARITIE' => '2012-01-11',
'ZONA' => 'Giurgiului',
'JUDET' => 'Bucuresti',
'COMISION' => 2,
'TITLU' => 'Apartament 2 camere in Giurgiului',
'SUPR_UTILA' => '91.55',
'GEO_LAT' => '44.392663',
'GEO_LONG' => '26.089659',
'AN_CONSTRUCTIE' => 1960,
'NRCAM' => 5,
'NRDORMITOARE' => 3,
'NR_BAI' => 2,
'NR_GR_SANITARE' => 2,
'DOTARI' => '',
'VECINATATI' => '',
'ACTE_DOBANDIRE' => '',
'TIP_IMOBIL_REAL' => 3,
$run['camp_pret'] => '43423',
$run['camp_moneda'] => 'EUR',
$run['camp_tranz'] => 1,
'CONTACT_PERS' => 'Geoerrge Popescu',
'CONTACT_EMAIL' => 'teest_agent@run.ro',
'CONTACT_TEL' => '0721117111',
'AMPLASAMENT' => '',
'A_IMPARTIRE' => '',
'STARE_IMOBIL' => '',
'T_EXTRAVILAN' => '',
'T_INTRAVILAN' => '',
'T_AGRICOL' => '',
'NR_BALCOANE' => 3,
'REPER' => 'Piata Progresul',
'SUPR_ALTE' => 'Baie 1: 5.54 mp, Bucatarie: 8.64 mp, Camera Zi (Living): 25.43 mp, Dormitor 2: 17.95 mp, Dormitor Matrimonial: 20.75 mp',
'OBSERVATII' => 'PIATA PROGRESUL - BLOC NOU. Straduta linistita de case, la cateva minute de bulevard dar ferita de trafic. Este o proprietate rafinata perfecta pentru o familie activa, intr-un bloc deosebit construit in 2008. Apartamentul are un decor minunat, un living perfect pentru recreere, baie cu hidromasaj, bucatarie mobilata si utilata. Cele trei balcoane ofera o panorama larga asupra imprejurimilor.',
'ADDRESS' => 'Adresa',
'C_PIVNITA' => '',
'C_MANSARDA' => '1',
'T_D_APA' => '1',
'T_D_CANALIZARE' => '1',
'T_D_GAZE' => '1',
'T_D_CURENT' => '1',
'VIDEO_INFO' => $videos,
];
$optionso = arrayToObject($options);
$soap_result = $imopedia->execute('saveProperty', $optionso);
$oferta_adaugata = null;
if (isset($soap_result['_success'][0]['result']['property_id'])) {
$oferta_adaugata = $soap_result['_success'][0]['result']['property_id'];
}
if ($oferta_adaugata) {
$photos = [
[
'Location' => 'http://clienti2.run.ro/usr/poze/thumb_612_x_0_309_1747.jpg',
'Content-Description' => 'Descrierea pozei',
'Object-ID' => 4534,
],
];
foreach ($photos as $photo) {
$fileOptions = [
'FILE_ID' => md5($photo['Object-ID'] . $photo['Content-Description'] . $photo['Location']),
'FILE_TITLE' => $photo['Content-Description'],
];
$fileOptionso = arrayToObject($fileOptions);
$rrr = $imopedia->execute('existsFile', $fileOptionso);
$exists = 0;
if (isset($rrr['_success']['0']['photo']['exists'])) {
$exists = $rrr['_success']['0']['photo']['exists'];
}
if ($exists == 1) {
continue;
}
$fileOptions['FILE_BODY'] = base64_encode(file_get_contents($photo['Location']));
$fileOptionso = arrayToObject($fileOptions);
$imopedia->execute('addFile', $fileOptionso);
}
}
$imopedia->disconnect();
function objectToArray($data)
{
if (is_array($data) || is_object($data)) {
$result = [];
foreach ($data as $key => $value) {
$result[$key] = objectToArray($value);
}
return $result;
}
return $data;
}
function arrayToObject($array)
{
if (!is_array($array)) {
return $array;
}
$object = new stdClass();
if (count($array) > 0) {
foreach ($array as $name => $value) {
$name = trim($name);
if (!empty($name)) {
$object->$name = arrayToObject($value);
}
}
return $object;
}
return false;
}
Clasă helper PHP
<?php
class ImopediaSoap
{
public function __construct($url, $user, $password)
{
ini_set('soap.wsdl_cache_enabled', '0');
ini_set('soap.wsdl_cache_ttl', '0');
$this->user = $user;
$this->password = $password;
$this->client = new SoapClient($url, ['cache_wsdl' => 0, 'trace' => 1]);
}
public function connect()
{
$this->sess_id = $this->client->__soapCall('login', ['username' => $this->user, 'password' => $this->password]);
return $this->sess_id;
}
public function disconnect()
{
$this->client->__soapCall('logout', ['session_id' => $this->sess_id]);
}
public function execute($method, $options)
{
$payload = [
'session_id' => $this->sess_id,
'options' => $options,
];
return $this->client->__soapCall($method, $payload);
}
}
Pentru payload-uri separate de codul PHP, vezi Exemple de payload-uri.