private function push($deviceToken, $msg, $accountId) { $content = $msg["content"]; unset($msg["content"]); $body = array("aps" => array('alert' => $content, 'badge' => 1, 'sound' => 'default', 'extra' => $msg)); $payload = json_encode($body); $msg = chr(0) . chr(0) . chr(32) . pack('H*', str_replace(' ', '', $deviceToken)) . chr(0) . chr(strlen($payload)) . $payload; $response = 0; $site = KlpAccountSetting::getAccountSite($accountId); //$site = 'TW'; if ($site == 'HK') { $response = $this->getHKfp(); } else { $response = $this->getTWfp(); } if ($response == 200) { if ($site == 'HK') { fwrite($this->hkfp, $msg); } else { fwrite($this->twfp, $msg); } } LogUtil::error('iOS push result: ' . $response); $this->saveLog($body, $response, $accountId); return $response; }
public function actionGetList() { $this->_setJSONFormat(Yii::$app); $data = Yii::$app->request->post(); $currentPage = $data['currentPage']; $pageSize = $data['pageSize']; $offset = ($currentPage - 1) * $pageSize; // $offSetRight = $currentPage * $pageSize - 1; // $product = new Product(); // $dataCount = $product->getCount(['accountId' => $this->getAccountId()]); // $products = $product->getList($data['currentPage'], $data['pageSize'], ['accountId' => $this->getAccountId()]); // $products = [ // // ['name' => 'abc', 'tag' => 'a', 'url' => 'http://aa'], // // ['name' => 'abc', 'tag' => 'b', 'url' => 'http://aa'], // // ['name' => 'abc', 'tag' => 'c', 'url' => 'http://cc'] // ]; $site = KlpAccountSetting::getAccountSite($this->getAccountId()); if ($site == 'TW') { $allProducts = (require dirname(__FILE__) . '/../' . 'ProductTW.php'); } else { $allProducts = (require dirname(__FILE__) . '/../' . 'ProductHK.php'); } $products = array_slice($allProducts, $offset, $pageSize); $dataCount = sizeof($allProducts); $resData = ['dataCount' => $dataCount, 'product' => $products]; return $resData; }
public static function getProductByName($name, $accountId) { //Token::getToken() // $query = new Query(); // $one = $query->from(self::collectionName())->select(['url'])->where(['accountId' => $accountId, 'name' => $name])->one(); // if ($one) { // return $one['url']; // } else { // return ''; // } $site = KlpAccountSetting::getAccountSite(new \MongoId($accountId)); if ($site == 'TW') { $products = (require dirname(__FILE__) . '/../' . 'ProductTW.php'); } else { $products = (require dirname(__FILE__) . '/../' . 'ProductHK.php'); } foreach ($products as $product) { $productName = trim(explode('(', $product['name'], 2)[0]); $name = trim(explode('(', $name, 2)[0]); $productName = trim(explode('(', $product['name'], 2)[0]); $name = trim(explode('(', $name, 2)[0]); if ($productName == $name) { return $product; } } return []; }
public function actionToJson() { sleep(3); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; $request = Yii::$app->request; $fileB64 = $request->post('fileB64'); $file = base64_decode(substr($fileB64, strpos($fileB64, ";base64,") + 8)); $filePath = Yii::getAlias('@runtime') . '/namelist' . date('his'); file_put_contents($filePath, $file); // $phpExcel = new \PHPExcel(); $phpReader = new \PHPExcel_Reader_Excel2007(); if (!$phpReader->canRead($filePath)) { $phpReader = new \PHPExcel_Reader_Excel5(); if (!$phpReader->canRead($filePath)) { $phpReader = new \PHPExcel_Reader_CSV(); if (!$phpReader->canRead($filePath)) { unlink($filePath); return ['fileError' => true]; } } } $phpExcel = $phpReader->load($filePath); $sheet = $phpExcel->getActiveSheet(); $colCount = $sheet->getHighestColumn(); $rowCount = $sheet->getHighestRow(); $data = []; for ($row = 1; $row <= $rowCount; $row++) { for ($col = 'A'; $col <= $colCount; $col++) { $val = $sheet->getCellByColumnAndRow(ord($col) - 65, $row)->getValue(); $val = (string) $val; if ($val) { $accountId = $this->getAccountId(); $site = KlpAccountSetting::getAccountSite($accountId); if ($site == 'TW') { if ($val[0] !== '0') { $val = '0' . $val; } } $data[] = $val; } } } unlink($filePath); $numError = $this->_checkData($data); if (!empty($numError)) { return $numError; } return array_unique($data); }
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; }
public static function processSmsMobile($accountId, $mobile) { $site = KlpAccountSetting::getAccountSite($accountId); if ($site == 'TW') { // DO nothing } else { if ($site == 'HK') { if (strlen($mobile) == 8) { $mobile = '852' . $mobile; } } } unset($site); return $mobile; }
public function actionGetAccountSetting() { $site = KlpAccountSetting::getAccountSite($this->getAccountId()); Yii::$app->response->format = \yii\web\Response::FORMAT_JSON; return ['site' => $site]; }
public static function getAccountSite($accountId) { $setting = KlpAccountSetting::findOne(['accountId' => $accountId]); return $setting->site; }