mirror of
https://gitee.com/farsunset/cim.git
synced 2025-07-20 23:06:43 +08:00
no message
This commit is contained in:
parent
fa14078188
commit
15f44ee285
@ -8,7 +8,9 @@ import org.apache.struts2.ServletActionContext;
|
|||||||
import org.springframework.web.bind.ServletRequestBindingException;
|
import org.springframework.web.bind.ServletRequestBindingException;
|
||||||
|
|
||||||
import com.farsunset.cim.nio.mutual.Message;
|
import com.farsunset.cim.nio.mutual.Message;
|
||||||
|
import com.farsunset.ichat.cim.push.DefaultMessagePusher;
|
||||||
import com.farsunset.ichat.cim.push.SystemMessagePusher;
|
import com.farsunset.ichat.cim.push.SystemMessagePusher;
|
||||||
|
import com.farsunset.ichat.common.util.Constants;
|
||||||
import com.farsunset.ichat.common.util.ContextHolder;
|
import com.farsunset.ichat.common.util.ContextHolder;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.opensymphony.xwork2.ActionSupport;
|
import com.opensymphony.xwork2.ActionSupport;
|
||||||
@ -43,8 +45,15 @@ public class MessageAction extends ActionSupport implements ModelDriven<Messa
|
|||||||
|
|
||||||
checkParams();
|
checkParams();
|
||||||
|
|
||||||
|
if(Constants.MessageType.TYPE_2.equals(message.getType()))
|
||||||
|
{
|
||||||
//Ïò¿Í»§¶Ë ·¢ËÍÏûÏ¢
|
//Ïò¿Í»§¶Ë ·¢ËÍÏûÏ¢
|
||||||
ContextHolder.getBean(SystemMessagePusher.class).pushMessageToUser(message);
|
ContextHolder.getBean(SystemMessagePusher.class).pushMessageToUser(message);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
//向客户端 发送消息
|
||||||
|
ContextHolder.getBean(DefaultMessagePusher.class).pushMessageToUser(message);
|
||||||
|
}
|
||||||
|
|
||||||
data.put("id", message.getMid());
|
data.put("id", message.getMid());
|
||||||
data.put("createTime", String.valueOf(message.getTimestamp()));
|
data.put("createTime", String.valueOf(message.getTimestamp()));
|
||||||
|
@ -42,32 +42,9 @@ public interface Constants {
|
|||||||
//用户之间的普通消息
|
//用户之间的普通消息
|
||||||
public static final String TYPE_0 = "0";
|
public static final String TYPE_0 = "0";
|
||||||
|
|
||||||
public static final String TYPE_1 = "1";
|
|
||||||
|
|
||||||
//系统向用户发送的普通消息
|
//系统向用户发送的普通消息
|
||||||
public static final String TYPE_2 = "2";
|
public static final String TYPE_2 = "2";
|
||||||
|
|
||||||
//群里用户发送的 消息
|
|
||||||
public static final String TYPE_3 = "3";
|
|
||||||
|
|
||||||
//系统定制消息---好友验证请求
|
|
||||||
String TYPE_100 = "100";
|
|
||||||
|
|
||||||
//系统定制消息---同意好友请求
|
|
||||||
String TYPE_101 = "101";
|
|
||||||
|
|
||||||
//系统定制消息---进群请求
|
|
||||||
String TYPE_102 = "102";
|
|
||||||
|
|
||||||
//系统定制消息---同意进群请求
|
|
||||||
String TYPE_103 = "103";
|
|
||||||
|
|
||||||
|
|
||||||
//系统定制消息---好友下线消息
|
|
||||||
String TYPE_900 = "900";
|
|
||||||
|
|
||||||
//系统定制消息---好友上线消息
|
|
||||||
String TYPE_901 = "901";
|
|
||||||
}
|
}
|
||||||
|
|
||||||
}
|
}
|
||||||
|
@ -13,11 +13,13 @@ import android.view.View;
|
|||||||
import android.view.View.OnClickListener;
|
import android.view.View.OnClickListener;
|
||||||
import android.widget.ListView;
|
import android.widget.ListView;
|
||||||
import android.widget.TextView;
|
import android.widget.TextView;
|
||||||
|
|
||||||
import com.alibaba.fastjson.JSONObject;
|
import com.alibaba.fastjson.JSONObject;
|
||||||
import com.alibaba.fastjson.TypeReference;
|
import com.alibaba.fastjson.TypeReference;
|
||||||
import com.farsunset.cim.client.android.CIMPushManager;
|
import com.farsunset.cim.client.android.CIMPushManager;
|
||||||
import com.farsunset.cim.nio.constant.CIMConstant;
|
import com.farsunset.cim.nio.constant.CIMConstant;
|
||||||
import com.farsunset.cim.nio.mutual.Message;
|
import com.farsunset.cim.nio.mutual.Message;
|
||||||
|
import com.farsunset.cim.nio.mutual.SentBody;
|
||||||
import com.farsunset.ichat.example.R;
|
import com.farsunset.ichat.example.R;
|
||||||
import com.farsunset.ichat.example.adapter.SystemMsgListViewAdapter;
|
import com.farsunset.ichat.example.adapter.SystemMsgListViewAdapter;
|
||||||
import com.farsunset.ichat.example.app.CIMMonitorActivity;
|
import com.farsunset.ichat.example.app.CIMMonitorActivity;
|
||||||
@ -88,6 +90,14 @@ public class SystemMessageActivity extends CIMMonitorActivity implements OnClick
|
|||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
//获取离线消息,代码示例,前提是服务端要实现此功能
|
||||||
|
private void getOfflineMessage()
|
||||||
|
{
|
||||||
|
SentBody sent = new SentBody();
|
||||||
|
sent.setKey(CIMConstant.RequestKey.CLIENT_OFFLINE_MESSAGE);
|
||||||
|
sent.put("account", this.getIntent().getStringExtra("account"));
|
||||||
|
CIMPushManager.sendRequest(this, sent);
|
||||||
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
public void onConnectionSucceed() {
|
public void onConnectionSucceed() {
|
||||||
@ -112,14 +122,7 @@ public class SystemMessageActivity extends CIMMonitorActivity implements OnClick
|
|||||||
private void sendMessage() throws Exception
|
private void sendMessage() throws Exception
|
||||||
{
|
{
|
||||||
|
|
||||||
|
|
||||||
apiParams.put("content", "hello world!");
|
|
||||||
apiParams.put("sender", "xiaogou");//发送者账号
|
|
||||||
apiParams.put("receiver", "xiaomao");//消息接收者账号
|
|
||||||
apiParams.put("type",Constant.MessageType.TYPE_0);
|
|
||||||
|
|
||||||
requester.execute(new TypeReference<JSONObject>(){}.getType(), null, SEND_MESSAGE_API_URL);
|
requester.execute(new TypeReference<JSONObject>(){}.getType(), null, SEND_MESSAGE_API_URL);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
|
||||||
@Override
|
@Override
|
||||||
@ -136,6 +139,12 @@ public class SystemMessageActivity extends CIMMonitorActivity implements OnClick
|
|||||||
|
|
||||||
@Override
|
@Override
|
||||||
public Map<String, Object> getRequestParams() {
|
public Map<String, Object> getRequestParams() {
|
||||||
|
|
||||||
|
apiParams.put("content", "hello world!");
|
||||||
|
apiParams.put("sender", "xiaogou");//发送者账号
|
||||||
|
apiParams.put("receiver", "xiaomao");//消息接收者账号
|
||||||
|
apiParams.put("type",Constant.MessageType.TYPE_0);
|
||||||
|
|
||||||
return apiParams;
|
return apiParams;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -8,7 +8,9 @@ import org.apache.struts2.ServletActionContext;
|
|||||||
import org.springframework.web.bind.ServletRequestBindingException;
|
import org.springframework.web.bind.ServletRequestBindingException;
|
||||||
|
|
||||||
import com.farsunset.cim.nio.mutual.Message;
|
import com.farsunset.cim.nio.mutual.Message;
|
||||||
|
import com.farsunset.ichat.cim.push.DefaultMessagePusher;
|
||||||
import com.farsunset.ichat.cim.push.SystemMessagePusher;
|
import com.farsunset.ichat.cim.push.SystemMessagePusher;
|
||||||
|
import com.farsunset.ichat.common.util.Constants;
|
||||||
import com.farsunset.ichat.common.util.ContextHolder;
|
import com.farsunset.ichat.common.util.ContextHolder;
|
||||||
import com.google.gson.Gson;
|
import com.google.gson.Gson;
|
||||||
import com.opensymphony.xwork2.ActionSupport;
|
import com.opensymphony.xwork2.ActionSupport;
|
||||||
@ -27,10 +29,10 @@ public class MessageAction extends ActionSupport implements ModelDriven<Messa
|
|||||||
Message message = new Message();
|
Message message = new Message();
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD>http<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD> struts2 <EFBFBD><EFBFBD>ģ<EFBFBD><EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD> http <EFBFBD><EFBFBD><EFBFBD><EFBFBD> sender=xiaomao&receiver=xiaogou
|
* 关于http参数获取, struts2 的模型驱动 比如 http 参数 sender=xiaomao&receiver=xiaogou
|
||||||
* struts<EFBFBD>Զ<EFBFBD><EFBFBD>Ὣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ֵ <EFBFBD><EFBFBD><EFBFBD><EFBFBD>getModel()<EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD>Ķ<EFBFBD>Ӧ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>У<EFBFBD><EFBFBD><EFBFBD>xiaomao<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>message.sender<EFBFBD><EFBFBD><EFBFBD><EFBFBD>,xiaogou<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>message.receiver<EFBFBD><EFBFBD><EFBFBD><EFBFBD>
|
* struts自动会将参数的值 存入getModel()返回的对象的对应属性中,即xiaomao会存入message.sender属性,xiaogou会存入message.receiver属性
|
||||||
* ʡȥ<EFBFBD><EFBFBD>request.getParameter("sender")<EFBFBD><EFBFBD>ʽ<EFBFBD><EFBFBD>ȡ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>getModel()<EFBFBD><EFBFBD><EFBFBD>صĶ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>в<EFBFBD><EFBFBD><EFBFBD><EFBFBD>ڣ<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ҫ<EFBFBD><EFBFBD>request.getParameter()<EFBFBD><EFBFBD>ȡ
|
* 省去了request.getParameter("sender")方式获取参数,,如果参数名在getModel()返回的对象中不存在,则需要用request.getParameter()获取
|
||||||
* <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>*Action.java<EFBFBD><EFBFBD> ͬ<EFBFBD>?<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>ͳһ˵<EFBFBD><EFBFBD>!
|
* 其他相关*Action.java中 同理,这里做统一说明!
|
||||||
*/
|
*/
|
||||||
public String send() throws Exception {
|
public String send() throws Exception {
|
||||||
|
|
||||||
@ -43,8 +45,15 @@ public class MessageAction extends ActionSupport implements ModelDriven<Messa
|
|||||||
|
|
||||||
checkParams();
|
checkParams();
|
||||||
|
|
||||||
//<EFBFBD><EFBFBD>ͻ<EFBFBD><EFBFBD><EFBFBD> <EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϣ
|
if(Constants.MessageType.TYPE_2.equals(message.getType()))
|
||||||
|
{
|
||||||
|
//向客户端 发送消息
|
||||||
ContextHolder.getBean(SystemMessagePusher.class).pushMessageToUser(message);
|
ContextHolder.getBean(SystemMessagePusher.class).pushMessageToUser(message);
|
||||||
|
}else
|
||||||
|
{
|
||||||
|
//向客户端 发送消息
|
||||||
|
ContextHolder.getBean(DefaultMessagePusher.class).pushMessageToUser(message);
|
||||||
|
}
|
||||||
|
|
||||||
data.put("id", message.getMid());
|
data.put("id", message.getMid());
|
||||||
data.put("createTime", String.valueOf(message.getTimestamp()));
|
data.put("createTime", String.valueOf(message.getTimestamp()));
|
||||||
@ -63,7 +72,7 @@ public class MessageAction extends ActionSupport implements ModelDriven<Messa
|
|||||||
|
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* <EFBFBD>ļ<EFBFBD><EFBFBD>ɿͻ<EFBFBD><EFBFBD>˷<EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD><EFBFBD> OSS <EFBFBD>洢
|
* 文件由客户端发往阿里云 OSS 存储
|
||||||
* @param messageServiceImpl
|
* @param messageServiceImpl
|
||||||
*/
|
*/
|
||||||
/* private void fileHandler(Message mo, HttpServletRequest request) throws IOException
|
/* private void fileHandler(Message mo, HttpServletRequest request) throws IOException
|
||||||
@ -78,7 +87,7 @@ public class MessageAction extends ActionSupport implements ModelDriven<Messa
|
|||||||
String dir = dirMap.get(fileType);
|
String dir = dirMap.get(fileType);
|
||||||
if(StringUtils.isEmpty(dir))
|
if(StringUtils.isEmpty(dir))
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("fileType:" +fileType+" δ<EFBFBD><EFBFBD><EFBFBD><EFBFBD>" );
|
throw new IllegalArgumentException("fileType:" +fileType+" 未定义" );
|
||||||
|
|
||||||
}
|
}
|
||||||
String path = request.getSession().getServletContext().getRealPath(dir);
|
String path = request.getSession().getServletContext().getRealPath(dir);
|
||||||
@ -98,7 +107,7 @@ public class MessageAction extends ActionSupport implements ModelDriven<Messa
|
|||||||
|
|
||||||
if(StringUtils.isEmpty(message.getReceiver()))
|
if(StringUtils.isEmpty(message.getReceiver()))
|
||||||
{
|
{
|
||||||
throw new IllegalArgumentException("receiver <EFBFBD><EFBFBD><EFBFBD><EFBFBD>Ϊ<EFBFBD><EFBFBD>!");
|
throw new IllegalArgumentException("receiver 不能为空!");
|
||||||
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
@ -17,6 +17,7 @@ import com.alibaba.fastjson.JSONObject;
|
|||||||
import com.alibaba.fastjson.TypeReference;
|
import com.alibaba.fastjson.TypeReference;
|
||||||
import com.farsunset.cim.client.android.CIMPushManager;
|
import com.farsunset.cim.client.android.CIMPushManager;
|
||||||
import com.farsunset.cim.nio.constant.CIMConstant;
|
import com.farsunset.cim.nio.constant.CIMConstant;
|
||||||
|
import com.farsunset.cim.nio.mutual.SentBody;
|
||||||
import com.farsunset.cim.nio.mutual.Message;
|
import com.farsunset.cim.nio.mutual.Message;
|
||||||
import com.farsunset.ichat.example.R;
|
import com.farsunset.ichat.example.R;
|
||||||
import com.farsunset.ichat.example.adapter.SystemMsgListViewAdapter;
|
import com.farsunset.ichat.example.adapter.SystemMsgListViewAdapter;
|
||||||
@ -64,6 +65,17 @@ public class SystemMessageActivity extends CIMMonitorActivity implements OnClick
|
|||||||
showToask("登录成功,请通过后台页面发送消息吧^_^");
|
showToask("登录成功,请通过后台页面发送消息吧^_^");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
//获取离线消息,代码示例,前提是服务端要实现此功能
|
||||||
|
private void getOfflineMessage()
|
||||||
|
{
|
||||||
|
SentBody sent = new SentBody();
|
||||||
|
sent.setKey(CIMConstant.RequestKey.CLIENT_OFFLINE_MESSAGE);
|
||||||
|
sent.put("account", this.getIntent().getStringExtra("account"));
|
||||||
|
CIMPushManager.sendRequest(this, sent);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
//收到消息
|
//收到消息
|
||||||
@Override
|
@Override
|
||||||
public void onMessageReceived(com.farsunset.cim.nio.mutual.Message message) {
|
public void onMessageReceived(com.farsunset.cim.nio.mutual.Message message) {
|
||||||
|
Loading…
x
Reference in New Issue
Block a user