GLPushManager.java
9.74 KB
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
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
package com.glsx.pushsdk.manager;
import android.content.Context;
import android.text.TextUtils;
import com.blankj.utilcode.util.LogUtils;
import com.glsx.pushsdk.biz.BizClient;
import com.glsx.pushsdk.common.NetStatu;
import com.glsx.pushsdk.common.Param;
import com.glsx.pushsdk.iface.PushBackFace;
import com.glsx.pushsdk.model.GetOffLineIdItem;
import com.glsx.pushsdk.model.GetOfflLineDataResult;
import com.glsx.pushsdk.model.LoginResult;
import com.glsx.pushsdk.tools.Tools;
import java.util.ArrayList;
import java.util.List;
import io.netty.channel.ChannelHandlerContext;
/**
* @author YFZX-yulg 2016-11-7 GL:广联,广联赛讯简称 广联赛讯的接入平台推送
*/
public class GLPushManager {
private static String TAG = "GLPushManager";
private Context myContext;
private String appKey = "";//应用Appkey
private String channelSecret = "";//应用秘钥
private String imei = "";
private String typy = "1";//设备类型 0:ios 1:android
private String appUserId = "";//第三方用户账号 如果没有账号体系的 直接填写终端唯一标识 如IMEI等
private String sdkVersion = "1.1.0.0";// 当前SDK本号
private String chIosDevToken = "";//ios使用, android里面这个参数传"" ,ntype为0时 ios device token 可以点""
private String appVersion = "";// 当前终端应用版本号
private String glsxKey = "";//登陆成功之后返回的glsxKey
private LoginResult mLoginResult;//登录成功返回结果数据
private PushBackFace mPushBackFace;//Login回调处理
private BizClient bizClient;// 链接业务服务器的客户端
private ChannelHandlerContext mChannelHandlerContext;
private static GLPushManager glPushManager;
public static GLPushManager getInstance() {
if (glPushManager == null) {
synchronized (GLPushManager.class) {
if (glPushManager == null) {
glPushManager = new GLPushManager();
}
}
}
return glPushManager;
}
/**
* 初始化参数
*
*/
public void init(Context mContext) {
this.myContext = mContext;
String userId = Tools.getUserFlag(mContext);
if (!TextUtils.isEmpty(userId)) {
setAppUserId(userId);
}
// 设置IMei参数
setImei(Tools.getImei(myContext));
// 设置用户accoudId,如何为空,设置imei
// 获取AppKey
if (!TextUtils.isEmpty(Tools.getAppKey(mContext))) {
setAppKey(Tools.getAppKey(mContext));
}
// 获取channel_secret
if (!TextUtils.isEmpty(Tools.getChannelSecret(mContext))) {
setChannelSecret(Tools.getChannelSecret(mContext));
}
// 获取应用App版本号
if (!TextUtils.isEmpty(Tools.getAppVersion(myContext))) {
setAppVersion(Tools.getAppVersion(myContext));
} else {
setAppVersion(Tools.getVersonCode(myContext));
}
LogUtils.i("ylgHandler", "Context = " + mContext + "\n" + "Imei = " + imei + "\n"
+ "appUserId = " + appUserId + "\n" + "appKey = " + appKey + "\n" + "appVerion = " + appVersion
+ "\n" + "channelSecret = " + channelSecret + "\n"
+ "mPushBackFace = " + mPushBackFace);
// 链接服务器
GLPushManager.getInstance().connectServer();
}
public String getAppKey() {
return appKey;
}
public void setAppKey(String appKey) {
this.appKey = appKey;
}
public String getChannelSecret() {
return channelSecret;
}
public void setChannelSecret(String channelSecret) {
this.channelSecret = channelSecret;
}
public String getImei() {
return imei;
}
public void setImei(String imei) {
this.imei = imei;
}
public String getTypy() {
return typy;
}
public void setTypy(String typy) {
this.typy = typy;
}
public String getAppUserId() {
return appUserId;
}
public void setAppUserId(String appUserId) {
this.appUserId = appUserId;
}
public String getSdkVersion() {
return sdkVersion;
}
public void setSdkVersion(String sdkVersion) {
this.sdkVersion = sdkVersion;
}
public String getAppVersion() {
return appVersion;
}
public void setAppVersion(String appVersion) {
this.appVersion = appVersion;
}
public String getChIosDevToken() {
return chIosDevToken;
}
public void setChIosDevToken(String chIosDevToken) {
this.chIosDevToken = chIosDevToken;
}
public String getGlsxKey() {
return glsxKey;
}
public void setGlsxKey(String glsxKey) {
this.glsxKey = glsxKey;
}
public LoginResult getmLoginResult() {
return mLoginResult;
}
public void setmLoginResult(LoginResult mLoginResult) {
this.mLoginResult = mLoginResult;
}
public PushBackFace getmPushBackFace() {
return mPushBackFace;
}
public void setmPushBackFace(PushBackFace mPushBackFace) {
this.mPushBackFace = mPushBackFace;
}
public ChannelHandlerContext getmChannelHandlerContext() {
return mChannelHandlerContext;
}
public void setmChannelHandlerContext(ChannelHandlerContext mChannelHandlerContext) {
this.mChannelHandlerContext = mChannelHandlerContext;
}
public Context getMyContext() {
return myContext;
}
public void setMyContext(Context myContext) {
this.myContext = myContext;
}
/**
* 设置用户的UserId
*
*/
public void setUserId(String userId) {
if (!TextUtils.isEmpty(userId)) {
this.setAppUserId(userId);
Tools.saveUserFlag(myContext, userId);
buildSetUserId();
}
}
/**
* 退出登录
*/
public void exitLogin() {
buildExit();
}
/**
* 连接服务器
*/
public void connectServer() {
LogUtils.d(TAG, "connectServer NetStatu.busiStatus= " + NetStatu.busiStatus);
if (NetStatu.busiStatus == NetStatu.LOGINED_BUSSERVER_SUCCESS && bizClient != null) {
return;
}
bizClient = BizClient.getInstance();
bizClient.startClient();
}
/**
* 关闭业务服务器链接
*/
public void closeBizConnect() {
if (bizClient != null) {
bizClient.closeConnect();
}
}
/**
* 关闭tcp连接
*/
public void closeAll() {
if (bizClient != null) {
bizClient.closeAll();
LogUtils.w(TAG, "closeAll3");
}
}
/**
* 登录
*/
public void buildLogin() {
if (NetStatu.busiStatus == NetStatu.LOGINED_BUSSERVER_SUCCESS && bizClient != null) {
writeMsg(Param.buildLoginData());
}
}
/**
* 获取离线数据
*/
public void buildGetOffLineData() {
if (NetStatu.busiStatus == NetStatu.LOGINED_BUSSERVER_SUCCESS && bizClient != null) {
LogUtils.i(TAG, "开始获取离线数据请求");
writeMsg(Param.buildOffLineData());
}
}
/**
* 根据联系数据ID获取详情封装
*/
public void buildGetOffLineDetailData() {
if (NetStatu.busiStatus == NetStatu.LOGINED_BUSSERVER_SUCCESS && bizClient != null) {
LogUtils.i(TAG, "开始进行获取离线消息详情请求");
GetOfflLineDataResult result = DataManager.getInstance().getmGetOfflLineDataResult();
if (null != result) {
List<GetOffLineIdItem> list = result.getmListMsgId();
if (null != list && list.size() > 0) {
writeMsg(Param.buildOffLineDetailData(list));
result.setCount(0);
result.setmListMsgId(null);
DataManager.getInstance().setmGetOfflLineDataResult(result);
}
}
}
}
/**
* 退出登录请求
*/
public void buildExit() {
if (NetStatu.busiStatus == NetStatu.LOGINED_BUSSERVER_SUCCESS && bizClient != null) {
LogUtils.i(TAG, "开始进行退出登录请求");
writeMsg(Param.buildExitData());
}
}
/**
* 重新设置userId
*/
public void buildSetUserId() {
if (NetStatu.busiStatus == NetStatu.LOGINED_BUSSERVER_SUCCESS && bizClient != null) {
LogUtils.i(TAG, "ylgHandler开始进行重新设置UserFlag请求");
writeMsg(Param.buildSetUserIdData());
} else {
LogUtils.i(TAG, "ylgHandler,buildSetUserId failed()");
}
}
/**
* 发送SDK版本
*/
public void buildSetSdkVersion() {
if (NetStatu.busiStatus == NetStatu.LOGINED_BUSSERVER_SUCCESS && bizClient != null) {
writeMsg(Param.buildSendSdkVersion(0, 1));
}
}
/**
* 终端点击消息通知
*/
public void buildSetMsgId(List<String> msgId) {
if (msgId == null || msgId.size() == 0) {
return;
}
if (NetStatu.busiStatus == NetStatu.LOGINED_BUSSERVER_SUCCESS && bizClient != null) {
LogUtils.i(TAG, "开始进行终端点击消息通知请求");
List<GetOffLineIdItem> mListId = new ArrayList<GetOffLineIdItem>();
for (int i = 0; i < msgId.size(); i++) {
GetOffLineIdItem item = new GetOffLineIdItem();
item.setMsgId(msgId.get(i));
mListId.add(item);
}
writeMsg(Param.buildSetMsgId(mListId));
}
}
/**
* 发送数据
*/
public void writeMsg(Object buildOffLineData) {
if (mChannelHandlerContext != null) {
mChannelHandlerContext.writeAndFlush(buildOffLineData);
}
}
}