java腾讯云通信(注册账号)

java腾讯云通信(注册账号)

Map<String, String> map = new HashMap<>();
map.put("Identifier", memberNo);//云通信账号,后台自定义,我用的用户编号
map.put("Nick", registerReq.getNickName());//昵称
map.put("FaceUrl", registerReq.getAvatarUrl());//头像地址
String json = JSON.toJSONString(map);
JSONObject jObject = JSON.parseObject(TXCloudHelper.executePost("https://console.tim.qq.com/v4/im_open_login_svc/account_import?" + "usersig=" + CloudSignHelper.GetSign() + //腾讯云签名
"&identifier=" + CloudSignHelper.identifier + //管理员账号
"&sdkappid=" + CloudSignHelper.skdAppid + //腾讯云通信APPID
"&random=" + randomInt() + //随机数
"&contenttype=json", json));
if (!"OK".equals(jObject.get("ActionStatus").toString()) && !"0".equals(jObject.get("ErrorCode").toString())) {
	throw new FdServiceException(ErrorCode.QUERY_EXCEPTION, "请求腾讯注册失败");
}

上面用到一个post方法

public static String executePost(String url, String parameters) {
        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
        HttpPost method =  new HttpPost(url);
        String body = null;
        if(method != null & parameters != null && !"".equals(parameters.trim()))
        {
            try{
                //建立一个NameValuePair数组,用于存储欲传送的参数
                method.addHeader("Content-type","application/json; charset=utf-8");
                method.setHeader("Accept", "application/json");
                method.setEntity(new StringEntity(parameters, Charset.forName("UTF-8")));
                HttpResponse response = closeableHttpClient.execute(method);
                int statusCode = response.getStatusLine().getStatusCode();
                if(statusCode != HttpStatus.SC_OK)
                {
                    System.out.println(response.getStatusLine());
                }
                //获取响应数据
                body = EntityUtils.toString(response.getEntity());
            } catch (IOException e) {
                e.printStackTrace();
            }
        }
        return body;
}
  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值