- 浏览: 6934 次
- 性别:
- 来自: 北京
最新评论
import java.net.URL;
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.jx.lcs.common.huanxin.Constants;
import com.jx.lcs.common.huanxin.HTTPMethod;
import com.jx.lcs.common.huanxin.Roles;
import com.jx.lcs.common.huanxin.httpclient.HTTPClientUtils;
import com.jx.lcs.common.huanxin.vo.ClientSecretCredential;
import com.jx.lcs.common.huanxin.vo.Credential;
import com.jx.lcs.common.huanxin.vo.EndPoints;
/**
* REST API Demo: 发送消息 REST API HttpClient4.3实现
*/
public class EasemobMessages {
private static Logger LOGGER = LoggerFactory.getLogger(EasemobMessages.class);
private static final String APPKEY = Constants.APPKEY;
private static JsonNodeFactory factory = new JsonNodeFactory(false);
// 通过app的client_id和client_secret来获取app管理员token
private static Credential credential = new ClientSecretCredential(Constants.APP_CLIENT_ID,
Constants.APP_CLIENT_SECRET, Roles.USER_ROLE_APPADMIN);
//发送消息到单个用户
public static void sendMsgToUser(String fromUid, String toUid, String content) {
// 给用户发一条文本消息
String from = fromUid;
String targetTypeus = "users";
ObjectNode ext = factory.objectNode();
ArrayNode targetusers = factory.arrayNode();
targetusers.add(toUid);
ObjectNode txtmsg = factory.objectNode();
txtmsg.put("msg", content);
txtmsg.put("type","txt");
ObjectNode sendTxtMessageusernode = sendMessages(targetTypeus, targetusers, txtmsg, from, ext);
if (null != sendTxtMessageusernode) {
LOGGER.info("给" + toUid + "发一条文本消息: " + sendTxtMessageusernode.toString());
}
}
public static void main(String[] args) {
/**
* 注册IM用户[单个]
*/
ObjectNode datanode = JsonNodeFactory.instance.objectNode();
datanode.put("username","test");
datanode.put("password", Constants.DEFAULT_PASSWORD);
ObjectNode createNewIMUserSingleNode = createNewIMUserSingle(datanode);
if (null != createNewIMUserSingleNode) {
LOGGER.info("注册IM用户[单个]: " + createNewIMUserSingleNode.toString());
}
// 检测用户是否在线
// String targetuserPrimaryKey = "683697";
// ObjectNode usernode = getUserStatus(targetuserPrimaryKey);
// if (null != usernode) {
// LOGGER.info("检测用户是否在线: " + usernode.toString());
// }
// 给用户发一条文本消息
/*
String from = "jiayy01";
String targetTypeus = "users";
ObjectNode ext = factory.objectNode();
ArrayNode targetusers = factory.arrayNode();
targetusers.add("683697");
// targetusers.add("lurong02");
ObjectNode txtmsg = factory.objectNode();
txtmsg.put("msg", "Apple Watch! 嘎嘎 嘎嘎 嘎嘎 嘎嘎!!!");
txtmsg.put("type","txt");
ObjectNode sendTxtMessageusernode = sendMessages(targetTypeus, targetusers, txtmsg, from, ext);
if (null != sendTxtMessageusernode) {
LOGGER.info("给用户发一条文本消息: " + sendTxtMessageusernode.toString());
}
*/
/*
// 给一个群组发文本消息
String targetTypegr = "chatgroups";
ArrayNode chatgroupidsNode = (ArrayNode) EasemobChatGroups.getAllChatgroupids().path("data");
ArrayNode targetgroup = factory.arrayNode();
targetgroup.add(chatgroupidsNode.get(0).path("groupid").asText());
ObjectNode sendTxtMessagegroupnode = sendMessages(targetTypegr, targetgroup, txtmsg, from, ext);
if (null != sendTxtMessagegroupnode) {
LOGGER.info("给一个群组发文本消息: " + sendTxtMessagegroupnode.toString());
}
// 给用户发一条图片消息
File uploadImgFile = new File("/home/lynch/Pictures/24849.jpg");
ObjectNode imgDataNode = EasemobFiles.mediaUpload(uploadImgFile);
String imgFileUUID = imgDataNode.path("entities").get(0).path("uuid").asText();
String shareSecret = imgDataNode.path("entities").get(0).path("share-secret").asText();
if (null != imgDataNode) {
LOGGER.info("上传图片文件: " + imgDataNode.toString());
}
ObjectNode imgmsg = factory.objectNode();
imgmsg.put("type","img");
imgmsg.put("url", HTTPClientUtils.getURL(Constants.APPKEY.replace("#", "/") + "/chatfiles/" + imgFileUUID).toString());
imgmsg.put("filename", "24849.jpg");
imgmsg.put("length", 10);
imgmsg.put("secret", shareSecret);
ObjectNode sendimgMessageusernode = sendMessages(targetTypeus, targetusers, imgmsg, from, ext);
if (null != sendimgMessageusernode) {
LOGGER.info("给一个群组发文本消息: " + sendimgMessageusernode.toString());
}
// 给一个群组发图片消息
ObjectNode sendimgMessagegroupnode = sendMessages(targetTypegr, targetgroup, imgmsg, from, ext);
if (null != sendimgMessagegroupnode) {
LOGGER.info("给一个群组发文本消息: " + sendimgMessagegroupnode.toString());
}
// 给用户发一条语音消息
File uploadAudioFile = new File("/home/lynch/Music/music.MP3");
ObjectNode audioDataNode = EasemobFiles.mediaUpload(uploadAudioFile);
String audioFileUUID = audioDataNode.path("entities").get(0).path("uuid").asText();
String audioFileShareSecret = audioDataNode.path("entities").get(0).path("share-secret").asText();
if (null != audioDataNode) {
LOGGER.info("上传语音文件: " + audioDataNode.toString());
}
ObjectNode audiomsg = factory.objectNode();
audiomsg.put("type","audio");
audiomsg.put("url", HTTPClientUtils.getURL(Constants.APPKEY.replace("#", "/") + "/chatfiles/" + audioFileUUID).toString());
audiomsg.put("filename", "music.MP3");
audiomsg.put("length", 10);
audiomsg.put("secret", audioFileShareSecret);
ObjectNode sendaudioMessageusernode = sendMessages(targetTypeus, targetusers, audiomsg, from, ext);
if (null != sendaudioMessageusernode) {
LOGGER.info("给用户发一条语音消息: " + sendaudioMessageusernode.toString());
}
// 给一个群组发语音消息
ObjectNode sendaudioMessagegroupnode = sendMessages(targetTypegr, targetgroup, audiomsg, from, ext);
if (null != sendaudioMessagegroupnode) {
LOGGER.info("给一个群组发语音消息: " + sendaudioMessagegroupnode.toString());
}
// 给用户发一条透传消息
ObjectNode cmdmsg = factory.objectNode();
cmdmsg.put("action", "gogogo");
cmdmsg.put("type","cmd");
ObjectNode sendcmdMessageusernode = sendMessages(targetTypeus, targetusers, cmdmsg, from, ext);
if (null != sendcmdMessageusernode) {
LOGGER.info("给用户发一条透传消息: " + sendcmdMessageusernode.toString());
}
*/
}
/**
* 检测用户是否在线
*
* @param username
*
* @return
*/
public static ObjectNode getUserStatus(String username) {
ObjectNode objectNode = factory.objectNode();
// check appKey format
if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) {
LOGGER.error("Bad format of Appkey: " + APPKEY);
objectNode.put("message", "Bad format of Appkey");
return objectNode;
}
// check properties that must be provided
if (StringUtils.isEmpty(username)) {
LOGGER.error("You must provided a targetUserPrimaryKey .");
objectNode.put("message", "You must provided a targetUserPrimaryKey .");
return objectNode;
}
try {
URL userStatusUrl = HTTPClientUtils.getURL(Constants.APPKEY.replace("#", "/") + "/users/"
+ username + "/status");
objectNode = HTTPClientUtils.sendHTTPRequest(userStatusUrl, credential, null, HTTPMethod.METHOD_GET);
String userStatus = objectNode.get("data").path(username).asText();
if ("online".equals(userStatus)) {
LOGGER.error(String.format("The status of user[%s] is : [%s] .", username, userStatus));
} else if ("offline".equals(userStatus)) {
LOGGER.error(String.format("The status of user[%s] is : [%s] .", username, userStatus));
}
} catch (Exception e) {
e.printStackTrace();
}
return objectNode;
}
/**
* 发送消息
*
* @param targetType
* 消息投递者类型:users 用户, chatgroups 群组
* @param target
* 接收者ID 必须是数组,数组元素为用户ID或者群组ID
* @param msg
* 消息内容
* @param from
* 发送者
* @param ext
* 扩展字段
*
* @return 请求响应
*/
public static ObjectNode sendMessages(String targetType, ArrayNode target, ObjectNode msg, String from,
ObjectNode ext) {
ObjectNode objectNode = factory.objectNode();
ObjectNode dataNode = factory.objectNode();
// check appKey format
if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) {
LOGGER.error("Bad format of Appkey: " + APPKEY);
objectNode.put("message", "Bad format of Appkey");
return objectNode;
}
// check properties that must be provided
if (!("users".equals(targetType) || "chatgroups".equals(targetType))) {
LOGGER.error("TargetType must be users or chatgroups .");
objectNode.put("message", "TargetType must be users or chatgroups .");
return objectNode;
}
try {
// 构造消息体
dataNode.put("target_type", targetType);
dataNode.put("target", target);
dataNode.put("msg", msg);
dataNode.put("from", from);
dataNode.put("ext", ext);
objectNode = HTTPClientUtils.sendHTTPRequest(EndPoints.MESSAGES_URL, credential, dataNode,
HTTPMethod.METHOD_POST);
objectNode = (ObjectNode) objectNode.get("data");
for (int i = 0; i < target.size(); i++) {
String resultStr = objectNode.path(target.path(i).asText()).asText();
if ("success".equals(resultStr)) {
LOGGER.error(String.format("Message has been send to user[%s] successfully .", target.path(i)
.asText()));
} else if (!"success".equals(resultStr)) {
LOGGER.error(String.format("Message has been send to user[%s] failed .", target.path(i).asText()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return objectNode;
}
/**
* 注册IM用户[单个]
*
* 给指定Constants.APPKEY创建一个新的用户
*
* @param dataNode
* @return
*/
public static ObjectNode createNewIMUserSingle(ObjectNode dataNode) {
ObjectNode objectNode = factory.objectNode();
// check Constants.APPKEY format
if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", Constants.APPKEY)) {
LOGGER.error("Bad format of Constants.APPKEY: " + Constants.APPKEY);
objectNode.put("message", "Bad format of Constants.APPKEY");
return objectNode;
}
objectNode.removeAll();
// check properties that must be provided
if (null != dataNode && !dataNode.has("username")) {
LOGGER.error("Property that named username must be provided .");
objectNode.put("message", "Property that named username must be provided .");
return objectNode;
}
if (null != dataNode && !dataNode.has("password")) {
LOGGER.error("Property that named password must be provided .");
objectNode.put("message", "Property that named password must be provided .");
return objectNode;
}
try {
objectNode = HTTPClientUtils.sendHTTPRequest(EndPoints.USERS_URL, credential, dataNode,
HTTPMethod.METHOD_POST);
} catch (Exception e) {
e.printStackTrace();
}
return objectNode;
}
/**
* 注册IM用户[批量]
*
* 给指定Constants.APPKEY创建一批用户
*
* @param dataArrayNode
* @return
*/
public static ObjectNode createNewIMUserBatch(ArrayNode dataArrayNode) {
ObjectNode objectNode = factory.objectNode();
// check Constants.APPKEY format
if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", Constants.APPKEY)) {
LOGGER.error("Bad format of Constants.APPKEY: " + Constants.APPKEY);
objectNode.put("message", "Bad format of Constants.APPKEY");
return objectNode;
}
// check properties that must be provided
if (dataArrayNode.isArray()) {
for (JsonNode jsonNode : dataArrayNode) {
if (null != jsonNode && !jsonNode.has("username")) {
LOGGER.error("Property that named username must be provided .");
objectNode.put("message", "Property that named username must be provided .");
return objectNode;
}
if (null != jsonNode && !jsonNode.has("password")) {
LOGGER.error("Property that named password must be provided .");
objectNode.put("message", "Property that named password must be provided .");
return objectNode;
}
}
}
try {
objectNode = HTTPClientUtils.sendHTTPRequest(EndPoints.USERS_URL, credential, dataArrayNode,
HTTPMethod.METHOD_POST);
} catch (Exception e) {
e.printStackTrace();
}
return objectNode;
}
}
import org.apache.commons.lang3.StringUtils;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import com.fasterxml.jackson.databind.JsonNode;
import com.fasterxml.jackson.databind.node.ArrayNode;
import com.fasterxml.jackson.databind.node.JsonNodeFactory;
import com.fasterxml.jackson.databind.node.ObjectNode;
import com.jx.lcs.common.huanxin.Constants;
import com.jx.lcs.common.huanxin.HTTPMethod;
import com.jx.lcs.common.huanxin.Roles;
import com.jx.lcs.common.huanxin.httpclient.HTTPClientUtils;
import com.jx.lcs.common.huanxin.vo.ClientSecretCredential;
import com.jx.lcs.common.huanxin.vo.Credential;
import com.jx.lcs.common.huanxin.vo.EndPoints;
/**
* REST API Demo: 发送消息 REST API HttpClient4.3实现
*/
public class EasemobMessages {
private static Logger LOGGER = LoggerFactory.getLogger(EasemobMessages.class);
private static final String APPKEY = Constants.APPKEY;
private static JsonNodeFactory factory = new JsonNodeFactory(false);
// 通过app的client_id和client_secret来获取app管理员token
private static Credential credential = new ClientSecretCredential(Constants.APP_CLIENT_ID,
Constants.APP_CLIENT_SECRET, Roles.USER_ROLE_APPADMIN);
//发送消息到单个用户
public static void sendMsgToUser(String fromUid, String toUid, String content) {
// 给用户发一条文本消息
String from = fromUid;
String targetTypeus = "users";
ObjectNode ext = factory.objectNode();
ArrayNode targetusers = factory.arrayNode();
targetusers.add(toUid);
ObjectNode txtmsg = factory.objectNode();
txtmsg.put("msg", content);
txtmsg.put("type","txt");
ObjectNode sendTxtMessageusernode = sendMessages(targetTypeus, targetusers, txtmsg, from, ext);
if (null != sendTxtMessageusernode) {
LOGGER.info("给" + toUid + "发一条文本消息: " + sendTxtMessageusernode.toString());
}
}
public static void main(String[] args) {
/**
* 注册IM用户[单个]
*/
ObjectNode datanode = JsonNodeFactory.instance.objectNode();
datanode.put("username","test");
datanode.put("password", Constants.DEFAULT_PASSWORD);
ObjectNode createNewIMUserSingleNode = createNewIMUserSingle(datanode);
if (null != createNewIMUserSingleNode) {
LOGGER.info("注册IM用户[单个]: " + createNewIMUserSingleNode.toString());
}
// 检测用户是否在线
// String targetuserPrimaryKey = "683697";
// ObjectNode usernode = getUserStatus(targetuserPrimaryKey);
// if (null != usernode) {
// LOGGER.info("检测用户是否在线: " + usernode.toString());
// }
// 给用户发一条文本消息
/*
String from = "jiayy01";
String targetTypeus = "users";
ObjectNode ext = factory.objectNode();
ArrayNode targetusers = factory.arrayNode();
targetusers.add("683697");
// targetusers.add("lurong02");
ObjectNode txtmsg = factory.objectNode();
txtmsg.put("msg", "Apple Watch! 嘎嘎 嘎嘎 嘎嘎 嘎嘎!!!");
txtmsg.put("type","txt");
ObjectNode sendTxtMessageusernode = sendMessages(targetTypeus, targetusers, txtmsg, from, ext);
if (null != sendTxtMessageusernode) {
LOGGER.info("给用户发一条文本消息: " + sendTxtMessageusernode.toString());
}
*/
/*
// 给一个群组发文本消息
String targetTypegr = "chatgroups";
ArrayNode chatgroupidsNode = (ArrayNode) EasemobChatGroups.getAllChatgroupids().path("data");
ArrayNode targetgroup = factory.arrayNode();
targetgroup.add(chatgroupidsNode.get(0).path("groupid").asText());
ObjectNode sendTxtMessagegroupnode = sendMessages(targetTypegr, targetgroup, txtmsg, from, ext);
if (null != sendTxtMessagegroupnode) {
LOGGER.info("给一个群组发文本消息: " + sendTxtMessagegroupnode.toString());
}
// 给用户发一条图片消息
File uploadImgFile = new File("/home/lynch/Pictures/24849.jpg");
ObjectNode imgDataNode = EasemobFiles.mediaUpload(uploadImgFile);
String imgFileUUID = imgDataNode.path("entities").get(0).path("uuid").asText();
String shareSecret = imgDataNode.path("entities").get(0).path("share-secret").asText();
if (null != imgDataNode) {
LOGGER.info("上传图片文件: " + imgDataNode.toString());
}
ObjectNode imgmsg = factory.objectNode();
imgmsg.put("type","img");
imgmsg.put("url", HTTPClientUtils.getURL(Constants.APPKEY.replace("#", "/") + "/chatfiles/" + imgFileUUID).toString());
imgmsg.put("filename", "24849.jpg");
imgmsg.put("length", 10);
imgmsg.put("secret", shareSecret);
ObjectNode sendimgMessageusernode = sendMessages(targetTypeus, targetusers, imgmsg, from, ext);
if (null != sendimgMessageusernode) {
LOGGER.info("给一个群组发文本消息: " + sendimgMessageusernode.toString());
}
// 给一个群组发图片消息
ObjectNode sendimgMessagegroupnode = sendMessages(targetTypegr, targetgroup, imgmsg, from, ext);
if (null != sendimgMessagegroupnode) {
LOGGER.info("给一个群组发文本消息: " + sendimgMessagegroupnode.toString());
}
// 给用户发一条语音消息
File uploadAudioFile = new File("/home/lynch/Music/music.MP3");
ObjectNode audioDataNode = EasemobFiles.mediaUpload(uploadAudioFile);
String audioFileUUID = audioDataNode.path("entities").get(0).path("uuid").asText();
String audioFileShareSecret = audioDataNode.path("entities").get(0).path("share-secret").asText();
if (null != audioDataNode) {
LOGGER.info("上传语音文件: " + audioDataNode.toString());
}
ObjectNode audiomsg = factory.objectNode();
audiomsg.put("type","audio");
audiomsg.put("url", HTTPClientUtils.getURL(Constants.APPKEY.replace("#", "/") + "/chatfiles/" + audioFileUUID).toString());
audiomsg.put("filename", "music.MP3");
audiomsg.put("length", 10);
audiomsg.put("secret", audioFileShareSecret);
ObjectNode sendaudioMessageusernode = sendMessages(targetTypeus, targetusers, audiomsg, from, ext);
if (null != sendaudioMessageusernode) {
LOGGER.info("给用户发一条语音消息: " + sendaudioMessageusernode.toString());
}
// 给一个群组发语音消息
ObjectNode sendaudioMessagegroupnode = sendMessages(targetTypegr, targetgroup, audiomsg, from, ext);
if (null != sendaudioMessagegroupnode) {
LOGGER.info("给一个群组发语音消息: " + sendaudioMessagegroupnode.toString());
}
// 给用户发一条透传消息
ObjectNode cmdmsg = factory.objectNode();
cmdmsg.put("action", "gogogo");
cmdmsg.put("type","cmd");
ObjectNode sendcmdMessageusernode = sendMessages(targetTypeus, targetusers, cmdmsg, from, ext);
if (null != sendcmdMessageusernode) {
LOGGER.info("给用户发一条透传消息: " + sendcmdMessageusernode.toString());
}
*/
}
/**
* 检测用户是否在线
*
* @param username
*
* @return
*/
public static ObjectNode getUserStatus(String username) {
ObjectNode objectNode = factory.objectNode();
// check appKey format
if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) {
LOGGER.error("Bad format of Appkey: " + APPKEY);
objectNode.put("message", "Bad format of Appkey");
return objectNode;
}
// check properties that must be provided
if (StringUtils.isEmpty(username)) {
LOGGER.error("You must provided a targetUserPrimaryKey .");
objectNode.put("message", "You must provided a targetUserPrimaryKey .");
return objectNode;
}
try {
URL userStatusUrl = HTTPClientUtils.getURL(Constants.APPKEY.replace("#", "/") + "/users/"
+ username + "/status");
objectNode = HTTPClientUtils.sendHTTPRequest(userStatusUrl, credential, null, HTTPMethod.METHOD_GET);
String userStatus = objectNode.get("data").path(username).asText();
if ("online".equals(userStatus)) {
LOGGER.error(String.format("The status of user[%s] is : [%s] .", username, userStatus));
} else if ("offline".equals(userStatus)) {
LOGGER.error(String.format("The status of user[%s] is : [%s] .", username, userStatus));
}
} catch (Exception e) {
e.printStackTrace();
}
return objectNode;
}
/**
* 发送消息
*
* @param targetType
* 消息投递者类型:users 用户, chatgroups 群组
* @param target
* 接收者ID 必须是数组,数组元素为用户ID或者群组ID
* @param msg
* 消息内容
* @param from
* 发送者
* @param ext
* 扩展字段
*
* @return 请求响应
*/
public static ObjectNode sendMessages(String targetType, ArrayNode target, ObjectNode msg, String from,
ObjectNode ext) {
ObjectNode objectNode = factory.objectNode();
ObjectNode dataNode = factory.objectNode();
// check appKey format
if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", APPKEY)) {
LOGGER.error("Bad format of Appkey: " + APPKEY);
objectNode.put("message", "Bad format of Appkey");
return objectNode;
}
// check properties that must be provided
if (!("users".equals(targetType) || "chatgroups".equals(targetType))) {
LOGGER.error("TargetType must be users or chatgroups .");
objectNode.put("message", "TargetType must be users or chatgroups .");
return objectNode;
}
try {
// 构造消息体
dataNode.put("target_type", targetType);
dataNode.put("target", target);
dataNode.put("msg", msg);
dataNode.put("from", from);
dataNode.put("ext", ext);
objectNode = HTTPClientUtils.sendHTTPRequest(EndPoints.MESSAGES_URL, credential, dataNode,
HTTPMethod.METHOD_POST);
objectNode = (ObjectNode) objectNode.get("data");
for (int i = 0; i < target.size(); i++) {
String resultStr = objectNode.path(target.path(i).asText()).asText();
if ("success".equals(resultStr)) {
LOGGER.error(String.format("Message has been send to user[%s] successfully .", target.path(i)
.asText()));
} else if (!"success".equals(resultStr)) {
LOGGER.error(String.format("Message has been send to user[%s] failed .", target.path(i).asText()));
}
}
} catch (Exception e) {
e.printStackTrace();
}
return objectNode;
}
/**
* 注册IM用户[单个]
*
* 给指定Constants.APPKEY创建一个新的用户
*
* @param dataNode
* @return
*/
public static ObjectNode createNewIMUserSingle(ObjectNode dataNode) {
ObjectNode objectNode = factory.objectNode();
// check Constants.APPKEY format
if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", Constants.APPKEY)) {
LOGGER.error("Bad format of Constants.APPKEY: " + Constants.APPKEY);
objectNode.put("message", "Bad format of Constants.APPKEY");
return objectNode;
}
objectNode.removeAll();
// check properties that must be provided
if (null != dataNode && !dataNode.has("username")) {
LOGGER.error("Property that named username must be provided .");
objectNode.put("message", "Property that named username must be provided .");
return objectNode;
}
if (null != dataNode && !dataNode.has("password")) {
LOGGER.error("Property that named password must be provided .");
objectNode.put("message", "Property that named password must be provided .");
return objectNode;
}
try {
objectNode = HTTPClientUtils.sendHTTPRequest(EndPoints.USERS_URL, credential, dataNode,
HTTPMethod.METHOD_POST);
} catch (Exception e) {
e.printStackTrace();
}
return objectNode;
}
/**
* 注册IM用户[批量]
*
* 给指定Constants.APPKEY创建一批用户
*
* @param dataArrayNode
* @return
*/
public static ObjectNode createNewIMUserBatch(ArrayNode dataArrayNode) {
ObjectNode objectNode = factory.objectNode();
// check Constants.APPKEY format
if (!HTTPClientUtils.match("^(?!-)[0-9a-zA-Z\\-]+#[0-9a-zA-Z]+", Constants.APPKEY)) {
LOGGER.error("Bad format of Constants.APPKEY: " + Constants.APPKEY);
objectNode.put("message", "Bad format of Constants.APPKEY");
return objectNode;
}
// check properties that must be provided
if (dataArrayNode.isArray()) {
for (JsonNode jsonNode : dataArrayNode) {
if (null != jsonNode && !jsonNode.has("username")) {
LOGGER.error("Property that named username must be provided .");
objectNode.put("message", "Property that named username must be provided .");
return objectNode;
}
if (null != jsonNode && !jsonNode.has("password")) {
LOGGER.error("Property that named password must be provided .");
objectNode.put("message", "Property that named password must be provided .");
return objectNode;
}
}
}
try {
objectNode = HTTPClientUtils.sendHTTPRequest(EndPoints.USERS_URL, credential, dataArrayNode,
HTTPMethod.METHOD_POST);
} catch (Exception e) {
e.printStackTrace();
}
return objectNode;
}
}
相关推荐
使用Winform做的一个使用unipush给安卓app推送消息的demo,介绍了如何集成个推的sdk和业务处理
各平台手机App消息推送push接口
关于unipush推送消息,手机端接收消息并且展示通知栏的服务端代码资源。 适用于App消息推送,支持在线离线推送消息。适用场景多元化(只需要用户登录App时进行用户信息和手机设备id绑定的处理) 首先要引入unipush的...
环信聊天appDemo
可以为手机端的app使用者推送消息,而不是通过手机上的app对用户发送消息。项目名称改为getuitest
java端给app端发送消息推送需要的jar包支持,极光推送
电商 APP 消息推送规则及模板 内部文档
1、在uni-app 中使用uni push; 2、可以实现在demo 中发送推送
问题的提出 本次接入的是个推,其他...App在前台时,弹出Dialog提醒用户有新消息,但是最新版的个推文档接收推送消息是继承IntentService,无法获取弹出Dialog所需要的Context(注意不能用getApplicationContext()),
各种消息推送的demo,如果不全,请发个demo给我,谢谢
友盟消息推送Java后端,简单集成于springboot,推送次数限制用redis缓存JAVA后端要推送消息给前端的话一般要做定时任务或者轮询,不然就只能等前端请求才能给回应。
金融APP的push计划,包括优先级等,并附有很好地说明,能够高效进行push
APNS(Apple Push Notification Service)苹果推送通知服务。该技术由苹果公司提供的APNS服务。工作原理:首先,APNS会对用户进行物理连接认证,和设备令牌认证(简言之就是苹果的服务器检查设备里的证书已确定其为...
Android中利用App实现消息推送机制
golang 推送系统 单机 客户端通过websocket连接到服务端 ...服务端从rabbitmq接收消息,根据消息所属通过websocket推送到具体用户 服务端从http api接收消息,根据消息所属通过websocket推送到具体用户
华为推送Push平台接口文档,用于华为终端设备(如手机,平板)中的第三方APP通知消息推送。
该demo用于华为推送保护ext扩展字段,其中appId、appSecret、appPkgName需要自己申请
android安卓app开发之亲测能用的APP消息推送例子源码_棒.zip
消息推送(Push SDK) 友盟消息推送,帮助开发者建立于用户直接沟通的渠道。将APP的内 友盟推送PushSDK 友盟推送PushSDK 容更新或者活动通知主动推送给终端用户,让用户第一时间获取到相关信息,有效提升用户活跃度...
这是在做项目开发之前练习的一个消息推送小功能,可自主设置推送标题与与内容,并且点击后自自动跳转到对应的active。