Last active
February 26, 2019 08:55
-
-
Save lislon/9612ec9872d4189e2efad8d00a5aed23 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package com.lislon; | |
import org.javagram.TelegramApiBridge; | |
import org.javagram.response.AuthAuthorization; | |
import org.javagram.response.AuthCheckedPhone; | |
import static com.lislon.Secret.APP_HASH; | |
import static com.lislon.Secret.APP_ID; | |
public class Main { | |
public static final String PROD_IP = "149.154.167.50:443"; // put your DC | |
public static final String TEST_IP = "149.154.167.40:443"; // put your DC | |
public static final String TEST_NUMBER = "9996624444"; | |
public static final String TEST_CODE = "22222"; | |
/** | |
* Чтобы телеграм не банил телефоны, стоит переключиться на тестовый IP и использовать специальный номер телефона: | |
* тестовый номер состоит из: | |
* 99966 - обязательный префикс | |
* 2 - DC (Если получаете NETWORK_MIGRATE_X error - меняете его на 1,2,3...) | |
* 4444 - рандомное число | |
* Код подтверджения всегда XXXXX Где X - это номер DC. например, 22222 | |
* и при signIn USER_NOT_OCCUPIED, то регистрируете пользователя через метод authSignUp | |
* Полное описание: https://core.telegram.org/api/datacenter | |
*/ | |
public static void main(String[] args) throws Exception { | |
// put your APP_ID and APP_HASH | |
TelegramApiBridge b = new TelegramApiBridge(TEST_IP, APP_ID, APP_HASH); | |
AuthCheckedPhone phone = b.authCheckPhone(TEST_NUMBER); | |
System.out.println("Is registered?" + phone.isRegistered()); | |
b.authSendCode(TEST_NUMBER); | |
AuthAuthorization authAuthorization; | |
if (!phone.isRegistered()) { | |
authAuthorization = b.authSignUp(TEST_CODE, "Lisa", "Slon"); | |
} else { | |
authAuthorization = b.authSignIn(TEST_CODE); | |
} | |
// write your code here | |
System.out.println("User logged in: " + authAuthorization.getUser().getFirstName()); | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment