You can not select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
49 lines
1.2 KiB
49 lines
1.2 KiB
1 year ago
|
<?php
|
||
|
|
||
|
use Joypack\Tencent\Map\Bundle\AddressOption;
|
||
|
use Joypack\Tencent\Map\Bundle\Address;
|
||
|
|
||
|
define('ROOT_PATH', dirname(__DIR__));
|
||
|
|
||
|
define('LOG_PATH', sprintf('%s/logs', ROOT_PATH));
|
||
|
|
||
|
spl_autoload_register(function ($className) {
|
||
|
$className = str_replace('\\', '/', $className);
|
||
|
$className = str_replace('Joypack/Tencent/Map/', '', $className);
|
||
|
|
||
|
require_once sprintf('%s/src/%s.php', ROOT_PATH, $className);
|
||
|
});
|
||
|
|
||
|
$option = new AddressOption();
|
||
|
$option->setKey('<your app key>');
|
||
|
$option->setSecret('<your app secret>');
|
||
|
|
||
|
$option->setAddress('<address>');
|
||
|
|
||
|
$address = new Address($option, LOG_PATH, true);
|
||
|
|
||
|
// 授权IP校验方式通信(无sig参数)
|
||
|
// $res = $address->request();
|
||
|
|
||
|
// 通过签名校验的方式通信
|
||
|
// 无需使用 $option->setSig()
|
||
|
$res = $address->request(true);
|
||
|
|
||
|
// $res->logger->print($res, true);
|
||
|
|
||
|
// 判断请求是否异常
|
||
|
if($res->error) {
|
||
|
$res->logger->print($res->error, true);
|
||
|
}
|
||
|
|
||
|
// 打印接口返回的原始数据
|
||
|
// $res->logger->print($res->getOriginal(), true);
|
||
|
|
||
|
// 判断接口返回状态
|
||
|
if($res->status) {
|
||
|
// 打印接口返回信息
|
||
|
$res->logger->print($res->message, true);
|
||
|
}
|
||
|
|
||
|
// 打印接口返回数据(内部已完成Array解析)
|
||
|
$res->logger->print($res->result, true);
|