使用 GUID 类型:PHP


Working with GUID type : PHP

我正在使用一个 SOAP 应用程序,该应用程序要求提供一些 GUID 类型的参数。我不确定这一切意味着什么。

我发现这是在 PHP 中制作 GUID 的:

function getGUID(){
    if (function_exists('com_create_guid')){
        return com_create_guid();
    } else {
        mt_srand((double)microtime()*10000);//optional for php 4.2.0 and up.
        $charid = strtoupper(md5(uniqid(rand(), true)));
        $hyphen = chr(45);// "-"
        $uuid = chr(123)// "{"
            .substr($charid, 0, 8).$hyphen
            .substr($charid, 8, 4).$hyphen
            .substr($charid,12, 4).$hyphen
            .substr($charid,16, 4).$hyphen
            .substr($charid,20,12)
            .chr(125);// "}"
        return $uuid;
    }
}

但是当我尝试传入参数时,我不知道这是如何工作的。以下是我需要如何使用它的示例:

$option=array('trace'=>1);
$url = "http://example.com/admin.asmx?WSDL";
$client = new SoapClient($url, $option);
$params = array(
    'consumerid'   => '1234',
    'userName'     => '1234',
    'password'     => '1234',
    'adminDomain'  => 'admin.example.com',
    'SubscriberID' => '1234',
    'orderID'      => '22147'); /* <- This value needs to be of the type GUID */
$result = $client->getOrderDetail($params);

我可以创建新的 GUID,但我不知道如何将值与它相关联。有人可以提供解释吗?

你的意思是:

$option=array('trace'=>1);
$url = "http://example.com/admin.asmx?WSDL";
$client = new SoapClient($url, $option);
# get guid and store in variable
$guid = getGUID();
$params = array(
    'consumerid'   => '1234',
    'userName'     => '1234',
    'password'     => '1234',
    'adminDomain'  => 'admin.example.com',
    'SubscriberID' => '1234',
    'orderID'      => $guid); # now use that guid here
$result = $client->getOrderDetail($params);