|
楼主 |
发表于 2023-10-15 14:16:26
|
显示全部楼层
- //挂机宝端口映射
- //添加端口
- 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()];
- }
- }
复制代码
|
|