feat(deploy): 添加部署路径权限检查功能
Webhook 由 PHP(www) 触发,项目目录必须对当前用户可写。
添加了对 DEPLOY_PATH 的写权限检查,如果当前用户对部署路径没有写权限,
则显示错误信息并退出部署流程。同时提供修复建议:
chown -R www:www ${DEPLOY_PATH} && chmod -R u+rwX ${DEPLOY_PATH}
```
88 行
2.8 KiB
PHP
88 行
2.8 KiB
PHP
<?php
|
|
|
|
namespace app\api\controller;
|
|
|
|
use app\common\controller\Api;
|
|
use think\Db;
|
|
|
|
/**
|
|
* 地图服务(服务端代理高德,避免小程序 request 域名限制)
|
|
*/
|
|
class Map extends Api
|
|
{
|
|
protected $noNeedLogin = ['geocode', 'regeo'];
|
|
protected $noNeedRight = '*';
|
|
|
|
protected function amapKey()
|
|
{
|
|
$raw = Db::name('shopro_config')->where('name', 'amap')->value('value');
|
|
if ($raw) {
|
|
$cfg = json_decode($raw, true);
|
|
if (!empty($cfg['appkey'])) {
|
|
return $cfg['appkey'];
|
|
}
|
|
}
|
|
$platform = Db::name('shopro_config')->where('name', 'platform')->value('value');
|
|
if ($platform) {
|
|
$cfg = json_decode($platform, true);
|
|
if (!empty($cfg['amap']['appkey'])) {
|
|
return $cfg['amap']['appkey'];
|
|
}
|
|
}
|
|
return '24eb092b2163da8fa5087bf92844a5bd';
|
|
}
|
|
|
|
protected function amapGet($path, $query)
|
|
{
|
|
$query['key'] = $this->amapKey();
|
|
$url = 'https://restapi.amap.com/v3/' . $path . '?' . http_build_query($query);
|
|
$ctx = stream_context_create(['http' => ['timeout' => 8]]);
|
|
$body = @file_get_contents($url, false, $ctx);
|
|
if ($body === false) {
|
|
$this->error('地图服务请求失败');
|
|
}
|
|
$data = json_decode($body, true);
|
|
if (!$data || (isset($data['status']) && $data['status'] !== '1')) {
|
|
$info = isset($data['info']) ? $data['info'] : '地理编码失败';
|
|
$this->error($info);
|
|
}
|
|
return $data;
|
|
}
|
|
|
|
/**
|
|
* 地址 → 坐标
|
|
* @ApiParams (name="address", type="string", required=true)
|
|
*/
|
|
public function geocode()
|
|
{
|
|
$address = trim($this->request->get('address', ''));
|
|
if ($address === '') {
|
|
$this->error('地址不能为空');
|
|
}
|
|
$data = $this->amapGet('geocode/geo', ['address' => $address]);
|
|
if (empty($data['geocodes'][0]['location'])) {
|
|
$this->error('无法解析该地址,请尽量填写门牌号');
|
|
}
|
|
list($lng, $lat) = explode(',', $data['geocodes'][0]['location']);
|
|
$this->success('ok', [
|
|
'latitude' => $lat,
|
|
'longitude' => $lng,
|
|
'formatted' => $data['geocodes'][0]['formatted_address'] ?? '',
|
|
]);
|
|
}
|
|
|
|
/**
|
|
* 坐标 → 地址
|
|
* @ApiParams (name="location", type="string", required=true, description="lng,lat")
|
|
*/
|
|
public function regeo()
|
|
{
|
|
$location = trim($this->request->get('location', ''));
|
|
if ($location === '') {
|
|
$this->error('坐标不能为空');
|
|
}
|
|
$data = $this->amapGet('geocode/regeo', ['location' => $location]);
|
|
$this->success('ok', $data['regeocode'] ?? []);
|
|
}
|
|
}
|