java 使用极光调用注册用户

1.引入依赖

 <dependency>
      <groupId>cn.jpush.api</groupId>
      <artifactId>jpush-client</artifactId>
      <version>3.3.9</version>
    </dependency>
    <dependency>
      <groupId>cn.jpush.api</groupId>
      <artifactId>jmessage-client</artifactId>
      <version>1.1.7</version>
    </dependency>
    <dependency>
      <groupId>cn.jpush.api</groupId>
      <artifactId>jiguang-common</artifactId>
      <version>1.1.0</version>
    </dependency>
    <dependency>
      <groupId>com.google.code.gson</groupId>
      <artifactId>gson</artifactId>
      <version>2.3</version>
    </dependency>
    <dependency>
      <groupId>org.slf4j</groupId>
      <artifactId>slf4j-api</artifactId>
      <version>1.7.7</version>
    </dependency>

service 代码

public static void regPP(String username,String password) {
        JMessageClient client = new JMessageClient(appKey, masterSecret);
        String authCode = ServiceHelper.getBasicAuthorization(appKey, masterSecret);
        ApacheHttpClient httpClient = new ApacheHttpClient(authCode, null, ClientConfig.getInstance());
        client.setHttpClient(httpClient);
        try {
            List<RegisterInfo> users = new ArrayList<RegisterInfo>();
            RegisterInfo user = RegisterInfo.newBuilder()
                    .setUsername(username)
                    .setPassword(password)
                    .build();
            users.add(user);
            RegisterInfo[] regUsers = new RegisterInfo[users.size()];

            String res = client.registerUsers(users.toArray(regUsers));
            //LOG.info(res);
        } catch (APIConnectionException e) {
           // LOG.error("连接错误。请稍后重试。 ", e);
        } catch (APIRequestException e) {
           //LOG.error("JPush服务器的错误响应。请检查并改正。", e);
            //LOG.info("网络状态: " + e.getStatus());
            //LOG.info("错误信息: " + e.getMessage());
        }
    }

将password username 传入即可

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值