<?php
/* 
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

namespace app\index\controller;
use think\Controller;
use app\common\lib\redisQueue;
class Test extends Controller{

    public function index() {
        echo '开始时间：'.microtime(true).'<br/>';
        $res = sx_call('5a4216fe6b2b5');
        echo '结束时间.'.microtime(true).'<br/>';
        var_dump($res);

        exit();
        var_dump(session(''));
//        $up =  new \app\index\lib\Update();
//        $res = $up->runUpdate();
//        var_dump($res);
   echo '
<audio controls="controls" preload="auto" autoplay="autoplay" loop="loop" src="/upload/audio/20180121/aaa.wav">
                                    
                                    你的浏览器不支持video标签。
                                </audio>



   ';
   exit();
        $listName = 'service_control_sign';
        $message = [
            'last_active'=>date('Y-m-d H:i:s'),
            'service_list'=>[
                'test1'=>['restart_count'=>102,'last_restart'=>date('Y-m-d H:i:s')],
                'test2'=>['restart_count'=>11,'last_restart'=>date('Y-m-d H:i:s')],
            ],
        ];
        $message = [
            'test1'=>['sign'=>'restart','status'=>0],
            'test2'=>['sign'=>'stop','status'=>0],
        ];


        //$res = \app\common\lib\redisQueue::init(['select'=>6])->get('sxmonitor_serializelist');
        $res = \app\common\lib\redisQueue::init(['select'=>6])->set($listName,$message,100);
        echo $res."\r\n";
        $res = json_decode($res,true);

        var_dump($res);
exit();
        $a = array('sbc','def','ddf');
        $b = array('def','abc','ddffff');
        $c = array_merge($a,$b);
        var_dump($c);
        //array_unique($c);
        
        var_dump(array_unique($c));
        var_dump($c);
        exit();
        $up = new \app\index\lib\Update();
        $up->runUpdate();
        exit();
        
        $appconfig = config('ext.app_config');
        $mcUrl = $appconfig['sx_mc']['addr'].'/getopenid';
        
        $returnUrl = urlencode(url('test/Returned','','',true));
        $this->redirect($mcUrl.'?get_type=2&return_url='.$returnUrl);
    }
    public function testphone(){
        die;
        echo $start = microtime(true)."<br/>\r\n";
        for ($i=0; $i < 10000; $i++) { 
            $mobile = '1'.get_rand_string(10,1);
            $a = encodePhone($mobile,'123');
            $b = decodePhone($a,'123');
            echo $mobile.'<==>'.$a.'<-->'.$b.'=='.($mobile==$b?'true':'false')."\r\n";
        }
        echo $end = microtime(true)."<br/>\r\n";
        echo 'diff:'.($end - $start)."<br>\r\n";
        /*
        $mobile = '13288765243';
        $a = $this->encodePhone($mobile);
        $b = $this->decodePhone($a);
        var_dump($a);
        var_dump($b);
        */
    }
    
    public function returned() {
        echo 'in returned :';
        var_dump(array('code'=>input('code')));
        $wxUserInfo = sx_call('5a0e5f4ced930', array('code'=>input('code')));
        var_dump($wxUserInfo);
    }
    public function pushmsg() {
        $redis = new \Redis();
        $redis->pconnect('192.168.0.12',6379);
        session_write_close();
        $res = $redis->publish('testchannel','{"staff_id":"11","msg_type":"sysmsg","msg_content":"'.  rand(100, 10000).'"}');
        var_dump($res);

        $redis->close();
        
    }
    public function sms() {
        
        
        
        
//        
//        $msg = [
//            'staff_id'=>'11',
//            'msg_type'=>'sysmsg',
//            'msg_content'=>'abcdfg',
//        ];
////        var_dump(json_encode($msg));
////        exit();
////        {"staff_id":"11","msg_type":"sysmsg","msg_content":"abcdfg"}
////        var_dump(session('staff_id'));
////        exit();
//        $redis = new \Redis();
//        $redis->pconnect('192.168.0.12',6379);
//        //*
//        ini_set('default_socket_timeout', -1);
//        define('CURRENT_STAFF_ID', session('staff_id'));
//        session_write_close();
//        $res = $redis->subscribe(['testchannel'],'test_channel_receive');
//        var_dump($res);
        //*/
        
        $mobile = [
            '18801299602',
            '13515303738',
            '15652779741',
            '13466616328',
            '13683093357',
            '18811554188',
            '18810881529',
            '17600057068',
            '13146165882',
            '18518987225',
            '13641009570',
            '15311440759',
            '13681481018',
            '13051556508',
            '18810003398',
            '13146929216',
            '18501043684',
            '18701389821',
            '15010163858',
            '15210056193',
            
        ];
        /*
        $query = 'https://dx.ipyy.net/statusJsonApi.aspx';
        $post['action'] = 'query';
        
        $res = http_request($query, 'POST', $post);
        var_dump($res['response']);
        
        exit();
         * 
         */
        $mobile = ['13051556508','15652779741'];
        $mobile = ['13641009570'];
        //$this->smsIpyy($mobile);
        $this->queryipyy('1711213500145457');
    }
    public function sms5c($mobile) {
        $url = 'https://m.5c.com.cn/api/send/index.php';
        $post = [
            'username'=>$userId,
            'password_md5'=>md5('asdf1234'),
            'apikey'=>'7de4169df27880ce767b75cac0994dcd',
            'encode'=>'utf-8',
        ];
        foreach($mobile as $value){
            $post['mobile'] = $value;
            $content = '【素玄科技】您好，您的验证码：'.get_rand_string(6,1).'，请妥善保管。';
            $post['content'] = $content;
            $res = http_request($url, 'POST', $post);
            if($res['code'] == 200){
                //$response = json_decode($res['response'],true);
                $response = $res['response'];
                if(strpos('success', $response) === 0){
                    echo '手机号：'.$value.'发送成功。<br/>'."\r\n";
                }else{
                    echo '手机号：'.$value.'发送请求成功，服务器返回:'.$response.'。<br/>'."\r\n";
                }
                /*
                if(strtolower($response['returnstatus']) == 'success'){
                    echo '手机号：'.$value.'发送成功。<br/>'."\r\n";
                }else{
                    echo '手机号：'.$value.'发送请求成功，服务器返回失败。<br/>'."\r\n";
                }*/
            }else{
                echo '手机号：'.$value.'发送失败。<br/>'."\r\n";
            }
        }
    }
    public function smsIpyy($mobile=array()) {
        $url = 'https://dx.ipyy.net/smsJson.aspx';
         $post = [
            'userid'=>$userId,
            'account'=>'AA01269',
            'password'=>  md5('AA0126922'),//strtoupper(md5('AA0126902')),
            'content'=>$content,
            'action'=>'send',
            'extno'=>'',
        ];
        $postQuery = $post;
        $postQuery['statusNum'] = 4000;
        $postQuery['action'] = 'query';
        foreach($mobile as $value){
            $post['mobile'] = $value;
            $content = '【素玄科技】您此次的验证码为'.  get_rand_string(6,1).'，如非本人操作忽略此条短信';
            $post['content'] = $content;
            $res = http_request($url, 'POST', $post);
            if($res['code'] == 200){
                $response = json_decode($res['response'],true);
                if(strtolower($response['returnstatus']) == 'success'){
                    echo '手机号：'.$value.'发送成功。<br/>'.$response['taskID']."\r\n";
                    $queryUrl = 'https://dx.ipyy.net/statusJsonApi.aspx';
                    
                    $postQuery['taskid'] = $response['taskID'];
                    $qures = http_request($queryUrl, 'POST', $postQuery);
                    var_dump($qures['response']);
                    
                }else{
                    echo '手机号：'.$value.'发送请求成功，服务器返回失败。<br/>'."\r\n";
                }
            }else{
                echo '手机号：'.$value.'发送失败。<br/>'."\r\n";
                var_dump($qures['response']);
            }
        }
    }
    public function queryipyy($teskid) {
        $queryUrl = 'https://dx.ipyy.net/statusJsonApi.aspx';
        $queryUrl = 'https://dx.ipyy.net/callJsonApi.aspx';
        $post = [
            'userid'=>$userId,
            'account'=>'AA01269',
            'password'=>  md5('AA0126922'),//strtoupper(md5('AA0126902')),
            'content'=>$content,
            'action'=>'send',
            'extno'=>'',
        ];
        $postQuery = $post;
        $postQuery['statusNum'] = 4000;
        $postQuery['action'] = 'query';
        //$postQuery['taskid'] = $teskid;
        $qures = http_request($queryUrl, 'POST', $postQuery);
        var_dump($qures['response']);
        
        
        
    }
}

