我对使用 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 注册用户?
答案 0 :(得分: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();
}