1
0
Fork 0
mirror of https://github.com/janickiy/yii2-nomer synced 2025-03-09 15:39:59 +00:00

add files to project

This commit is contained in:
janickiy 2020-02-05 06:34:26 +03:00
commit 5cac498444
3729 changed files with 836998 additions and 0 deletions

13
modules/api/ApiModule.php Normal file
View file

@ -0,0 +1,13 @@
<?php
namespace app\modules\api;
use yii\base\Module;
class ApiModule extends Module
{
public $controllerNamespace = 'app\modules\api\controllers';
public $defaultRoute = 'search';
public $layout = null;
}

View file

@ -0,0 +1,435 @@
<?php
namespace app\modules\api\controllers;
use app\models\Payment;
use app\models\User;
use app\models\UserSub;
use Exception;
use Yii;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\rest\Controller;
use yii\web\BadRequestHttpException;
use ReceiptValidator\iTunes\Validator as iTunesValidator;
use ReceiptValidator\GooglePlay\Validator as PlayValidator;
class BuyController extends Controller
{
public function actionStatus()
{
/*
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
if (!$uuid) {
throw new BadRequestHttpException();
}
$user = User::find()->select(["id", "balance", "checks"])->where(["uuid" => $uuid])->one();
if (!$user) {
$user = new User();
$user->email = null;
$user->uuid = $uuid;
$user->save();
$user = User::find()->select(["id", "balance", "checks"])->where(["uuid" => $uuid])->one();
}
*/
$f = fopen(\Yii::getAlias('@runtime') . '/apple.log', 'a+');
$data = Json::decode(\Yii::$app->request->getRawBody());
//$data = Yii::$app->request->getBodyParams();
//$receiptBase64Data = ArrayHelper::getValue($data, "receipt");//'ewoJInNpZ25hdHVyZSIgPSAiQXBNVUJDODZBbHpOaWtWNVl0clpBTWlKUWJLOEVkZVhrNjNrV0JBWHpsQzhkWEd1anE0N1puSVlLb0ZFMW9OL0ZTOGNYbEZmcDlZWHQ5aU1CZEwyNTBsUlJtaU5HYnloaXRyeVlWQVFvcmkzMlc5YVIwVDhML2FZVkJkZlcrT3kvUXlQWkVtb05LeGhudDJXTlNVRG9VaFo4Wis0cFA3MHBlNWtVUWxiZElWaEF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FeUlqc0tDU0ppYVdRaUlEMGdJbU52YlM1dGFXNWtiVzlpWVhCd0xrMXBibVJOYjJJaU93b0pJbkIxY21Ob1lYTmxMV1JoZEdVdGJYTWlJRDBnSWpFek16VTNPVGd6TlRVNE5qZ2lPd29KSW5CMWNtTm9ZWE5sTFdSaGRHVWlJRDBnSWpJd01USXRNRFF0TXpBZ01UVTZNRFU2TlRVZ1JYUmpMMGROVkNJN0Nna2ljSFZ5WTJoaGMyVXRaR0YwWlMxd2MzUWlJRDBnSWpJd01USXRNRFF0TXpBZ01EZzZNRFU2TlRVZ1FXMWxjbWxqWVM5TWIzTmZRVzVuWld4bGN5STdDZ2tpYjNKcFoybHVZV3d0Y0hWeVkyaGhjMlV0WkdGMFpTSWdQU0FpTWpBeE1pMHdOQzB6TUNBeE5Ub3dOVG8xTlNCRmRHTXZSMDFVSWpzS2ZRPT0iOwoJImVudmlyb25tZW50IiA9ICJTYW5kYm94IjsKCSJwb2QiID0gIjEwMCI7Cgkic2lnbmluZy1zdGF0dXMiID0gIjAiOwp9';
$type = ArrayHelper::getValue($data, "notification_type");
$env = ArrayHelper::getValue($data, "environment");
fwrite($f, print_r($data, true) . "\n");
if(!in_array($type, ["INTERACTIVE_RENEWAL", "RENEWAL"])) return [];
$p = ArrayHelper::getValue($data, "latest_receipt_info");
$uuid = ArrayHelper::getValue($p, "unique_vendor_identifier");
fwrite($f, print_r($p, true) . "\n");
$originalTransactionID = (string)ArrayHelper::getValue($p, "original_transaction_id");
$sub = UserSub::find()->where(["original_transaction_id" => $originalTransactionID])->one();
$user = null;
if($sub) {
$user = User::find()->where(["id" => $sub->user_id])->one();
}
$transactionID = (string)ArrayHelper::getValue($p, "transaction_id");
$productID = (string)ArrayHelper::getValue($p, "product_id");
$payment = Payment::find()->where(["operation_id" => $transactionID])->one();
if (!$payment) {
$payment = new Payment();
$payment->user_id = ArrayHelper::getValue($user, "id", null);
$payment->tm = new Expression('NOW()');
if ($env == "PROD") {
$payment->type_id = Payment::TYPE_APPLE;
} else {
$payment->type_id = Payment::TYPE_TESTAPPLE;
}
$payment->operation_label = $productID;
$payment->operation_id = $transactionID;
$sum = 0;
$checks = 0;
if (preg_match("/com\.wcaller\.Wcaller\.search(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 1:
$sum = 149;
break;
case 10:
$sum = 749;
break;
case 100:
$sum = 3490;
break;
case 300:
$sum = 8990;
break;
case 30:
$sum = 1390;
break;
}
$checks = $m[1];
}
$isSubscribe = false;
if (preg_match("/com\.wcaller\.Wcaller\.sub\.month\.(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 0:
$sum = 2750;
break;
case 10:
$sum = 199;
break;
case 15:
$sum = 299;
break;
case 50:
$sum = 499;
break;
case 999:
$sum = 1690;
break;
}
$checks = $m[1];
$isSubscribe = true;
}
if (preg_match("/com\.wcaller\.Wcaller\.sub\.6month\.(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 0:
$sum = 6190;
break;
}
$checks = $m[1];
$isSubscribe = true;
}
if (preg_match("/com\.wcaller\.Wcaller\.sub\.week\.(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 0:
$sum = 499;
break;
case 999:
$sum = 249;
break;
}
$checks = $m[1];
$isSubscribe = true;
}
if($checks == 0 || $checks == 999) $checks = -1;
$payment->sum = $sum;
$payment->amount = $sum * 0.59;
if ($payment->save()) {
if ($isSubscribe) {
$sub = new UserSub();
$sub->user_id = $user->id;
$sub->transaction_id = ArrayHelper::getValue($p, "transaction_id");
$sub->original_transaction_id = ArrayHelper::getValue($p, "original_transaction_id");
$sub->tm_purchase = \Yii::$app->formatter->asDatetime(ArrayHelper::getValue($p, "purchase_date"), "yyyy-MM-dd HH:mm:ss");
$sub->tm_expires = \Yii::$app->formatter->asDatetime(ArrayHelper::getValue($p, "expires_date")/1000, "yyyy-MM-dd HH:mm:ss");
$sub->status = ArrayHelper::getValue($p, "is_trial_period")?0:1;
$sub->save();
}
$user->checks = $checks;
$user->save();
}
}
fclose($f);
return "OK";
}
public function actionIndex()
{
$userId = \Yii::$app->getRequest()->post("id", false);
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
if (!$uuid && !$userId) {
throw new BadRequestHttpException();
}
if ($userId) {
$user = User::find()->select(["id", "balance", "checks"])->where(["id" => $userId])->one();
} else {
$user = User::find()->select(["id", "balance", "checks"])->where(["uuid" => $uuid])->one();
}
if (!$user) {
$user = new User();
$user->email = null;
$user->uuid = $uuid;
$user->save();
$user = User::find()->select(["id", "balance", "checks"])->where(["uuid" => $uuid])->one();
}
$isAndroid = Yii::$app->getRequest()->getHeaders()->get('isandroid', false);
if ($isAndroid) {
$client = new \Google_Client();
$client->setApplicationName('nomergg');
$client->setAuthConfig(\Yii::getAlias('@runtime') . '/nomergg-2842ed9066f5.json');
$client->setScopes([\Google_Service_AndroidPublisher::ANDROIDPUBLISHER]);
$validator = new PlayValidator(new \Google_Service_AndroidPublisher($client));
$packageName = \Yii::$app->request->post("packageName");
$productId = \Yii::$app->request->post("productId");
$orderId = \Yii::$app->request->post("orderId");
$purchaseToken = \Yii::$app->request->post("purchaseToken");
try {
$response = $validator->setPackageName($packageName)
->setProductId($productId)
->setPurchaseToken($purchaseToken)
->validatePurchase();
if (preg_match("/com\.nomergg\.app\.search(\d+)/", $productId, $m)) {
$user->checks += $m[1];
if ($user->save()) {
$payment = new Payment();
$payment->user_id = $user->id;
$payment->tm = new Expression('NOW()');
$payment->type_id = Payment::TYPE_ANDROID;
$payment->operation_id = (string)$orderId;
$payment->operation_label = $productId;
$sum = 0;
switch ($m[1]) {
case 1:
$sum = 98;
break;
case 10:
$sum = 880;
break;
case 100:
$sum = 6800;
break;
case 30:
$sum = 2340;
break;
case 20:
$sum = 1660;
break;
}
$payment->sum = $sum;
$payment->amount = $sum * 0.7;
$payment->save();
}
}
} catch (Exception $e) {
var_dump($e->getMessage());
// example message: Error calling GET ....: (404) Product not found for this application.
}
} else {
$f = fopen(\Yii::getAlias('@runtime') . '/ios.log', 'a+');
fwrite($f, $uuid . "\n");
$validator = new iTunesValidator(iTunesValidator::ENDPOINT_PRODUCTION);
$data = Json::decode(\Yii::$app->request->getRawBody());
//$data = Yii::$app->request->getBodyParams();
$source = ArrayHelper::getValue($data, "source", "");
$receiptBase64Data = ArrayHelper::getValue($data, "receipt");//'ewoJInNpZ25hdHVyZSIgPSAiQXBNVUJDODZBbHpOaWtWNVl0clpBTWlKUWJLOEVkZVhrNjNrV0JBWHpsQzhkWEd1anE0N1puSVlLb0ZFMW9OL0ZTOGNYbEZmcDlZWHQ5aU1CZEwyNTBsUlJtaU5HYnloaXRyeVlWQVFvcmkzMlc5YVIwVDhML2FZVkJkZlcrT3kvUXlQWkVtb05LeGhudDJXTlNVRG9VaFo4Wis0cFA3MHBlNWtVUWxiZElWaEFBQURWekNDQTFNd2dnSTdvQU1DQVFJQ0NHVVVrVTNaV0FTMU1BMEdDU3FHU0liM0RRRUJCUVVBTUg4eEN6QUpCZ05WQkFZVEFsVlRNUk13RVFZRFZRUUtEQXBCY0hCc1pTQkpibU11TVNZd0pBWURWUVFMREIxQmNIQnNaU0JEWlhKMGFXWnBZMkYwYVc5dUlFRjFkR2h2Y21sMGVURXpNREVHQTFVRUF3d3FRWEJ3YkdVZ2FWUjFibVZ6SUZOMGIzSmxJRU5sY25ScFptbGpZWFJwYjI0Z1FYVjBhRzl5YVhSNU1CNFhEVEE1TURZeE5USXlNRFUxTmxvWERURTBNRFl4TkRJeU1EVTFObG93WkRFak1DRUdBMVVFQXd3YVVIVnlZMmhoYzJWU1pXTmxhWEIwUTJWeWRHbG1hV05oZEdVeEd6QVpCZ05WQkFzTUVrRndjR3hsSUdsVWRXNWxjeUJUZEc5eVpURVRNQkVHQTFVRUNnd0tRWEJ3YkdVZ1NXNWpMakVMTUFrR0ExVUVCaE1DVlZNd2daOHdEUVlKS29aSWh2Y05BUUVCQlFBRGdZMEFNSUdKQW9HQkFNclJqRjJjdDRJclNkaVRDaGFJMGc4cHd2L2NtSHM4cC9Sd1YvcnQvOTF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nlZVzV6WVdOMGFXOXVMV2xrSWlBOUlDSXhNREF3TURBd01EUTJNVGM0T0RFM0lqc0tDU0ppZG5KeklpQTlJQ0l5TURFeU1EUXlOeUk3Q2draWRISmhibk5oWTNScGIyNHRhV1FpSUQwZ0lqRXdNREF3TURBd05EWXhOemc0TVRjaU93b0pJbkYxWVc1MGFYUjVJaUE5SUNJeElqc0tDU0p2Y21sbmFXNWhiQzF3ZFhKamFHRnpaUzFrWVhSbExXMXpJaUE5SUNJeE16TTFOems0TXpVMU9EWTRJanNLQ1NKd2NtOWtkV04wTFdsa0lpQTlJQ0pqYjIwdWJXbHVaRzF2WW1Gd2NDNWtiM2R1Ykc5aFpDSTdDZ2tpYVhSbGJTMXBaQ0lnUFNBaU5USXhNVEk1T0RFeUlqc0tDU0ppYVdRaUlEMGdJbU52YlM1dGFXNWtiVzlpWVhCd0xrMXBibVJOYjJJaU93b0pJbkIxY21Ob1lYTmxMV1JoZEdVdGJYTWlJRDBnSWpFek16VTNPVGd6TlRVNE5qZ2lPd29KSW5CMWNtTm9ZWE5sTFdSaGRHVWlJRDBnSWpJd01USXRNRFF0TXpBZ01UVTZNRFU2TlRVZ1JYUmpMMGROVkNJN0Nna2ljSFZ5WTJoaGMyVXRaR0YwWlMxd2MzUWlJRDBnSWpJd01USXRNRFF0TXpBZ01EZzZNRFU2TlRVZ1FXMWxjbWxqWVM5TWIzTmZRVzVuWld4bGN5STdDZ2tpYjNKcFoybHVZV3d0Y0hWeVkyaGhjMlV0WkdGMFpTSWdQU0FpTWpBeE1pMHdOQzB6TUNBeE5Ub3dOVG8xTlNCRmRHTXZSMDFVSWpzS2ZRPT0iOwoJImVudmlyb25tZW50IiA9ICJTYW5kYm94IjsKCSJwb2QiID0gIjEwMCI7Cgkic2lnbmluZy1zdGF0dXMiID0gIjAiOwp9';
fwrite($f, print_r($data, true) . "\n");
//return [""$receiptBase64Data;
try {
$response = $validator->validate($receiptBase64Data, "63baa92164f4400699f78f32dded316f");
} catch (Exception $e) {
throw new BadRequestHttpException($e->getMessage());
}
if ($response->isValid()) {
$data = $response->getReceipt();
fwrite($f, print_r($data, true) . "\n");
//print_r($data);
$products = $data["in_app"];
foreach ($products as $p) {
$transactionID = (string)ArrayHelper::getValue($p, "transaction_id");
$productID = (string)ArrayHelper::getValue($p, "product_id");
$payment = Payment::find()->where(["operation_id" => $transactionID])->one();
if (!$payment) {
$payment = new Payment();
$payment->user_id = $user->id;
$payment->tm = new Expression('NOW()');
if (ArrayHelper::getValue($data, "receipt_type") == "ProductionSandbox") {
$payment->type_id = Payment::TYPE_TESTAPPLE;
} else {
$payment->type_id = Payment::TYPE_APPLE;
}
$payment->operation_label = $productID;
$payment->operation_id = $transactionID;
$payment->source = $source;
$sum = 0;
$checks = 0;
if (preg_match("/com\.wcaller\.Wcaller\.search(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 1:
$sum = 149;
break;
case 10:
$sum = 749;
break;
case 100:
$sum = 3490;
break;
case 300:
$sum = 8990;
break;
case 30:
$sum = 1390;
break;
}
$checks = $m[1];
}
$isSubscribe = false;
if (preg_match("/com\.wcaller\.Wcaller\.sub\.month\.(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 0:
$sum = 2750;
break;
case 10:
$sum = 199;
break;
case 15:
$sum = 299;
break;
case 50:
$sum = 499;
break;
case 999:
$sum = 1690;
}
$checks = $m[1];
$isSubscribe = true;
}
if (preg_match("/com\.wcaller\.Wcaller\.sub\.6month\.(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 0:
$sum = 6190;
break;
}
$checks = $m[1];
$isSubscribe = true;
}
if (preg_match("/com\.wcaller\.Wcaller\.sub\.week\.(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 0:
$sum = 499;
break;
case 999:
$sum = 249;
break;
}
$checks = $m[1];
$isSubscribe = true;
}
if($checks == 0 || $checks == 999) $checks = -1;
$payment->sum = $sum;
$payment->amount = $sum * 0.59;
if ($payment->save()) {
if ($isSubscribe) {
$sub = new UserSub();
$sub->user_id = $user->id;
$sub->transaction_id = ArrayHelper::getValue($p, "transaction_id");
$sub->original_transaction_id = ArrayHelper::getValue($p, "original_transaction_id");
$sub->tm_purchase = \Yii::$app->formatter->asDatetime(ArrayHelper::getValue($p, "purchase_date"), "yyyy-MM-dd HH:mm:ss");
$sub->tm_expires = \Yii::$app->formatter->asDatetime(ArrayHelper::getValue($p, "expires_date"), "yyyy-MM-dd HH:mm:ss");
$sub->status = ArrayHelper::getValue($p, "is_trial_period")?0:1;
$sub->save();
}
$user->checks += $checks;
$user->save();
}
} else {
if($payment->user_id != $user->id) {
$payment->user_id = $user->id;
$payment->save();
}
$sub = UserSub::find()->where(["transaction_id" => ArrayHelper::getValue($p, "transaction_id")])->one();
if($sub && $sub->user_id != $user->id) {
$sub->user_id = $user->id;
$sub->save();
$checks = null;
if (preg_match("/com\.wcaller\.Wcaller\.sub\.month\.(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 0:
$sum = 2750;
break;
case 10:
$sum = 199;
break;
case 15:
$sum = 299;
break;
case 50:
$sum = 499;
break;
case 999:
$sum = 1690;
}
$checks = $m[1];
$isSubscribe = true;
}
if (preg_match("/com\.wcaller\.Wcaller\.sub\.6month\.(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 0:
$sum = 6190;
break;
}
$checks = $m[1];
$isSubscribe = true;
}
if (preg_match("/com\.wcaller\.Wcaller\.sub\.week\.(\d+)/", $productID, $m)) {
switch ($m[1]) {
case 0:
$sum = 499;
break;
case 999:
$sum = 249;
break;
}
$checks = $m[1];
$isSubscribe = true;
}
if($checks == 0 || $checks == 999) $checks = -1;
$user->checks = $checks;
$user->save();
}
}
}
//product_id
//echo 'Receipt is valid.' . PHP_EOL;
//echo 'Receipt data = ' . print_r($response->getReceipt()) . PHP_EOL;
} else {
fwrite($f, "invalid data\n");
}
fclose($f);
}
return [
"id" => $user->id,
"balance" => $user->balance,
"checks" => $user->checks
];
}
}

View file

@ -0,0 +1,56 @@
<?php
namespace app\modules\api\controllers;
use app\models\Call;
use app\models\User;
use Yii;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\helpers\Url;
use yii\rest\Controller;
class CallController extends Controller {
public function actionIndex() {
$body = \Yii::$app->request->getRawBody();
$body = Json::decode($body);
$call = new Call();
$call->cuid = ArrayHelper::getValue($body, 'cuid');
$call->status = ArrayHelper::getValue($body, 'status');
$call->duration = ArrayHelper::getValue($body, 'duration');
$call->phone = ArrayHelper::getValue($body, 'number');
$call->tm = new Expression('NOW()');
$call->save();
if($call->status == "dtmf-1") {
$user = User::find()->where(["email" => $call->phone])->one();
if(!$user) {
$code = sprintf("%'.04d", rand(0, 9999));
$user = new User();
$user->email = $call->phone;
$user->password = $code;
$user->auth_key = \Yii::$app->getSecurity()->generateRandomString();
$user->checks = 3;
if($user->save()) {
$user->checks = 3;
$user->save();
$url = Url::to(['https://smsc.ru/sys/send.php',
'login' => 'admeo',
'psw' => 'admeosmsc',
'phones' => $call->phone,
'mes' => "Probiv nomera telefona(3 besplatnye proverki):\nhttps://num.gg\nlogin:".$user->email."\npass:".$user->password,
'charset' => 'utf-8',
'sender' => 'num.gg'
], 'https');
file_get_contents($url);
}
}
}
}
}

View file

@ -0,0 +1,84 @@
<?php
namespace app\modules\api\controllers;
use app\models\TmpVk;
use app\models\Vk;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\rest\Controller;
use yii\web\BadRequestHttpException;
use yii\web\ForbiddenHttpException;
class CheckController extends Controller {
private $tokens = [
"vMnP2BEx1vlKk7cLAKCBgbNVuBArl3xb" => "antiparkon"
];
public function actionIndex($phone, $token) {
if(!array_key_exists($token, $this->tokens)) throw new ForbiddenHttpException("Bad token");
if(!preg_match("/^79([0-9]{9})$/", $phone)) throw new BadRequestHttpException("Invalid phone number");
return ["success" => 1];
$success = 0;
$ch = curl_init('http://ssd.nomer.io/api/' . $phone . '?token=NWBpdeqbbAFJMVYJU6XAfhyydeyhgX');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
$phones = [];
if ($httpCode == 200) { // Все ок, берем данные
$response = Json::decode($response);
foreach ($response as $r) {
if(isset($r["type"])) {
switch ($r["type"]) {
case "profile_id":
$success = 1;
break;
case "phone":
$phones[] = $r["data"];
break;
}
}
}
}
if($success) {
return ["success" => $success];
}
$ids = [];
foreach ($phones as $_phone) {
$vk = TmpVk::find()->where(['phone' => $_phone])->all();
if(count($vk)) {
$success = 1;
$ids = ArrayHelper::merge($ids, ArrayHelper::getColumn($vk, "id"));
}
}
$vkrows = Vk::find()->where(["or",
["phone1" => $phone],
["phone2" => $phone],
])->all();
$ids = ArrayHelper::merge($ids, ArrayHelper::getColumn($vkrows, "id"));
if(count($ids)) {
$success = 1;
}
$photos = [];
$socData = @file_get_contents("https://api.vk.com/method/users.get?user_ids=" . join(",", $ids) . "&fields=photo_id,photo_max,photo_max_orig&lang=ru&access_token=8f95fab19fb8d3d41bdeeb28f0112cb2cd3c86a93fc66acbd29f327d1aa3f196540bfe10dcd4ca97baf37");
if($socData) {
$socData = Json::decode($socData);
$socData = $socData["response"];
$photos = ArrayHelper::getColumn($socData, "photo_max_orig");
}
return ["success" => $success, "photos" => $photos];
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace app\modules\api\controllers;
use app\models\Ticket;
use app\models\User;
use Yii;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\rest\Controller;
use yii\web\BadRequestHttpException;
class ContactController extends Controller {
public $enableCsrfValidation = false;
public function actionIndex() {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
if(!$uuid) {
throw new BadRequestHttpException();
}
$user = User::find()->where(["uuid" => $uuid])->one();
$ticket = new Ticket();
$ticket->detachBehavior("user_id");
$ticket->user_id = $user->id;
$rawBody = \Yii::$app->request->getRawBody();
$email = \Yii::$app->request->post("email", null);
if($email) {
$message = \Yii::$app->request->post("message");
} else {
$data = Json::decode($rawBody);
$message = ArrayHelper::getValue($data,"message");
$email = ArrayHelper::getValue($data,"email");
}
$ticket->text = $message."\n\n".$email;
$ticket->tm_create = new Expression('NOW()');
$ticket->subject_id = 1;
$ticket->subject = "Сообщение из iOS приложения";
$ticket->save(false);
return ["success" => \Yii::$app->mailer->compose()
->setTextBody("E-mail: ".$email."\n\n\n".$message)
->setFrom('noreply@'.\Yii::$app->name)
->setTo("support@nomer.io")
->setSubject(\Yii::$app->name." - обратная связь")
->send()];
}
}

View file

@ -0,0 +1,54 @@
<?php
namespace app\modules\api\controllers;
use app\models\Free;
use app\models\User;
use Yii;
use yii\db\Expression;
use yii\rest\Controller;
use yii\web\BadRequestHttpException;
class FreeController extends Controller {
public function actionIndex() {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
if(!$uuid) {
throw new BadRequestHttpException();
}
$typeID = \Yii::$app->request->get("type_id");
if(!in_array($typeID, Free::types())) {
throw new BadRequestHttpException();
}
$user = User::find()->where(["uuid" => $uuid])->one();
if(!$user) {
$user = new User();
$user->email = null;
$user->uuid = $uuid;
$user->save();
}
$free = Free::find()->where(["uuid" => $uuid, "type_id" => $typeID])->one();
if($free) return ["success" => 0];
else {
$free = new Free();
$free->uuid = $uuid;
$free->user_id = $user->id;
$free->tm = new Expression('NOW()');
$free->type_id = $typeID;
if($free->type_id == Free::TYPE_INSTALL) {
$free->checks = 1;
} else if($free->type_id == Free::TYPE_RATE) {
$free->checks = 2;
}
if($free->save()) {
$user->checks += $free->checks;
$user->save();
}
return ["success" => 1];
}
}
}

View file

@ -0,0 +1,95 @@
<?php
namespace app\modules\api\controllers;
use app\models\RequestResult;
use app\models\ResultCache;
use app\models\SearchRequest;
use app\models\User;
use Yii;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\rest\Controller;
use yii\web\BadRequestHttpException;
class HistoryController extends Controller {
public function actionIndex() {
$userId = Yii::$app->request->get("id", false);
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
if(!$uuid && !$userId) {
throw new BadRequestHttpException();
}
/* @var $user User */
if($userId) {
$user = User::find()->where(["id" => $userId])->one();
if($uuid) {
$user->uuid = $uuid;
$user->save();
}
} elseif($uuid) {
$user = User::find()->where(compact('uuid'))->one();
if (!$user) {
$user = new User();
$user->email = null;
$user->uuid = $uuid;
$user->save();
}
}
$data = [];
foreach(SearchRequest::find()->where(["user_id" => $user->id])->orderBy(["id" => SORT_DESC])->limit(20)->all() as $sr) {
$operatorRow = RequestResult::find()->where(["request_id" => $sr->id, "type_id" => ResultCache::TYPE_OPERATOR])->one();
$operator = [];
if($operatorRow) {
$operator = Json::decode($operatorRow->data);
}
$names = [];
$namesRows = RequestResult::find()->where(["request_id" => $sr->id, "type_id" => [
ResultCache::TYPE_TRUECALLER,
ResultCache::TYPE_NUMBUSTER
]])->all();
foreach ($namesRows as $namesRow) {
$nameData = Json::decode($namesRow->data);
$names = ArrayHelper::merge($names, ArrayHelper::getColumn($nameData, "name"));
}
$names = array_unique($names);
if(count($names) < 2) {
$namesRows = RequestResult::find()->where(["request_id" => $sr->id, "type_id" => [
ResultCache::TYPE_FACEBOOK,
ResultCache::TYPE_VK_2012,
ResultCache::TYPE_VK_OPEN,
ResultCache::TYPE_VIBER,
ResultCache::TYPE_TELEGRAM,
ResultCache::TYPE_VK,
ResultCache::TYPE_AVITO,
]])->all();
foreach ($namesRows as $namesRow) {
$nameData = Json::decode($namesRow->data);
$names = ArrayHelper::merge($names, ArrayHelper::getColumn($nameData, "name"));
}
}
$names = array_unique($names);
$names = array_splice($names, 0, 2);
$data[] = [
"id" => $sr->id,
"phone" => $sr->phone,
"names" => $names,
"is_payed" => $sr->is_payed?1:0,
"index" => array_sum(ArrayHelper::getColumn($sr->results, "index")),
"operator" => ArrayHelper::getValue($operator,"operator", "не известно"),
"region" => ArrayHelper::getValue($operator,"region", "не известно"),
];
}
return $data;
}
}

View file

@ -0,0 +1,55 @@
<?php
namespace app\modules\api\controllers;
use app\models\User;
use app\models\UserSub;
use Yii;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use yii\rest\Controller;
use yii\web\BadRequestHttpException;
class InfoController extends Controller {
public function actionIndex() {
$userId = \Yii::$app->getRequest()->get("id", false);
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
if(!$uuid && !$userId) {
throw new BadRequestHttpException();
}
if($userId) {
$user = User::find()->select(["id", "balance", "checks", "email"])->where(["id" => $userId])->one();
} else {
$user = User::find()->select(["id", "balance", "checks", "email"])->where(["uuid" => $uuid])->one();
}
$isAndroid = Yii::$app->getRequest()->getHeaders()->get('isandroid', false);
if(!$user && !$isAndroid) {
$user = new User();
$user->email = null;
$user->uuid = $uuid;
$user->save();
$user = User::find()->select(["id", "balance", "checks", "email"])->where(["uuid" => $uuid])->one();
}
$sub = UserSub::find()->where(["user_id" => $user->id])->andWhere([">=", "tm_expires", new Expression("NOW()")])->orderBy(["tm_expires" => SORT_DESC])->one();
$expire = ArrayHelper::getValue($sub, "tm_expires", null);
$checks = $user->checks;
if(strtotime($expire) < time() && $checks < 0) {
$user->checks = 0;
$user->save();
$checks = 0;
}
if($checks < 0) $checks = -1;
return [
"id" => $user->id,
"balance" => $user->balance,
"checks" => $checks,
"email" => $user->email,
"isSubscribe" => $expire?1:0,
"subscribe" => $expire?Yii::$app->formatter->asDate($expire, 'd MMMM'):null
];
}
}

View file

@ -0,0 +1,31 @@
<?php
namespace app\modules\api\controllers;
use app\models\User;
use Yii;
use yii\rest\Controller;
use yii\web\BadRequestHttpException;
class NotifyController extends Controller {
public function actionIndex($token) {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
if(!$uuid) {
throw new BadRequestHttpException();
}
$user = User::find()->where(["uuid" => $uuid])->one();
if($user) {
$user->token = $token;
if(!$user->save()) {
return $user->getErrors();
} else {
return true;
}
} else {
return false;
}
}
}

View file

@ -0,0 +1,275 @@
<?php
namespace app\modules\api\controllers;
use app\models\User;
use app\models\UserSub;
use Yii;
use yii\db\Expression;
use yii\rest\Controller;
class PlansController extends Controller {
public function actionIndex() {
$userAgent = \Yii::$app->getRequest()->getUserAgent();
if(preg_match("/Nomer\/2\.5\.7/", $userAgent) || preg_match("/Nomer\/2\.5\.8/", $userAgent) ) {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$user = User::find()->where(["uuid" => $uuid])->one();
if(!$user) {
$user = new User();
$user->email = null;
$user->uuid = $uuid;
$user->save();
}
$sub = UserSub::find()->where(["user_id" => $user->id])->andWhere([">=", "tm_expires", new Expression("NOW()")])->orderBy(["tm_expires" => SORT_DESC])->one();
if($sub) {
return [];
}
/*
$packs = [
[
"count" => -1,
"product_id" => "com.wcaller.Wcaller.sub.month.0",
"type" => "sub",
"caption" => "Безлимит на месяц",
"subtitle" => "в неделю",
"special" => 0,
"style" => 0 // Большая кнопка
],
[
"count" => -2,
"product_id" => "com.wcaller.Wcaller.sub.6month.0",
"type" => "sub6",
"caption" => "Безлимит на пол года",
"subtitle" => "в неделю",
"special" => 0,
"style" => 0 // Большая кнопка
],
];
*/
$packs = [
[
"count" => -2,
"product_id" => "com.wcaller.Wcaller.sub.month.0",
"type" => "sub",
"caption" => "3 дня - БЕСПЛАТНО",
"subtitle" => "",
"special" => 0,
"style" => 1,
],
[
"count" => -1,
"product_id" => "com.wcaller.Wcaller.sub.6month.0",
"type" => "sub6",
"caption" => "Лучшая цена",
"subtitle" => "0.49$ в день",
"special" => 0,
"style" => 1 // Большая кнопка
],
];
/*
$packs = [
[
"count" => -2,
"product_id" => "com.wcaller.Wcaller.sub.month.0",
"type" => "sub",
"caption" => "3 дня - БЕСПЛАТНО",
"subtitle" => "",
"special" => 0,
"style" => 1,
],
[
"count" => -1,
"product_id" => "com.wcaller.Wcaller.sub.6month.0",
"type" => "sub6",
"caption" => "Лучшая цена",
"subtitle" => "0.49$ в день",
"special" => 0,
"style" => 1 // Большая кнопка
],
];
*/
return $packs;
} elseif(preg_match("/Nomer\/2\.5/", $userAgent)) {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$user = User::find()->where(["uuid" => $uuid])->one();
/*
$packs = [
[
"count" => -2,
"product_id" => "com.wcaller.Wcaller.sub.week.999",
"type" => "sub",
"caption" => "Полный безлимит",
"subtitle" => "Все провеки бесплатно",
"special" => 0,
"style" => 1,
],
[
"count" => -1,
"product_id" => "com.wcaller.Wcaller.sub.6month.0",
"type" => "sub6",
"caption" => "Лучшая цена",
"subtitle" => "0.49$ в день",
"special" => 0,
"style" => 1 // Большая кнопка
],
];
*/
$packs = [
[
"count" => -2,
"product_id" => "com.wcaller.Wcaller.sub.month.0",
"type" => "sub",
"caption" => "3 дня - БЕСПЛАТНО",
"subtitle" => "",
"special" => 0,
"style" => 1,
],
[
"count" => -1,
"product_id" => "com.wcaller.Wcaller.sub.6month.0",
"type" => "sub6",
"caption" => "Лучшая цена",
"subtitle" => "0.49$ в день",
"special" => 0,
"style" => 1 // Большая кнопка
],
];
/*
$packs = [
[
"count" => -2,
"product_id" => "com.wcaller.Wcaller.sub.month.999",
"type" => "sub",
"caption" => "БЕСПЛАТНО",
"subtitle" => "безлимит на месяц",
"special" => 0,
"style" => 1,
],
[
"count" => -1,
"product_id" => "com.wcaller.Wcaller.sub.6month.0",
"type" => "sub6",
"caption" => "Лучшая цена",
"subtitle" => "0.49$ в день",
"special" => 0,
"style" => 1 // Большая кнопка
],
];
*/
if(!$user) return $packs;
$sub = UserSub::find()->where(["user_id" => $user->id])->andWhere([">=", "tm_expires", new Expression("NOW()")])->orderBy(["tm_expires" => SORT_DESC])->one();
if($sub && $user->checks == 0) {
$packs = [
[
"count" => 1,
"product_id" => "com.wcaller.Wcaller.search1",
"type" => "inapp",
],
[
"count" => 10,
"product_id" => "com.wcaller.Wcaller.search10",
"type" => "inapp",
],
[
"count" => 30,
"product_id" => "com.wcaller.Wcaller.search30",
"type" => "inapp",
],
];
} elseif($sub && $user->checks < 0) {
$packs = [];
}
return $packs;
} elseif(preg_match("/Nomer\/2\.3/", $userAgent) || preg_match("/Nomer\/2\.4/", $userAgent)) {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$user = User::find()->where(["uuid" => $uuid])->one();
$packs = [
/*
[
"count" => 1,
"product_id" => "com.wcaller.Wcaller.search1",
"type" => "inapp",
],
*/
[
"count" => 10,
"product_id" => "com.wcaller.Wcaller.sub.month.10",
"type" => "sub",
"special" => 1
],
[
"count" => 15,
"product_id" => "com.wcaller.Wcaller.sub.month.15",
"type" => "sub",
"special" => 0
],
[
"count" => 50,
"product_id" => "com.wcaller.Wcaller.sub.month.50",
"type" => "sub",
"special" => 0
],
];
if(!$user) return $packs;
$sub = UserSub::find()->where(["user_id" => $user->id])->andWhere([">=", "tm_expires", new Expression("NOW()")])->orderBy(["tm_expires" => SORT_DESC])->one();
if($sub) {
$packs = [
[
"count" => 1,
"product_id" => "com.wcaller.Wcaller.search1",
"type" => "inapp",
],
[
"count" => 10,
"product_id" => "com.wcaller.Wcaller.search10",
"type" => "inapp",
],
[
"count" => 30,
"product_id" => "com.wcaller.Wcaller.search30",
"type" => "inapp",
],
];
}
return $packs;
}
$plans = [
[
"count" => 1,
"product_id" => "com.wcaller.Wcaller.search1",
],
[
"count" => 10,
"product_id" => "com.wcaller.Wcaller.search10",
],
[
"count" => 30,
"product_id" => "com.wcaller.Wcaller.search30",
]
/*
[
"count" => 100,
"product_id" => "com.nomer.app.search100",
],
[
"count" => 300,
"product_id" => "com.nomer.app.search300",
]
*/
];
return $plans;
}
}

View file

@ -0,0 +1,51 @@
<?php
namespace app\modules\api\controllers;
use app\models\TmpVk;
use app\models\Vk;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\rest\Controller;
class PonomeruController extends Controller {
public function actionIndex($phone) {
if(!in_array(\Yii::$app->request->getUserIP(), ["46.20.39.121", "82.204.203.174"])) die("Превед медвед :)");
$phone = preg_replace("/\D/", "", $phone);
$phone = preg_replace("/^8/", "7", $phone);
$response = [];
$profiles = [];
$vkOpen = Vk::find()->where(["or", ["phone1" => $phone], ["phone2" => $phone]])->all();
$vk2012 = TmpVk::find()->where(['phone' => $phone])->all();
$profiles = ArrayHelper::merge($profiles, ArrayHelper::getColumn($vkOpen, "id"));
$profiles = ArrayHelper::merge($profiles, ArrayHelper::getColumn($vk2012, "id"));
if(count($profiles)) {
$socData = @file_get_contents("https://api.vk.com/method/users.get?user_ids=" . join(",", $profiles) . "&fields=photo_id,photo_max,photo_max_orig&lang=ru&access_token=8f95fab19fb8d3d41bdeeb28f0112cb2cd3c86a93fc66acbd29f327d1aa3f196540bfe10dcd4ca97baf37");
if($socData) {
$socData = Json::decode($socData);
$socData = $socData["response"];
foreach($socData as $p) {
$row = [
"id" => ArrayHelper::getValue($p, "uid"),
"name" => ArrayHelper::getValue($p, "first_name")." ".ArrayHelper::getValue($p, "last_name"),
];
$photo = @file_get_contents(ArrayHelper::getValue($p, "photo_max_orig"));
if($photo) {
$row["photo"] = base64_encode($photo);
}
$response[] = $row;
}
}
}
return $response;
}
}

View file

@ -0,0 +1,100 @@
<?php
namespace app\modules\api\controllers;
use app\models\RequestResult;
use app\models\ResultCache;
use app\models\SearchRequest;
use app\models\User;
use Yii;
use yii\base\Exception;
use yii\helpers\Json;
use yii\rest\Controller;
use yii\web\BadRequestHttpException;
use yii\web\Response;
class ResultController extends Controller {
public function actionIndex($id) {
//\Yii::$app->response->format = Response::FORMAT_RAW;
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$user_id = \Yii::$app->request->get("user_id", false);
if(!$uuid && !$user_id) {
throw new BadRequestHttpException();
}
if($user_id) {
$user = User::find()->where(["id" => $user_id])->one();
} else {
$user = User::find()->where(["uuid" => $uuid])->one();
}
if(!$user) {
throw new BadRequestHttpException();
}
$searchRequest = SearchRequest::find()->where(["id" => $id, "user_id" => $user->id])->one();
if(!$searchRequest) {
throw new BadRequestHttpException();
}
$results = [];
$resultsData = RequestResult::find()->where(["request_id" => $id])->all();
foreach($resultsData as $r) {
try {
$data = Json::decode($r->data);
if($r->type_id == ResultCache::TYPE_VIBER) {
$data = [$data];
}
sort($data);
if($r->type_id == ResultCache::TYPE_AVITO) {
foreach ($data as $i => $row) {
$base64images = [];
if (isset($row["images"])) {
$images = explode(",", $row["images"]);
foreach ($images as $image) {
if(file_exists(Yii::$app->params['files'] . '/' . $image)) {
$i = @file_get_contents(Yii::$app->params['files'] . '/' . $image);
if($i) {
$b64 = @base64_encode($i);
if($b64) {
$base64images[] = $b64;
}
}
}
}
}
/*
$ijson = json_encode($base64images);
if($ijson) {
$data[$i]["images"] = $base64images;
}
*/
}
}
$result = [
"type" => ResultCache::getTypeSysname($r->type_id),
"elements" => $data
];
if($r->type_id == ResultCache::TYPE_AVINFO_API) {
$result["avinfo"] = $data;
$result["type"] = "avinfo";
}
if($r->type_id == ResultCache::TYPE_GIBDD) {
$result["gibdd"] = $data;
$result["type"] = "avinfo";
}
if($r->type_id == ResultCache::TYPE_ANTIPARKON) {
$result["antiparkon"] = $data;
$result["type"] = "avinfo";
}
$results[] = $result;
} catch (Exception $e) {
}
}
return $results;
}
}

View file

@ -0,0 +1,154 @@
<?php
namespace app\modules\api\controllers;
use app\components\SearchHelper;
use app\models\BlockPhone;
use app\models\SearchRequest;
use app\models\User;
use Yii;
use yii\base\Exception;
use yii\db\Expression;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\rest\Controller;
use yii\web\BadRequestHttpException;
class SearchController extends Controller{
public function actionIndex() {
$phone = \Yii::$app->request->get('phone');
$phone = preg_replace('/\D/', '', $phone);
if (mb_strlen($phone) == 10) {
$phone = '7' . $phone;
} else {
$phone = preg_replace('/^8/', '7', $phone);
}
$source = null;
$userId = Yii::$app->request->get("id", false);
$isAndroid = Yii::$app->getRequest()->getHeaders()->get('isandroid', false);
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
if(!$uuid && !$userId) {
throw new BadRequestHttpException();
}
/* @var $user User */
if($userId) {
$user = User::find()->where(["id" => $userId])->one();
if($uuid) {
$user->uuid = $uuid;
$user->save();
}
} elseif($uuid) {
$user = User::find()->where(compact('uuid'))->one();
if (!$user) {
$user = new User();
$user->email = null;
$user->uuid = $uuid;
$user->save();
}
}
$count = SearchRequest::find()->where(["user_id" => $user->id])->count(1);
if(!$user->is_vip) {
$block = BlockPhone::find()->where(["phone" => $phone, "status" => [1]])->one();
if(!is_null($block)) {
return ['id' => -1];
}
}
$limit = 1;
$countSeaches = 0;
if($user->checks == 0) {
$results = 0;
$freePhones = [];
$users = User::find()->where(["uuid" => $user->uuid])->all();
foreach($users as $u) {
$searchRequests = SearchRequest::find()->where(["user_id" => $u->id])->andWhere([">", "tm", date("Y-m-d H:i:s", strtotime("-7 days"))])->all();
foreach ($searchRequests as $s) {
if($s->is_has_name && $s->is_has_photo && !in_array($s->phone, $freePhones)) {
$countSeaches++;
$freePhones[] = $s->phone;
}
if($countSeaches == $limit) break;
}
}
if($countSeaches >= $limit) return ['id' => 0];
}
$isCache = 0;
//$searchRequest = SearchRequest::find()->where(["user_id" => $user->id, "phone" => $phone])->orderBy(["id" => SORT_DESC])->one();
$searchRequest = false;
$refresh = \Yii::$app->request->get("refresh", 0);
if($phone == "79645552229") {
$refresh = 1;
}
if(!$refresh) {
$searchRequest = SearchRequest::find()->with('results')->where([
"user_id" => $user->id,
"phone" => $phone,
"is_payed" => [1, 2]
])->orderBy(["id" => SORT_DESC])->one();
if($searchRequest) {
$isCache = 1;
}
}
if(!$searchRequest) {
$isCache = 0;
$searchRequest = new SearchRequest();
$searchRequest->ip = \Yii::$app->request->userIP;
$searchRequest->ua = \Yii::$app->request->userAgent;
$searchRequest->phone = $phone;
$searchRequest->tm = new Expression('NOW()');
$searchRequest->user_id = $user->id;
$searchRequest->refresh = true;
if($isAndroid) {
$searchRequest->source_id = SearchRequest::SOURCE_ANDROID;
} else {
$searchRequest->source_id = SearchRequest::SOURCE_IOS;
}
if($user->checks < 0) {
$searchRequest->is_payed = 1;
} elseif($user->checks > 0) {
$user->checks--;
$searchRequest->is_payed = 1;
} elseif($user->balance >= \Yii::$app->params["cost"]) {
$user->balance -= \Yii::$app->params["cost"];
$searchRequest->is_payed = 1;
} elseif(!$isAndroid) {
$searchRequest->is_payed = 1;
} elseif($countSeaches == 0) {
$searchRequest->is_payed = 1;
}
$user->save();
$searchRequest->save();
}
// if($uuid == "AA4AD41A-E2CE-4A7B-8AA0-FCE2EFAE52EE") $count = 0;
$result = [
'id' => $searchRequest->id,
'mobile' => null,
'is_payed' => (int)$searchRequest->is_payed,
'is_cache' => $isCache,
'is_first' => $count?0:1
];
$operator = SearchHelper::Operator($phone);
if($operator) {
$result['mobile'] = $operator;
}
return $result;
}
}

View file

@ -0,0 +1,168 @@
<?php
namespace app\modules\api\controllers;
use app\models\Auth;
use app\models\User;
use Yii;
use yii\db\Expression;
use yii\rest\Controller;
class SigninController extends Controller {
public function actionExit() {
/*
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$user = User::find()->where(["uuid" => $uuid])->andWhere(["IS NOT", "email", null])->one();
if($user) {
$user->uuid = null;
$user->save();
}
$userFree = User::find()->select(["id", "checks"])->where(["uuid" => $uuid])->andWhere(["email" => null])->one();
if(!$userFree) {
$userFree = new User();
$userFree->email = null;
$userFree->uuid = $uuid;
$userFree->save();
}
return $userFree;
*/
return ["success" => 1];
}
public function actionReg() {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$email = \Yii::$app->request->post("email");
$password = \Yii::$app->request->post("password");
$user = User::find()->where(["email" => $email])->one();
if($user) {
return ["error" => 1];
} else {
$user = new User();
$user->email = $email;
$user->password = $password;
$user->uuid = $uuid;
$user->save();
return $user;
}
}
public function actionIndex() {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$email = \Yii::$app->request->post("email");
$password = \Yii::$app->request->post("password");
$user = User::find()->where(["email" => $email])->one();
if($user && $user->validatePassword($password)) {
$user->uuid = $uuid;
$user->save();
return [
"id" => $user->id,
"checks" => $user->checks,
"email" => $user->email
];
}
return [
"id" => 0,
"checks" => 0
];
}
public function actionGoogle() {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$id = \Yii::$app->request->post("id");
$email = \Yii::$app->request->post("email");
$user = User::find()->where(["email" => $email])->one();
if(!$user) {
$password = Yii::$app->security->generateRandomString(6);
$user = new User([
'email' => mb_strtolower($email),
'password' => $password,
'is_confirm' => true,
'tm_confirm' => new Expression('NOW()')
]);
$user->uuid = $uuid;
if ($user->save()) {
$auth = new Auth([
'user_id' => $user->id,
'source' => "google",
'source_id' => (string)$id,
]);
$auth->save();
}
}
return [
"id" => $user->id,
"checks" => $user->checks
];
}
public function actionVk() {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$id = \Yii::$app->request->post("id");
$email = \Yii::$app->request->post("email");
$user = User::find()->where(["email" => $email])->one();
if(!$user) {
$password = Yii::$app->security->generateRandomString(6);
$user = new User([
'email' => mb_strtolower($email),
'password' => $password,
'is_confirm' => true,
'tm_confirm' => new Expression('NOW()')
]);
$user->uuid = $uuid;
if ($user->save()) {
$auth = new Auth([
'user_id' => $user->id,
'source' => "vk",
'source_id' => (string)$id,
]);
$auth->save();
}
}
return [
"id" => $user->id,
"checks" => $user->checks
];
}
public function actionFacebook() {
$uuid = Yii::$app->getRequest()->getHeaders()->get('uuid', false);
$id = \Yii::$app->request->post("id");
$email = \Yii::$app->request->post("email");
$user = User::find()->where(["email" => $email])->one();
if(!$user) {
$password = Yii::$app->security->generateRandomString(6);
$user = new User([
'email' => mb_strtolower($email),
'password' => $password,
'is_confirm' => true,
'tm_confirm' => new Expression('NOW()')
]);
$user->uuid = $uuid;
if ($user->save()) {
$auth = new Auth([
'user_id' => $user->id,
'source' => "facebook",
'source_id' => (string)$id,
]);
$auth->save();
}
}
return [
"id" => $user->id,
"checks" => $user->checks
];
}
}

View file

@ -0,0 +1,241 @@
<?php
namespace app\modules\api\controllers;
use app\components\SearchHelper;
use app\models\RequestResult;
use app\models\ResultCache;
use app\models\SearchRequest;
use app\models\Settings;
use app\models\TmpVk;
use app\models\Vk;
use yii\helpers\ArrayHelper;
use yii\helpers\Json;
use yii\rest\Controller;
use yii\web\Response;
class TelegramController extends Controller
{
public function actionIndex($phone)
{
\Yii::$app->response->format = Response::FORMAT_JSON;
$searchRequest = new SearchRequest();
$searchRequest->phone = $phone;
$searchRequest->source_id = SearchRequest::SOURCE_TELEGRAM;
$searchRequest->save();
$id = $searchRequest->id;
$result = [
"phones" => [$phone],
"emails" => [],
"profiles" => [],
"public" => [],
"phone" => $phone,
"open" => [],
"elements" => [],
"valid" => []
];
$profiles = [];
$ch = curl_init('http://ssd.nomer.io/api/'.$phone.'?token=NWBpdeqbbAFJMVYJU6XAfhyydeyhgX');
curl_setopt($ch, CURLOPT_RETURNTRANSFER, true);
$response = curl_exec($ch);
$httpCode = curl_getinfo($ch, CURLINFO_HTTP_CODE);
if($httpCode == 200) { // Все ок, берем данные
$response = Json::decode($response);
foreach($response as $r) {
switch($r["type"]) {
case "phone":
$result["phones"][] = $r["data"];
break;
case "profile_id":
$result["profiles"][] = $r["data"];
$profiles[] = $r["data"];
if(isset($r["isValid"]) && $r["isValid"] == 1) {
$result["valid"][] = $r["data"];
}
break;
case "email":
if (strpos($r["data"], '@') !== false) {
$result["emails"][] = $r["data"];
}
break;
}
}
}
$result["phones"] = array_unique($result["phones"]);
foreach($result["phones"] as $_phone) {
$vk = TmpVk::find()->where(['phone' => $phone])->all();
foreach($vk as $v) {
$profile_id = $v["id"];
$result["public"][] = $profile_id;
$profiles[] = $profile_id;
}
}
$vkrows = Vk::find()->where(["or",
["phone1" => $phone],
["phone2" => $phone],
])->all();
foreach ($vkrows as $vkrow) {
$profiles[] = $vkrow["id"];
// $result["public"][] = $vkrow["id"];
$result["open"][] = $vkrow["id"];
$result["phones"][] = $vkrow["phone1"];
$result["phones"][] = $vkrow["phone2"];
$result["phones"][] = $vkrow["phone3"];
$result["phones"][] = $vkrow["phone4"];
}
$result["emails"] = array_unique($result["emails"]);
$result["phones"] = array_unique(array_filter($result["phones"]));
$phones = $result['phones'];
// Получаем оператора и регион
$operator = SearchHelper::Operator($searchRequest->phone);
$requestResult = RequestResult::find()->where(["request_id" => $id, "type_id" => ResultCache::TYPE_OPERATOR])->one();
if(is_null($requestResult)) {
$requestResult = new RequestResult();
$requestResult->request_id = $id;
$requestResult->type_id = ResultCache::TYPE_OPERATOR;
$requestResult->data = Json::encode($operator);
$requestResult->index = 0;
$requestResult->save();
}
$items = [];
// Telegram
$telegramItems = SearchHelper::Telegram($phones);
$requestResult = RequestResult::find()->where(["request_id" => $id, "type_id" => ResultCache::TYPE_TELEGRAM])->one();
if(is_null($requestResult)) {
$requestResult = new RequestResult();
$requestResult->request_id = $id;
$requestResult->type_id = ResultCache::TYPE_TELEGRAM;
$requestResult->data = Json::encode($telegramItems);
$requestResult->index = count($telegramItems)?Settings::get("search_index_telegram", 7):0;
$requestResult->save();
}
$items = ArrayHelper::merge($items, $telegramItems);
// Viber
$viberItems = SearchHelper::Viber($phones);
$requestResult = RequestResult::find()->where(["request_id" => $id, "type_id" => ResultCache::TYPE_VIBER])->one();
if(is_null($requestResult)) {
$requestResult = new RequestResult();
$requestResult->request_id = $id;
$requestResult->type_id = ResultCache::TYPE_VIBER;
$requestResult->data = Json::encode($viberItems);
$requestResult->index = count($viberItems)?Settings::get("search_index_viber", 7):0;
$requestResult->save();
}
$items = ArrayHelper::merge($items, $viberItems);
// Numbuster
$numbusterItems = SearchHelper::Numbuster($phones);
$requestResult = RequestResult::find()->where(["request_id" => $id, "type_id" => ResultCache::TYPE_NUMBUSTER])->one();
if(is_null($requestResult)) {
$requestResult = new RequestResult();
$requestResult->request_id = $id;
$requestResult->type_id = ResultCache::TYPE_NUMBUSTER;
$requestResult->data = Json::encode($numbusterItems);
$requestResult->index = count($numbusterItems)?Settings::get("search_index_numbuster", 7):0;
$requestResult->save();
}
$items = ArrayHelper::merge($items, $numbusterItems);
// Truecaller
$truecallerItems = SearchHelper::Truecaller($phones);
$requestResult = RequestResult::find()->where(["request_id" => $id, "type_id" => ResultCache::TYPE_TRUECALLER])->one();
if(is_null($requestResult)) {
$requestResult = new RequestResult();
$requestResult->request_id = $id;
$requestResult->type_id = ResultCache::TYPE_TRUECALLER;
$requestResult->data = Json::encode($truecallerItems);
$requestResult->index = count($truecallerItems)?Settings::get("search_index_truecaller", 7):0;
$requestResult->save();
}
$items = ArrayHelper::merge($items, $truecallerItems);
// Vk
$vkItems = SearchHelper::Vk($phones);
$requestResult = RequestResult::find()->where(["request_id" => $id, "type_id" => ResultCache::TYPE_VK_2012])->one();
if(is_null($requestResult)) {
$requestResult = new RequestResult();
$requestResult->request_id = $id;
$requestResult->type_id = ResultCache::TYPE_VK_2012;
$requestResult->data = Json::encode($vkItems);
$requestResult->index = count($vkItems)?Settings::get("search_index_vk", 20):0;
$requestResult->save();
}
$items = ArrayHelper::merge($items, $vkItems);
// Avito
$avitoItems = SearchHelper::Avito($phones);
$requestResult = RequestResult::find()->where(["request_id" => $id, "type_id" => ResultCache::TYPE_AVITO])->one();
if(is_null($requestResult)) {
$requestResult = new RequestResult();
$requestResult->request_id = $id;
$requestResult->type_id = ResultCache::TYPE_AVITO;
$requestResult->data = Json::encode($avitoItems);
$requestResult->index = count($avitoItems)?Settings::get("search_index_avito", 15):0;
$requestResult->save();
}
$items = ArrayHelper::merge($items, $avitoItems);
if(count(ArrayHelper::getColumn($items, "name"))) {
$searchRequest->is_has_name = true;
}
if(count(ArrayHelper::getColumn($items, "photo"))) {
$searchRequest->is_has_photo = true;
}
$searchRequest->save();
sort($items);
$names = array_unique(array_filter(array_map(function ($data) {
return ArrayHelper::getValue($data, 'name');
}, $items)));
sort($names);
$photo = false;
foreach ($items as $item) {
if (isset($item['photo'])) {
$photo = $item['photo'];
break;
}
}
return compact('names', 'photo');
}
}