Helius
2020-05-31 7db3689070adf273d1d23487eeccb327c33b1ab8
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
package com.xcong.excoin.netty.logic;
 
import com.alibaba.fastjson.JSONObject;
import com.xcong.excoin.netty.bean.RequestBean;
import com.xcong.excoin.netty.bean.ResponseBean;
import com.xcong.excoin.netty.common.ChannelManager;
import com.xcong.excoin.netty.common.NettyTools;
import io.netty.channel.Channel;
import org.springframework.stereotype.Component;
 
 
/**
 * @author wzy
 * @email wangdoubleone@gmail.com
 * @date 2019-05-09
 */
@Component
public class WebSocketLogic {
 
 
    public void webReqConnection(RequestBean requestBean) {
        Channel channel = ChannelManager.findWebSocketChannel(requestBean.getChannelId());
        channel.writeAndFlush(NettyTools.webSocketBytes("this is ok"));
    }
 
    public void reqHomeSymbols(RequestBean requestBean) {
        String params = requestBean.getParams();
        JSONObject jsonObject = JSONObject.parseObject(params);
        String token = jsonObject.getString("token");
        String type = jsonObject.getString("type");
        ResponseBean responseBean = ResponseBean.ok(requestBean.getType(), null);
 
        Channel channel = ChannelManager.findWebSocketChannel(requestBean.getChannelId());
        channel.writeAndFlush(NettyTools.webSocketBytes(JSONObject.toJSONString(responseBean)));
    }
 
    public void defaultReq(RequestBean requestBean) {
        Channel channel = ChannelManager.findWebSocketChannel(requestBean.getChannelId());
        channel.writeAndFlush("this is error type");
    }
}