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

use Yii;
use common\exts\Aes;
use common\exts\RSACrypt;
use common\exts\Http;
use common\helpers\Utils;

use GuzzleHttp\Psr7;
use yii\console\Controller;

use function chr;

class TestController extends Controller
{

   public function actionGen()
   {
       $no = hexdec('000A') + 1;
       echo sprintf('%04X', $no);
   }

    public function actionCheckSign()
    {
        $str = '{"manufacture":"0001","device_id":"4705BF36C376","project":"0001","model":"0001","production":"0001","timestamp":"1500000000","sign":"f16b3f969714a400e155e04e0ea29938"}';
        $arr = json_decode($str, true);
        //md5($arr[''])
    }



    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://47.107.95.101/app-api/web/checkAppVersion';
        $params = [
            'barcode' => '0001000100010001',
            'device_id' => 'DEVICE000001',
            'current_version' => 'V1.0.1',
            'package_name' => 'V1.0.2安装包',
        ];
        //$params = json_decode($params);
        $params = '{"barcode":"0001000100010001","device_id":"DGDEVBICEID00001","package_name":"com.kingboard.settings","current_version":"1"}';

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

    public function actionCheckOtaUpdate()
    {
        //actionCheckAppVersion
        $url = 'http://47.107.95.101/app-api/web/checkOtaVersion';
        //$url = 'http://kingb:8012/app-api/web/checkOtaVersion';
        $params = [
            'barcode' => '0001000100010001',
            'device_id' => 'DGDEVBICEID00001',
            'software_version' => 'V1.0.1',
            'hardware_version' => 'V1.0.1',
        ];
        $params = json_encode($params);
        $params = '{"barcode":"0001000100010001","device_id":"DEVICEID00001","software_version":"V1.00.1A.20191002","hardware_version":""}';
        $postResult = Http::POST($url, $params);
        echo $postResult;
    }

    //{"barcode":"0001000100010001","device_id":"DEVICEID00001","current_version":"V1.00.1A.20191022","target_version":"V1.00.1A.20191022","status":5,"timestamp":"1572759793"}

    public function actionReportOtaEvent()
    {
        //actionCheckAppVersion
        $url = 'http://47.107.95.101/app-api/web/reportOtaUpgradeEvent';
        //$url = 'http://kingb:8012/app-api/web/reportOtaUpgradeEvent';

        $params = [
            'barcode' => '0001000100010001',
            'device_id' => 'DGDEVBICEID00001',
            'software_version' => 'V1.0.1',
            'hardware_version' => 'V1.0.1',
        ];
        $params = json_encode($params);
        $params = '{"barcode":"0001000100010001","device_id":"DEVICEID00001","current_version":"V1.00.1A.20191022", "target_version":"V1.00.1A.20191022","status":5,"timestamp":"1572759793"}';
        $postResult = Http::POST($url, $params);
        echo $postResult;
    }

    public function actionReportAppEvent()
    {
        //actionCheckAppVersion
        //$url = 'http://47.107.95.101/app-api/web/reportAppUpgradeEvent';
        $url = 'http://kingb:8012/app-api/web/reportAppUpgradeEvent';

        $params = [
            'barcode' => '0001000100010001',
            'device_id' => 'DGDEVBICEID00001',
            'current_version' => 'V1.0.1',
            'target_version' => 'V1.0.1',
            'package_name'     => 'com.app.king.dd',
            "status"           => 0,
            "error_code"       => '',
            "timestamp"        => 1572767677

        ];
        $params = json_encode($params);
        //$params = '{"barcode":"0001000100010001","device_id":"DGDEVBICEID00001","current_version":"1","target_version":"2","status":"5","error_code":"0","timestamp":"1572767677"}';
        $postResult = Http::POST($url, $params);
        echo $postResult;
    }

    public function actionEncodePost()
    {
        $url = 'http://kingb:8012/app-api/web/CryptTxt';
        $randKey = '98765432';//Utils::rand(32);
        $rsaKeys = Yii::$app->params['AUTH_DEVICE_RSA_PKCS_1'];
        $rsa = new RSACrypt($rsaKeys['PRIVATE'], $rsaKeys['PUBLIC']);
        $aes = new Aes($randKey);
        $deviceId = 'oelooeloeloeloe';
        $manufactureNo = '0001';
        $tt = time();
        $sign = md5($deviceId . $tt . $randKey);
        $dd = json_encode(['manufacture' => $manufactureNo, 'timestamp' => $tt, 'sign' => $sign, 'device_id' => $deviceId]);
        $params = [
            'randomKey' => $rsa->encrypt($randKey),
            'content'   => $aes->encrypt($dd)
        ];
        $params = json_encode($params);
        $postResult = Http::POST($url, $params);
        $postResult = json_decode($postResult, true);
        $decodeJson = $aes->decrypt($postResult['content']);
        print_r($decodeJson);
    }

    /**
     *
     */
    public function actionAuthDevice()
    {
        $url = 'http://kingb:8012/app-api/web/authDevice';
        $url = 'http://47.107.95.101/app-api/web/authDevice';
        $manufactureNo = '0001';
        $device_id = 'DEVICE00000B';
        $projectNo = '0001';
        $modelNo = '0001';
        $productionNo = '0001';
        $timestamp = time();


        $randKey = Utils::rand(16);
        $salt = "13456";
        $sign = md5($manufactureNo. $projectNo. $modelNo . $productionNo . $timestamp .$device_id. $salt);
        $deviceParams = [
            'manufacture' => $manufactureNo,
            'device_id' => $device_id,
            'project' => $projectNo,
            'model' => $modelNo,
            'production' => $productionNo,
            'timestamp' => $timestamp,
            'sign' => $sign,
        ];
        $deviceParams = json_encode($deviceParams);
        $rsaKeys = Yii::$app->params['AUTH_DEVICE_RSA_PKCS_1'];
        $rsa = new RSACrypt($rsaKeys['PRIVATE'], $rsaKeys['PUBLIC']);

        $randomKey = $rsa->encrypt($randKey);
        $aes = new Aes(substr(md5($randKey.'12356'), 8, 16));
        $params = [
            'randomKey' => $randomKey,
            'content'   => $aes->encrypt($deviceParams)
        ];
        $params = json_encode($params);
        $postResult = Http::POST($url, $params);

        $postResult = json_decode($postResult, true);
        $decodeJson = $aes->decrypt($postResult['content']);

        echo $decodeJson;
    }


    public function actionA()
    {
        $str = "87654321";
        $rsaKeys = Yii::$app->params['AUTH_DEVICE_RSA_PKCS_1'];
        $rsa = new RSACrypt($rsaKeys['PRIVATE'], $rsaKeys['PUBLIC']);
        $deStr = "SRAeq\/pjyDA+0TtCTo06cbskERUUXvmGh3FdocS9AFmMsYDN\/TACQeU9pZhB5zKYHsJSTo\/JawuN\nG0ZBFd1B6TvJ\/1PkX30cvL9i03Ujo1JVe1njhMrig3mvNd7RDAylNzaFAAHU\/Wb\/94kf7gRGNyTj\ngj78Oe0bLdwasz4vBFE=\n";

        //echo $deStr."\r\n";
        $randKey = $rsa->decrypt($deStr);
echo $randKey."\r\n";
        $randKey = substr(md5($randKey.'12356'), 8, 16)."\r\n";
        echo $randKey."\r\n";
        $aes = new Aes($randKey);
        echo $aes->decrypt("nZ8U4BlG0vxckrPM0lquvGDZ9Yuv32+MbYKZG8cqfMGJcltEEquc9v88bzpzm2dpkX5nR4ugLxfw\nc65yqYouozxyX+UdXPNHqaOYIQK\/MVWi+GkYsEafezJhozyGrLWAo7hHIdYcV\/fnm7xyEAaN\/91Q\nWdrhYmGvMf1IusGPBDaRnZtJ+mR1MhElZP73mQppFlusI8EJVFcEx\/z\/SkE9ywhPqAsK721xV+Fe\ncd7sNKs=\n");

    }

}