5.5. PHP пример за използване на Colibri® ERP web services

Тук ще представим пример за комуникационна сесия с Colibri® ERP, която връща масив с наличностите за артикули с определени от заявката номера.

Пример за Colibri® ERP web service – Наличности за избрани артикули.

Пример 54. Пример за Colibri® ERP web service – Наличности за избрани артикули


<?php /*
Colibri ERP - Web Services
Copyright (c) 2006 EDA Ltd.

$Id: wsclient-example.php,v 1.4 2009/11/12 13:29:16 $

Simple Script Demonstrating use of Colibri ERP Web Services

Simple Web Service Session scenario:
1. Logging in to Colibri ERP
2. Calling application methods and retrieve information
3. Logout

Notes:
1. Web Service exchange data in UTF-8 encoding.
2. Both peers must conform using of Windows-1251 charset.
Modified client scenario:
Before pass data to calling methods data must be encoded in UTF-8 and
after receive data must be decoded from UTF-8.
*/
include("nusoap.php");

// Common functions supporting encoding transformation between peer
function cyr2utf($data) {
	if (!is_array($data)) return iconv("Windows-1251", "UTF-8", $data);
	foreach($data as $key => $val)
		$data[$key] = cyr2utf($val);
	return ($data);
}

function utf2cyr($data) {
	if (!is_array($data)) return iconv("UTF-8", "Windows-1251", $data);
	foreach($data as $key => $val)
		$data[$key] = utf2cyr($val);
	return ($data);
}

// Entry point data
$WS_URL = "https://colibrierp.mydomain.com/ws/wsbase.php?wsdl";
$CNum = "000";
$DBName = "erp_database";
$UserName = "ws-user";
$UserPass = "ws-pass";

// Initializing client
$sc = & new nusoap_client($WS_URL, true);
$err = $sc->getError();
if ($err) {
	echo "Constructor error $err\n";
}

$sc->soap_defencoding = "UTF-8";
$sc->decode_utf8 = false;

echo "Logging in ...\n";
$result = $sc->call("erpSOAPServer..Login",
	array("username" => $UserName, "password" => $UserPass, "cnum" => $CNum, "db" => $DBName));
//$result = $sc->call("erpSOAPServer..Login",
//	array("username" => $UserName, "password" => $UserPass));
if ($sc->fault) {
	echo "Fault:\n";
	print_r($result);
	die;
} else {
	$err = $sc->getError();
	if ($err) {
		echo "Error: $err\n";
		die;
	} else {
		echo "Login OK! Result:$result\n";
	}
}

echo "\nRequest ERP Info ...\n";
$result = $sc->call("erpSOAPBase..Info");
if ($sc->fault) {
	echo "Fault:\n";
	print_r($result);
} else {
	$err = $sc->getError();
	if ($err) {
		echo "Error: $err\n";
	} else {
		echo "Result:\n";
		print_r(utf2cyr($result));
	}
}

echo "\nCheck encoding between peers ...\n";
$result = $sc->call("erpSOAPServer..CheckEncoding",
                    array("input" => cyr2utf("Тестово съобщение на кирилица (Charset: Windows-1251)!"))
					);
if ($sc->fault) {
	echo "Fault:\n";
	print_r($result);
} else {
	$err = $sc->getError();
	if ($err) {
		echo "Error: $err\n";
	} else {
		echo "Result:\n";
		print_r(utf2cyr($result));
	}
}

echo "\nRequest Available quantity\n";
//$result = $sc->call("erpSOAPStore..GetAvQ", array("SNumber" => "001", "MNum" => "001"));
$result = $sc->call("erpSOAPStore..GetAvQA", cyr2utf(array("SNumber" => "001", "MNumA" => array("001", "002", "003"))));
if ($sc->fault) {
	echo "Fault:\n";
	print_r($result);
} else {
	$err = $sc->getError();
	if ($err) {
		echo "Error: $err\n";
	} else {
		echo "Result:\n";
		print_r(utf2cyr($result));
	}
}

echo "\nLogout ...\n";
$result = $sc->call("erpSOAPServer..Logout");
if ($sc->fault) {
	echo "Fault:\n";
	print_r($result);
} else {
	$err = $sc->getError();
	if ($err) {
		echo "Error: $err\n";
	} else {
		echo "Logout OK! Result:$result\n";
	}
}
echo "\nDone.\n";

//echo "\n\nDebug\n";
//echo "".$sc->debug_str."\n";
?>

				


Copyright © 2006-2024 EDA Ltd.