-1

我对如何使用smack api注册用户一无所知。查看他们的文档并查看Registration课程。我写了这段代码。但我想这不会注册用户。尽管代码运行良好,即没有错误或异常,但我没有看到数据库表填充了这些值。

Registration r = new Registration();

    /*
     *  name -- the user's name.
        first -- the user's first name.
        last -- the user's last name.
        email -- the user's email address.
        city -- the user's city.
        state -- the user's state.
        zip -- the user's ZIP code.
        phone -- the user's phone number.
        url -- the user's website.
        date -- the date the registration took place.
        misc -- other miscellaneous information to associate with the account.
        text -- textual information to associate with the account.
        remove -- empty flag to remove account.
     */

    Map<String,String> regAttr = new HashMap<String, String>();

    regAttr.put("username", "suhail");
    regAttr.put("first", "suhail");
    regAttr.put("last", "gupta");
    regAttr.put("email", "pqr@lmn.com");
    regAttr.put("city", "ptk");
    regAttr.put("state", "Punjab");
    regAttr.put("zip", "145001");
    regAttr.put("phone","9999");
    regAttr.put("url", "www.abc.com");
    regAttr.put("date", "14/8/2013");
    regAttr.put("misc", "misc");
    regAttr.put("text", "text");
    regAttr.put("remove", "r");

    r.setAttributes(regAttr);

如何使用smack api注册用户?

4

1 回答 1

0

我使用下面的代码。该代码假定 XMPP 服务器在本地 (localhost) 运行。该createAccount方法在内部创建一个Registration数据包并通过connection.

public static void main(String[] args)
{
    XMPPConnection.DEBUG_ENABLED = true;
    XMPPConnection connection=null;
    try
    {
        ConnectionConfiguration config = new ConnectionConfiguration("localhost", 5222);
        connection = new XMPPConnection(config);
        connection.connect();
        AccountManager accountManager = connection.getAccountManager();
        if(accountManager.supportsAccountCreation())
        {
            accountManager.createAccount("user1", "user1pw");
        }
        else
        {
            ...
        }
    }
    catch (Exception e) 
    {
        ...
    }
    connection.disconnect();
}
于 2013-08-16T11:38:07.687 回答