PHP SDK
This topic describes how to use the PHP SDK and provides code examples.
Dependencies for service invocation
composer require alibabacloud/address-purification-20191118Configure environment variables
The Alibaba Cloud software development kit (SDK) lets you create default access credentials by setting the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables. When you call an API operation, the program uses these environment variables to retrieve your AccessKey pair and automatically complete the authentication.
An AccessKey pair for an Alibaba Cloud account grants access permissions to all API operations. To prevent AccessKey pair leaks, we recommend using a Resource Access Management (RAM) user for API access or daily O&M.
Configuration method
Set the ALIBABA_CLOUD_ACCESS_KEY_ID and ALIBABA_CLOUD_ACCESS_KEY_SECRET environment variables.
Configure on Linux and macOS
Run the following commands:
export ALIBABA_CLOUD_ACCESS_KEY_ID=<access_key_id> export ALIBABA_CLOUD_ACCESS_KEY_SECRET=<access_key_secret>Replace
<access_key_id>with your AccessKey ID and<access_key_secret>with your AccessKey secret.Configure on Windows
Create the
ALIBABA_CLOUD_ACCESS_KEY_IDandALIBABA_CLOUD_ACCESS_KEY_SECRETenvironment variables and set their values to your AccessKey ID and AccessKey secret, respectively.Restart Windows.
Address extraction
Request example
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class ExtractAddress
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
// Set the API operation name for the address extraction request.
'action' => 'ExtractAddress',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
ExtractAddress::main();Response example
string(191) "{"location_extract":[{"start":0,"end":8,"type":"LOC","word":"Alibaba Xixi Campus"}],"status":"OK","time_used":{"rt":{"location_extract":0.008560419082641602},"start":1678937689.8589857}}"Name extraction
Request example
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class ExtractName
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "John Doe";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'ExtractName',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
ExtractName::main();Response example
string(169) "{"person_extract":[{"start":0,"end":3,"type":"PER","word":"Zhang San"}],"status":"OK","time_used":{"rt":{"person_extract":0.007501125335693359},"start":1678937857.677193}}"
Phone number extraction
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class ExtractPhone
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "John Doe 1800****000";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'ExtractPhone',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
ExtractPhone::main();Example response
string(173) "{"phone_extract":[{"start":2,"end":13,"type":"TEL","word":"180****0000"}],"status":"OK","time_used":{"rt":{"phone_extract":0.009283781051635742},"start":1678938127.0899167}}"
Administrative region parsing
Sample request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class GetAddressDivisionCode
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'GetAddressDivisionCode',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
GetAddressDivisionCode::main();Example response
string(371) "{"division_info":{"divcode":"330110000000","division_name":"Zhejiang Province;Hangzhou;Yuhang District;"},"status":"OK","time_used":{"rt":{"basic_chunking":0.010630607604980469,"division_info":0.005403041839599609,"segment":0.0003552436828613281,"address_correct":0.0020055770874023438,"complete":0.00007677078247070312,"structure":0.00006628036499023438},"start":1678938277.3653004}}"
Postal code detection
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class GetZipcode
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'GetZipcode',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
GetZipcode::main();Example response
string(288) "{"zipcode":"311100","status":"OK","time_used":{"rt":{"basic_chunking":0.01495504379272461,"zipcode":0.007276773452758789,"segment":0.0005021095275878906,"address_correct":0.002620220184326172,"complete":0.000102996826171875,"structure":0.00011849403381347656},"start":1678938377.1863396}}"
Address completion
Sample request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class CompleteAddress
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'CompleteAddress',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
CompleteAddress::main();Example response
string(480) "{"complete":"prov=Zhejiang Province\tcity=Hangzhou\tdistrict=Yuhang District\ttown=Wuchang Subdistrict\troad=North Side Road\tpoi=Alibaba Xixi Campus\tpoi_list=Alibaba Xixi Campus\tdetail=poi:Alibaba Xixi Campus","status":"OK","time_used":{"rt":{"basic_chunking":0.016544818878173828,"segment":0.0004928112030029297,"address_correct":0.002981901168823242,"complete":0.00019621849060058594,"address_search":0.164764404296875,"structure":0.00010776519775390625},"start":1678938449.9231422}}"
Address correction
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class CorrectAddress
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'CorrectAddress',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
CorrectAddress::main();Example response
string(224) "{"address_correct":["Alibaba Xixi Campus=poi"],"status":"OK","time_used":{"rt":{"basic_chunking":0.01656961441040039,"segment":0.00040650367736816406,"address_correct":0.0026862621307373047},"start":1678938516.8619475}}"
Address structuring
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class StructureAddress
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'StructureAddress',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
StructureAddress::main();Example response
string(302) "{"structure":"prov=Zhejiang Province\tcity=Hangzhou\tdistrict=Yuhang District\tpoi=Alibaba Xixi Campus\tpoi_list=Alibaba Xixi Campus\tdetail=poi:Alibaba Xixi Campus","status":"OK","time_used":{"rt":{"basic_chunking":0.01711559295654297,"structure":0.00012445449829101562},"start":1678938549.4122353}}"
Multi-address similarity judgment
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class GetAddressSimilarity
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus, Hangzhou;Building 1, No. 969 Wenyi West Road, Hangzhou";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'GetAddressSimilarity',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
GetAddressSimilarity::main();Example response
string(384) "{"sim_level":{"distance":"806.86m","level":"none","address_a":"Alibaba Xixi Campus, Hangzhou","address_b":"Building 1, No. 969 Wenyi West Road, Hangzhou","is_same":false,"same_info":"prov=Zhejiang Province city=Hangzhou district=Yuhang District town=Wuchang Subdistrict road=North Side Road poi=Alibaba Xixi Campus"},"status":"OK","time_used":{"rt":{"sim_level":0.4123516082763672},"start":1678938668.682179}}"
Logistics waybill information extraction
Sample request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class ExtractExpress
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'ExtractExpress',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
ExtractExpress::main();Sample response
string(529) "{"express_extract":{"house_info":"","poi_info":"Alibaba Xixi Campus","town":"Wuchang Subdistrict","city":"Hangzhou","district":"Yuhang District","tel":"","addr_info":"Alibaba Xixi Campus","per":"","prov":"Zhejiang Province"},"status":"OK","time_used":{"rt":{"basic_chunking":0.021270751953125,"segment":0.000637054443359375,"address_correct":0.0030400753021240234,"complete":0.00018548965454101562,"express_extract":0.0000209808349609375,"address_search":0.16134858131408691,"structure":0.00011014938354492188},"start":1678938704.1794796}}"
Address type detection
Sample request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class ClassifyPOI
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'ClassifyPOI',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
ClassifyPOI::main();Example response
string(364) "{"poi_category":"Real Estate Parks and Warehousing#Industrial Parks","status":"OK","time_used":{"rt":{"basic_chunking":0.017373323440551758,"segment":0.0005145072937011719,"poi_category":0.10416412353515625,"address_correct":0.003175020217895508,"complete":0.0001938343048095703,"address_search":0.16731476783752441,"structure":0.00012159347534179688},"start":1678938745.3905106}}"POI prediction
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class PredictPOI
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'PredictPOI',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
PredictPOI::main();Example response
string(353) "{"poi_predict":"Alibaba Xixi Campus","status":"OK","time_used":{"rt":{"basic_chunking":0.01753520965576172,"segment":0.0005474090576171875,"address_correct":0.0031142234802246094,"complete":0.0001862049102783203,"poi_predict":0.006916522979736328,"address_search":0.17387175559997559,"structure":0.00011134147644042969},"start":1678938801.3496034}}"
Coordinate system transformation
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class TransferCoord
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "120.026268,30.279164";
$body['SrcCoord'] = "gcj02";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'TransferCoord',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
TransferCoord::main();Example response
string(247) "{"coord_transfer":{"BD09":"120.032768,30.285238","CGCS2000":"120.021519,30.281543","WGS84":"120.021519,30.281543","GCJ02":"120.026268,30.279164"},"status":"OK","time_used":{"rt":{"coord_transfer":0.0032346248626708984},"start":1678938912.9115283}}"
General latitude and longitude query (POI level)
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class GetAddressGeocode
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'GetAddressGeocode',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
GetAddressGeocode::main();Sample response
string(421) "{"offline_geocode":{"wgs84":"120.01842160190826,30.28575692671618","level":"poi","gcj02":"120.023164,30.28337"},"status":"OK","time_used":{"rt":{"basic_chunking":0.016934871673583984,"div_search":0.0010542869567871094,"segment":0.00046372413635253906,"geocode":0.005757570266723633,"address_correct":0.002730131149291992,"address_search":0.1618194580078125,"structure":0.00011229515075683594},"start":1678939072.4625604}}"
Address anomaly detection
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class GetAddressEvaluate
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'GetAddressEvaluate',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
GetAddressEvaluate::main();Example response
string(245) "{"address_evaluate":{"errors":"Missing administrative region; Missing road name and number"},"status":"OK","time_used":{"rt":{"basic_chunking":0.016921281814575195,"address_evaluate":0.00017523765563964844,"segment":0.000438690185546875},"start":1678939122.942952}}"Address search
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class GetAddressSearch
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'GetAddressSearch',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
GetAddressSearch::main();Example response
string(1147) "{"address_search":[{"address":"North Side Road, Xixi Phase V","name":"Alibaba Xixi Campus C","std_addr":"Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict North Side Road Alibaba Xixi Campus C"},{"address":"No. 969 Wenyi West Road","name":"Alibaba Xixi Campus A","std_addr":"Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Wenyi West Road No. 969 Alibaba Xixi Campus A"},{"address":"Xiwang Road","name":"Alibaba Xixi Campus B","std_addr":"Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Xiwang Road Alibaba Xixi Campus B"},{"address":"No. 969 Wenyi West Road, Alibaba Xixi Campus A","name":"Alibaba Xixi Campus A (Building A5)","std_addr":"Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Wenyi West Road No. 969 Alibaba Xixi Campus A (Building A5)"},{"address":"No. 969 Wenyi West Road, Alibaba Xixi Campus A","name":"Alibaba Xixi Campus A (Building A4)","std_addr":"Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Wenyi West Road No. 969 Alibaba Xixi Campus A (Building A4)"}],"status":"OK","time_used":{"rt":{"basic_chunking":0.01698446273803711,"segment":0.0005893707275390625,"address_correct":0.0024530887603759766,"address_search":0.14429116249084473,"structure":0.00011181831359863281},"start":1678939163.2801683}}"
Address input suggestion
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class GetInputSearch
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'GetInputSearch',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
GetInputSearch::main();Response example
string(741) "{"input_search":["Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Wenyi West Road Alibaba Xixi Campus (Bus Stop)","Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Jucheng Road Yike Hotel Apartment (Alibaba Xixi Campus Branch)","Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Xiangwang Street No. 199 Building 1 Tongyue Hotel (Hangzhou Alibaba Xixi Campus Branch)","Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Wenyi West Road Alibaba Xixi Campus (Caijiage) (Bus Stop)","Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Hecui Road Building 1 Hangzhou Yijia Apartment Hotel (Alibaba Xixi Campus Branch)"],"status":"OK","time_used":{"rt":{"basic_chunking":0.017215251922607422,"input_search":0.027119874954223633,"structure":0.00011205673217773438},"start":1678939207.8285642}}"
House number standardization
Sample request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class StreetStd
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'StreetStd',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
StreetStd::main();Example response
string(426) "{"street_std":"prov=Zhejiang Province\tcity=Hangzhou\tdistrict=Yuhang District\ttown=Wuchang Subdistrict\troad=Wenyi West Road\troadno=No. 969\tpoi=Alibaba Xixi Campus","status":"OK","time_used":{"rt":{"basic_chunking":0.016364336013793945,"street_std":0.00029277801513671875,"segment":0.0005488395690917969,"address_correct":0.002571582794189453,"address_search":0.1461029052734375,"structure":0.000102996826171875},"start":1678939421.2437048}}"
Voice address input detection
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class InputAsrAddress
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'InputAsrAddress',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
InputAsrAddress::main();Example response
string(381) "{"asr_address_input":{"house_info":"","struct":"prov=Zhejiang Province\tcity=Hangzhou\tdistrict=Yuhang District\tpoi=Alibaba Xixi Campus","poi_info":"Alibaba Xixi Campus","town":"","city":"Hangzhou","district":"Yuhang District","addr_info":"Alibaba Xixi Campus","prov":"Zhejiang Province"},"status":"OK","time_used":{"rt":{"asr_address_input":0.03881049156188965},"start":1678939666.2516294}}"
Multi-source address unification
Sample request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class OneIdAddress
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'OneIdAddress',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
OneIdAddress::main();Example response
{'RequestId': '7EF87685-675C-1753-BED1-3181D1F4D565', 'Data': '{"online_address_unify":"82310db47579d1e4ef4484d7ce3f0b76","status":"OK","time_used":{"rt":{"basic_chunking":0.010370254516601562,"online_address_unify":0.0012214183807373047,"segment":0.0004582405090332031,"address_correct":0.0020546913146972656,"address_search":0.1227867603302002,"structure":0.0000743865966796875},"start":1675414152.5409853}}'}
Address inference from conversational context
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class AddressInference
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "I was hit by a car at the gate of Alibaba in Binjiang District.";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'AddressInference',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
AddressInference::main();Response example
string(838) "{"address_inference":[{"address":"No. 699 Wangshang Road","divcode":"330108","name":"Alibaba Binjiang Campus","id":"B0FFG083SL","lxly":"30.1896,120.190371","std_addr":"Zhejiang Province Hangzhou Binjiang District Changhe Subdistrict Wangshang Road No. 699 Alibaba Binjiang Campus"},{"address":"No. 969 Wenyi West Road","divcode":"330110","name":"Alibaba Xixi Campus A","id":"B023B1D4BX","lxly":"30.278984,120.025746","std_addr":"Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Wenyi West Road No. 969 Alibaba Xixi Campus A"},{"address":"Xiwang Road","divcode":"330110","name":"Alibaba Xixi Campus B","id":"B0FFGUEOJ9","lxly":"30.275962,120.027276","std_addr":"Zhejiang Province Hangzhou Yuhang District Wuchang Subdistrict Xiwang Road Alibaba Xixi Campus B"}],"status":"OK","time_used":{"rt":{"dialog_extract":0.009522676467895508,"address_inference":0.6170024871826172},"start":1678939524.550949}}"
High-precision latitude and longitude query (building level)
Example request
<?php
require __DIR__ . '/vendor/autoload.php';
use AlibabaCloud\OpenApiUtil\OpenApiUtilClient;
use AlibabaCloud\SDK\Addresspurification\V20191118\Addresspurification;
use AlibabaCloud\Tea\Utils\Utils\RuntimeOptions;
use Darabonba\OpenApi\Models\Config;
use Darabonba\OpenApi\Models\OpenApiRequest;
use Darabonba\OpenApi\Models\Params;
/**
* author: shuaicheng
* Date: 2023/3/7 4:10 PM
*/
class HpGeocode
{
/**
* Use the AccessKey ID and AccessKey secret to initialize the account client.
* @param string $accessKeyId <your-access-key-id>
* @param string $accessKeySecret <your-access-key-secret>
* @return Addresspurification Client
*/
public static function createClient()
{
$config = new Config();
// We strongly recommend that you do not save the AccessKey ID and AccessKey secret in your project code.
// Otherwise, the AccessKey pair may be leaked, which threatens the security of all resources in your account.
// This example shows how to save the AccessKey ID and AccessKey secret to environment variables. Before you run this code example, configure the environment variables.
$config->accessKeyId = getenv("ALIBABA_CLOUD_ACCESS_KEY_ID");
$config->accessKeySecret = getenv("ALIBABA_CLOUD_ACCESS_KEY_SECRET");
$config->endpoint = "address-purification.cn-hangzhou.aliyuncs.com";
return new Addresspurification($config);
}
public static function main()
{
$client = self::createClient();
$body = [];
// Set it to your appKey.
$body['AppKey'] = "<your-appKey>";
// Set the city name.
$body['DefaultCity'] = "Hangzhou";
// Set the district name.
$body['DefaultDistrict'] = "Yuhang District";
// Set the province name.
$body['DefaultProvince'] = "Zhejiang Province";
// The value is fixed to addrp.
$body['ServiceCode'] = "addrp";
// Set the request text.
$body['Text'] = "Alibaba Xixi Campus";
$req = new OpenApiRequest([
'body' => OpenApiUtilClient::parseToMap($body),
]);
$params = new Params([
'action' => 'HpGeocode',
'version' => '2019-11-18',
'protocol' => 'HTTPS',
'pathname' => '/',
'method' => 'POST',
'authType' => 'AK',
'style' => 'RPC',
'reqBodyType' => 'formData',
'bodyType' => 'json',
]);
$runtime = new RuntimeOptions([
'maxIdleConns' => 3,
'connectTimeout' => 10000,
'readTimeout' => 10000
]);
$map = $client->callApi($params, $req, $runtime);
/**
* public $headers;
* public $statusCode;
* public $body;
*/
var_dump($map["body"]["Data"]);
}
}
HpGeocode::main();Example response
string(154) "{"hpgeocode":{"level":"poi","gcj02":"120.024408,30.275953"},"status":"OK","time_used":{"rt":{"hpgeocode":0.18193364143371582},"start":1678939622.3214366}}"