能否让对接轻舟的共享IP机器支持端口映射
如题,完成对接后发现没有端口映射的选项,请问是否可以实现 需要有轻舟相关api接口才可以实现 //挂机宝端口映射//添加端口
public function addForwardPort(array $nodeInfo=[],array $param=[]){
if($this->apikey==""&&$nodeInfo['apikey']==""){
return ['code'=>0,'msg'=>'通讯密钥错误'];
}
if($this->node_url==""&&$nodeInfo['node_ip']==""){
return ['code'=>0,'msg'=>'节点通讯地址为空'];
}
$apikey = $this->apikey?$this->apikey:$nodeInfo['apikey'];
$forward_url = $this->forward_url?$this->forward_url:$nodeInfo['forward_url'];
$post_data = [];
$post_data['dport'] =strval($param['dport']); //小鸡内网端口
$post_data['sport'] = strval($param['sport']); //映射服务器公网端口
$post_data['dip'] = $param['dip'];
$post_data['vm_name'] = $param['host_name'];
try {
$Client = new Client();
$res = $Client->post('http://'.$forward_url.':'.$this->forward_port."/api/Forward/AddPort",[
'headers' => ['Content-Type' => 'application/json','apikey'=>$apikey],
'http_errors' => false,
'json' => $post_data,
'timeout' => 10
]);
if($res->getStatusCode()!=200){
return ['code'=>0,'msg'=>$res->getBody()->getContents()];
}else{
$body = $res->getBody();
$result = \GuzzleHttp\json_decode($body,true);
if($result['code']!=200){
return ['code'=>0,'msg'=>$result['msg']];
}else{
return ['code'=>200,'msg'=>'success','data'=>$result['data']];
}
}
}catch (\Exception $e){
return ['code'=>0,'msg'=>$e->getMessage()];
}
}
//删除端口
public function removeForwardPort(array $nodeInfo=[],array $param=[]){
if($this->apikey==""&&$nodeInfo['apikey']==""){
return ['code'=>0,'msg'=>'通讯密钥错误'];
}
if($this->node_url==""&&$nodeInfo['node_ip']==""){
return ['code'=>0,'msg'=>'节点通讯地址为空'];
}
$apikey = $this->apikey?$this->apikey:$nodeInfo['apikey'];
$forward_url = $this->forward_url?$this->forward_url:$nodeInfo['forward_url'];
$post_data = [];
$post_data['dport'] = $param['dport']; //小鸡内网端口
$post_data['sport'] = $param['sport']; //映射服务器公网端口
$post_data['dip'] = $param['dip'];
$post_data['vm_name'] = $param['host_name'];
try {
$Client = new Client();
$res = $Client->post('http://'.$forward_url.':'.$this->forward_port."/api/Forward/DelPort",[
'headers' => ['Content-Type' => 'application/json','apikey'=>$apikey],
'http_errors' => false,
'json' => $post_data,
'timeout' => 10
]);
if($res->getStatusCode()!=200){
return ['code'=>0,'msg'=>$res->getBody()->getContents()];
}else{
$body = $res->getBody();
$result = \GuzzleHttp\json_decode($body,true);
if($result['code']!=200){
return ['code'=>0,'msg'=>$result['msg']];
}else{
return ['code'=>200,'msg'=>'success','data'=>$result['data']];
}
}
}catch (\Exception $e){
return ['code'=>0,'msg'=>$e->getMessage()];
}
}
kanwenjie123 发表于 2023-10-15 14:16
你好,你发的这个代码不是对接轻舟主控的api,看代码更向是轻舟主控通讯端口转发控制器的。 nat是必须要的 做nat服务器现在很好 不能自助就做跳转到轻舟控制页面即可,所以 老板可以做1个开关,需要轻舟nat就跳转,不需要nat就不跳转~~~~ 加载云 发表于 2023-10-15 15:02
你好,你发的这个代码不是对接轻舟主控的api,看代码更向是轻舟主控通讯端口转发控制器的。 ...
nat是必须要的 做nat服务器现在很好 不能自助就做跳转到轻舟控制页面即可,所以 老板可以做1个开关,需要轻舟nat就跳转,不需要nat就不跳转~~~~
页:
[1]