Example #1
0
 /**
  * Constructor
  * 
  * @param array $curlOpts 用于内部http包装对象使用的全局curl参数.
  */
 function __construct($curlOpts = array())
 {
     date_default_timezone_set('Asia/Shanghai');
     self::$suppressException = BAIDU_PUSH_CONFIG::SUPPRESS_EXCPTION;
     $this->log = new PushSimpleLog(BAIDU_PUSH_CONFIG::LOG_OUTPUT, BAIDU_PUSH_CONFIG::LOG_LEVEL);
     try {
         $this->http = new HttpRequest(BAIDU_PUSH_CONFIG::HOST, $curlOpts, $this->log);
         $this->log->log("HttpRequest: ready to work...");
     } catch (Exception $e) {
         $this->log->fault($e->__toString());
         die;
     }
     $this->assert = new AssertHelper();
     $this->signExpires = intval(BAIDU_PUSH_CONFIG::SIGN_EXPIRES);
     $this->log->log("SDK: initializing...");
 }
Example #2
0
 /**
  * Constructor
  *
  * @param string $apiKey
  *        开发者apikey, 由开发者中心(http://developer.baidu.com)获取
  * @param string $secretKey
  *        开发者当前secretKey, 在应用重新生成secret key后, 旧的secret key将失效, 由开发者中心(http://developer.baidu.com)获取.
  * @param array $curlopts
  *        用于cUrl::curl_setopt方法的控制参数.
  * @link http://php.net/manual/zh/function.curl-setopt.php (curl_setopt相关内容)
  */
 function __construct($apiKey = null, $secretKey = null, $curlopts = array())
 {
     if ($apiKey !== null && $secretKey !== null) {
         $this->setApiKey($apiKey);
         $this->setSecretKey($secretKey);
     } else {
         if ($apiKey !== null || $secretKey !== null) {
             $loss = $apiKey == null ? 'apikey' : 'secretKey';
             throw new Exception("need {$loss}.");
         } else {
             $this->setApiKey(BAIDU_PUSH_CONFIG::default_apiKey);
             $this->setSecretKey(BAIDU_PUSH_CONFIG::default_secretkey);
         }
     }
     parent::__construct($curlopts);
     $this->log->log("SDK ready to work !!");
 }
Example #3
0
 /**
  * @depends testCreateBaseSdk
  * @param BaseSDK $sdk
  */
 public function testSendRequest($sdk)
 {
     $rs = $sdk->sendRequest($this->testUrl, array('q' => 'checkSign', 'a' => 100, 'b' => 200));
     $this->assertNotNull($rs);
     // will be null
     $sign = $rs['sign'];
     unset($rs['sign']);
     $checkSign = $sdk->genSign('POST', $this->testUrl, $rs);
     $this->assertEquals($sign, $checkSign, 'check sign failed!');
 }