PHP code example of boneq / laravel-onenet

1. Go to this page and download the library: Download boneq/laravel-onenet library. Choose the download type require.

2. Extract the ZIP file and open the index.php.

3. Add this code to the index.php.
    
        
<?php
require_once('vendor/autoload.php');

/* Start to develop here. Best regards https://php-download.com/ */

    

boneq / laravel-onenet example snippets


  Boneq\OneNet\OneNetServiceProvider::class,
  

  'token'=>env('OneNet_Token','令牌'),
  'encodekey'=>env('OneNet_EncodingAESKey', '消息加解密秘钥'),
  'apikey'=>env('OneNet_APIKey','设备操作中的密钥')
  

  'OneNet'=>Boneq\OneNet\Facades\OneNet::class,
  

Route::any('/onenet', 'OneNetController@onenet');



namespace App\Http\Controllers;

use OneNet;

class OneNetController extends Controller
{
    public function serve()
    {
        $app = app('onenet');
        $server=$app->server(function($message){
            //收到服务器推送的信息数据存为日志 info为laravel日志函数
            info($message);
        });
        //必须return $server 基本平台验证就要返回数据
        return $server;
    }
}

use OneNet;

public function addTerminal()
{
    // name 是设备名称,MQTT是设备协议
    return OneNet::add('name','MQTT');
}

use OneNet;

public function editTerminal()
{
    // ter_id是设备id,name 是设备名称,MQTT是设备协议
    return OneNet::edit('ter_id','name','MQTT');
}

use OneNet;

public function deleteTerminal()
{
    // ter_id是设备id
    return OneNet::delect('ter_id');
}

use OneNet;

public function sendMessage()
{
    // ter_id是设备id,$data是json数据
    $data=['msgtype'=>'text','text'=>'4444'];
    return OneNet::send('ter_id',$data);
}
shell
  php artisan vendor:publish --provider="Boneq\OneNet\OneNetServiceProvider"