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 +
"&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{
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;
}