Ejemplo n.º 1
0
 private function push($registrationList, $data, $accountId)
 {
     $setting = KlpAccountSetting::findOne(['accountId' => new \MongoId($accountId)]);
     if (empty($setting) || !isset($setting->gcmKey) || empty($setting->gcmKey)) {
         return null;
     }
     $apiKey = $setting->gcmKey;
     if (!is_array($data)) {
         $data = ['message' => $data];
     }
     $body = ['registration_ids' => $registrationList, 'data' => $data];
     $response = null;
     try {
         $response = Yii::$app->curl->setHeaders(['Content-Type: application/json', 'Authorization: key=' . $apiKey])->setOption(CURLOPT_PROXY, "sgsgprxs000.unileverservices.com")->setOption(CURLOPT_PROXYPORT, 3128)->post('https://gcm-http.googleapis.com/gcm/send', json_encode($body));
     } catch (Exception $e) {
         $response = $e->getMessage();
     }
     $this->saveLog($body, $response, $accountId);
     return $response;
 }
Ejemplo n.º 2
0
 public static function getAccountSite($accountId)
 {
     $setting = KlpAccountSetting::findOne(['accountId' => $accountId]);
     return $setting->site;
 }