zoukankan      html  css  js  c++  java
  • Smack4.1注册新用户

    更新了smack4.1后,发现之前的注册表单不能使用了,很多属性都不能使用.

    发现4.1把帐号的出来都集中到

    org.jivesoftware.smackx.iqregister.AccountManager类

    /**
    * Creates a new account using the specified username and password. The server may
    * require a number of extra account attributes such as an email address and phone
    * number. In that case, Smack will attempt to automatically set all required
    * attributes with blank values, which may or may not be accepted by the server.
    * Therefore, it's recommended to check the required account attributes and to let
    * the end-user populate them with real values instead.
    *
    * @param username the username.
    * @param password the password.
    * @throws XMPPErrorException
    * @throws NoResponseException
    * @throws NotConnectedException
    */
    public void createAccount(String username, String password) throws NoResponseException, XMPPErrorException, NotConnectedException {
    // Create a map for all the required attributes, but give them blank values.
    Map<String, String> attributes = new HashMap<String, String>();
    for (String attributeName : getAccountAttributes()) {
    attributes.put(attributeName, "");
    }
    createAccount(username, password, attributes);
    }

    /**
    * Creates a new account using the specified username, password and account attributes.
    * The attributes Map must contain only String name/value pairs and must also have values
    * for all required attributes.
    *
    * @param username the username.
    * @param password the password.
    * @param attributes the account attributes.
    * @throws XMPPErrorException if an error occurs creating the account.
    * @throws NoResponseException if there was no response from the server.
    * @throws NotConnectedException
    * @see #getAccountAttributes()
    */
    public void createAccount(String username, String password, Map<String, String> attributes)
    throws NoResponseException, XMPPErrorException, NotConnectedException {
    if (!connection().isSecureConnection() && !allowSensitiveOperationOverInsecureConnection) {
    // TODO throw exception in newer Smack versions
    LOGGER.warning("Creating account over insecure connection. "
    + "This will throw an exception in future versions of Smack if AccountManager.sensitiveOperationOverInsecureConnection(true) is not set");
    }
    attributes.put("username", username);
    attributes.put("password", password);
    Registration reg = new Registration(attributes);
    reg.setType(IQ.Type.set);
    reg.setTo(connection().getServiceName());
    createPacketCollectorAndSend(reg).nextResultOrThrow();
    }

    创建新帐号
    AccountManager.getInstance(XmppConnectionManager.getInstance().getConnection()).createAccount("test001", "123456");
  • 相关阅读:
    stm32之不定长接收
    3、列表和列表项
    2、FreeRTOS任务相关API函数
    1、FreeRTOS移植
    5、根文件系统原理
    1、c++对c语言的扩展
    4、移植三星官方内核
    3、内核的启动过程
    2、内核的配置和移植
    iOS学习笔记19-地图(一)定位CoreLocation
  • 原文地址:https://www.cnblogs.com/John5/p/4472543.html
Copyright © 2011-2022 走看看