TestController.php 2.91 KB
<?php
namespace console\controllers;
/**
 * Created by PhpStorm.
 * User: scott
 * Date: 8/15/18
 * Time: 11:32 AM
 */


use app\api\helpers\Aes;
use common\exts\Http;
use domain\device\Device;
use GuzzleHttp\Psr7;
use yii\console\Controller;
use GuzzleHttp\Psr7\Request;
use function chr;
use yii\helpers\ArrayHelper;

class TestController extends Controller
{

   public function actionGen()
   {
       echo sprintf('%04x', 1);
   }

    public function actionDeviceAuth()
    {
        $url = 'http://kingb:8012/app-api/web/authDevice';
        $manufactureNo = '0002';
        $device_id = 'SZDEVICE000037';
        $projectNo = '002';
        $modelNo = '002';
        $productionNo = '0001';

        $timestamp = time();
        $salt = 13456;
        $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp . $salt);
        $params = [
                'manufacture' => $manufactureNo,
                'device_id' => $device_id,
                'project' => $projectNo,
                'model' => $modelNo,
                'production' => $productionNo,
                'timestamp' => $timestamp,
                'sign' => $sign,
        ];
        $postResult = Http::POST($url, $params);
        echo $postResult;

    }

    public function actionUpgrade()
    {
        $url = 'http://kingb:8012/app-api/web/reportDeviceVersion';
        $params = [
            'barcode' => '00001',
            'device_id' => 'DEVICE001',
            'software_version' => 'V1.0.1',
            'hardware_version' => 'V1.0.2',
            'timestamp' => 1500000000
        ];

        $postResult = Http::POST($url, $params);
        echo $postResult;
    }

    public function actionAec()
    {
        $aes = new Aes('12345678');
        $encrypted = $aes->encrypt('this is en AES testing');
        echo '要加密的字符串:this is en AES testing<br>加密后的字符串:'. $encrypted. '<hr>';
        $decrypted = $aes->decrypt($encrypted);
        echo '要解密的字符串:'. $encrypted, '<br>解密后的字符串:'. $decrypted;
    }

    public function actionDeviceSt()
    {
        $url = 'http://kingb:8012/app-api/web/reportDeviceVersion';
        $params = [
            'barcode' => '0001000100010001',
            'device_id' => 'DEVICE003',
            'software_version' => 'V1.0.1',
            'hardware_version' => 'V1.0.2',
            'timestamp' => 1500000000
        ];

        $postResult = Http::POST($url, json_encode($params));
        echo $postResult;
    }

    public function actionCheckAppUpdate()
    {
        //actionCheckAppVersion
        $url = 'http://kingb:8012/app-api/web/checkAppVersion';
        $params = [
            'barcode' => '0001000100010001',
            'device_id' => 'DEVICE000001',
            'current_version' => 'V1.0.1',
            'package_name' => 'com.ota.app.pro',
        ];

        $postResult = Http::POST($url, json_encode($params));
        echo $postResult;
    }

}