<?php
//namespace ThinkPHP\Library\Vendor\JPush;
require 'autoload.php';
class JPush
{
    // private $appKey = 'ac3355cc4a9342e34869b6e1';
      // private $masterSecret = '9c235d2bbbb7f49540490544';
    private $appKey = '401c98fa2bf86a95c845c257';
    private $masterSecret = '3375e107cb59188a0bf1eaa0';
    private $client;

    public function __construct(){
        $this->client = new \JPush\Client($this->appKey, $this->masterSecret);
    }


    public function openDoor($serial_no,$boxs){
        $data = array(
				"alert"=>"open door",
				"type"=>"1",//1开锁 2升级
				"lock"=>$boxs
		);
		$msg = json_encode($data);

        $pusher = $this->client->push();
        $pusher->setPlatform('all');
        $pusher->addAlias($serial_no);
        $pusher->setMessage($msg);
        return $res = $pusher->send();
        try {
            $res = $pusher->send();
            
            if($res['http_code']==200)
                return true;
            else
                return false;
            //print_pre($res);
        } catch (\JPush\Exceptions\JPushException $e) {
            //print $e;
            return false;
        }
    }


    public function printBarcode($serial_no,$out_trade_no){
    	$data = array(
    			"alert"=>"prict barcode",
    			"type"=>"3",//1开锁 2升级
    			"out_trade_no"=>$out_trade_no
    	);
    	$msg = json_encode($data);

    	$pusher = $this->client->push();
    	$pusher->setPlatform('all');
    	$pusher->addAlias($serial_no);
    	$pusher->setMessage($msg);
    	try {
    		$res = $pusher->send();
    		if($res['http_code']==200)
    			return true;
    		else
    			return false;
    		//print_pre($res);
    	} catch (\JPush\Exceptions\JPushException $e) {
    		//print $e;
    		return false;
    	}
    }
}

?>
