【问题标题】:How to do a basic remote procedure call (RPC) in Telegram?如何在 Telegram 中进行基本的远程过程调用(RPC)?
【发布时间】:2014-05-28 03:26:25
【问题描述】:

我正在尝试创建一个小程序来演示 Telegram API 的某些功能。我希望能够通过 SMS 注册和验证用户。根据user authorization guide,我需要调用auth.sendCode RPC。但是,代码库的文档记录不充分,而且很难进入。

如何在 Telegram 中发送auth.sendCode 远程过程调用?请提供代码 sn-p,它显示从设置和初始化开始的所有内容。

【问题讨论】:

标签: rpc telegram


【解决方案1】:

像这样试试……

TLSentCode sentCode;
    try {
        sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0, 5, "your app id", "en"));
    } catch (RpcException e) {
        if (e.getErrorCode() == 303) {
            int destDC;
            if (e.getErrorTag().startsWith("NETWORK_MIGRATE_")) {
                destDC = Integer.parseInt(e.getErrorTag().substring("NETWORK_MIGRATE_".length()));
            } else if (e.getErrorTag().startsWith("PHONE_MIGRATE_")) {
                destDC = Integer.parseInt(e.getErrorTag().substring("PHONE_MIGRATE_".length()));
            } else if (e.getErrorTag().startsWith("USER_MIGRATE_")) {
                destDC = Integer.parseInt(e.getErrorTag().substring("USER_MIGRATE_".length()));
            } else {
                throw e;
            }
            api.switchToDc(destDC);
            sentCode = api.doRpcCallNonAuth(new TLRequestAuthSendCode(phone, 0, 5, "youa app id", "en"));
        } else {
            throw e;
        }
    }

【讨论】:

    猜你喜欢
    • 2012-04-17
    • 2017-08-24
    • 1970-01-01
    • 1970-01-01
    • 2019-08-15
    • 1970-01-01
    • 2015-07-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多