Param.java
12.9 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
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
package com.glsx.pushsdk.common;
import android.annotation.SuppressLint;
import com.blankj.utilcode.util.LogUtils;
import com.glsx.pushsdk.manager.GLPushManager;
import com.glsx.pushsdk.model.GetOffLineIdItem;
import com.glsx.pushsdk.model.proto.MsgClient;
import com.glsx.pushsdk.model.proto.MsgClient.ClientGetMsgContextByMsgIdsReq;
import com.glsx.pushsdk.model.proto.MsgClient.ClientGetOfflineMsgReq;
import com.glsx.pushsdk.model.proto.MsgClient.ClientGetSdkVersionReq;
import com.glsx.pushsdk.model.proto.MsgClient.ClientHeartBeatReq;
import com.glsx.pushsdk.model.proto.MsgClient.ClientLoginReq;
import com.glsx.pushsdk.model.proto.MsgClient.ClientLogoutReq;
import com.glsx.pushsdk.model.proto.MsgClient.ClientUpAppUserFlagReq;
import com.glsx.pushsdk.model.proto.MsgClient.NotifyMsgToClientRsp;
import com.glsx.pushsdk.tools.ProtocolHandler;
import com.google.protobuf.ByteString;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* 封装向业务服务器请求数据 感觉好坑呀,要死人,搞了半天才搞出第一个 夸平台数数据真蛋疼
*
* @author YFZX-yulg
*/
public class Param {
public static final String TAG = "Param";
/**
* 终端类型0:ios 1:android
*
* @return
*/
/* public static RequestParams getAccessIport() {
Map<String, String> map = new HashMap<String, String>();
map.put("type", "1");
return getParams(map);
}*/
public static Map<String, String> getAccessIport() {
Map<String, String> map = new HashMap<String, String>();
map.put("type", "1");
return map;
}
/**
* 获取Param
* @param map
* @return
*/
/*public static RequestParams getParams(Map<String, String> map) {
RequestParams params = new RequestParams();
Iterator<String> key = map.keySet().iterator();
while (key.hasNext()) {
String key_s = key.next();
params.addQueryStringParameter(key_s, map.get(key_s));
}
return params;
}*/
/**
* 数组拼接
*
* @param first
* @param rest
* @return
*/
@SuppressLint("NewApi")
public static byte[] concatAll(byte[] first, byte[]... rest) {
int totalLength = first.length;
for (byte[] array : rest) {
totalLength += array.length;
}
byte[] result = Arrays.copyOf(first, totalLength);
int offset = first.length;
for (byte[] array : rest) {
System.arraycopy(array, 0, result, offset, array.length);
offset += array.length;
}
return result;
}
/**
* 登录验证,设置请求参数
*
* @return
*/
public static byte[] buildLoginData() {
byte[] allData = null;
try {
MsgClient.ClientLoginReq.Builder loginReqBuilder = MsgClient.ClientLoginReq
.newBuilder();
loginReqBuilder.setChAppKey(ByteString.copyFrom(GLPushManager
.getInstance().getAppKey().getBytes()));// appkey
loginReqBuilder.setChannelSecret(ByteString.copyFrom(GLPushManager
.getInstance().getChannelSecret().getBytes()));// 通道密钥
loginReqBuilder.setChImei(ByteString.copyFrom(GLPushManager
.getInstance().getImei().getBytes()));// imei
loginReqBuilder.setNType(ByteString.copyFrom(GLPushManager
.getInstance().getTypy().getBytes()));// 终端类型0:ios
// 1:android
loginReqBuilder.setChSdkVno(ByteString.copyFrom(GLPushManager
.getInstance().getSdkVersion().getBytes()));// SDK当前版本号
loginReqBuilder.setChIosDevToken(ByteString.copyFrom(GLPushManager
.getInstance().getChIosDevToken().getBytes()));// SDK当前版本号
loginReqBuilder.setChAppUserFlag(ByteString.copyFrom(GLPushManager
.getInstance().getAppUserId().getBytes()));// 第三方用户账号,
// 如果没有账号体系的,
// 直接填写终端唯一标识,如IMEI等
loginReqBuilder.setChAppVersion(ByteString.copyFrom(GLPushManager
.getInstance().getAppVersion().getBytes()));// 应用版本号
ClientLoginReq loginReq = loginReqBuilder.build();
allData = loginReq.toByteArray();// 转换的数据
} catch (Exception e) {
LogUtils.i("TAG", "e = " + e);
}
return ProtocolHandler.getProtocolHead(allData, CmdContants.LOGIN_SEND,
CmdContants.FLAGS_F2);
}
/**
* 心跳包数据封装
*
* @return
*/
public static Object buildHeartBeatData() {
byte[] allData = null;
try {
MsgClient.ClientHeartBeatReq.Builder heartBeatReqBuilder = MsgClient.ClientHeartBeatReq
.newBuilder();
heartBeatReqBuilder.setChGlsxKey(ByteString.copyFrom(GLPushManager
.getInstance().getmLoginResult().getGlsxkey().getBytes()));
ClientHeartBeatReq heartReq = heartBeatReqBuilder.build();
allData = heartReq.toByteArray();// 转换的数据
} catch (Exception e) {
LogUtils.i("TAG", "e = " + e);
}
return ProtocolHandler.getProtocolHead(allData, CmdContants.HEART_SEND,
CmdContants.FLAGS_F2);
}
/**
* 获取离线数据封装
*
* @return
* @author YFZX-yulg 2016-11-15
*/
public static Object buildOffLineData() {
byte[] allData = null;
try {
MsgClient.ClientGetOfflineMsgReq.Builder getOffLineReqBuilder = MsgClient.ClientGetOfflineMsgReq
.newBuilder();
getOffLineReqBuilder.setChGlsxKey(ByteString.copyFrom(GLPushManager
.getInstance().getmLoginResult().getGlsxkey().getBytes()));
ClientGetOfflineMsgReq req = getOffLineReqBuilder.build();
allData = req.toByteArray();// 转换的数据
} catch (Exception e) {
LogUtils.i("TAG", "e = " + e);
}
LogUtils.i("ylg", "请求获取离线数据");
return ProtocolHandler.getProtocolHead(allData,
CmdContants.GET_OFF_LINE_SEND, CmdContants.FLAGS_F2);
}
/**
* 根据联系数据ID获取详情封装
*
* @author YFZX-yulg 2016-11-15
*/
public static Object buildOffLineDetailData(List<GetOffLineIdItem> mListMsgId) {
byte[] allData = null;
try {
MsgClient.ClientGetMsgContextByMsgIdsReq.Builder reqBuilder =
MsgClient.ClientGetMsgContextByMsgIdsReq.newBuilder();
reqBuilder.setChGlsxKey(ByteString.copyFrom(GLPushManager.getInstance()
.getmLoginResult().getGlsxkey().getBytes()));
for (int i = 0; i < mListMsgId.size(); i++) {
MsgClient.MsgId.Builder msgIdBuilder = MsgClient.MsgId.newBuilder();
msgIdBuilder.setChMsgId(ByteString.copyFrom(mListMsgId.get(i).getMsgId().getBytes()));
reqBuilder.addChMsgIds(i, msgIdBuilder);// 加载消息ID集合
}
ClientGetMsgContextByMsgIdsReq req = reqBuilder.build();
allData = req.toByteArray();// 转换的数据
} catch (Exception e) {
LogUtils.i("TAG", "e = " + e);
}
LogUtils.i("ylg", "请求根据联系数据ID获取详情封装");
return ProtocolHandler.getProtocolHead(allData,
CmdContants.GET_OFF_LINE_DETAIL_MESSAGE_SEND,
CmdContants.FLAGS_F2);
}
/**
* 请求退出登录
*
* @return
*/
public static Object buildExitData() {
// TODO Auto-generated method stub
byte[] allData = null;
try {
MsgClient.ClientLogoutReq.Builder reqBuilder = MsgClient.ClientLogoutReq
.newBuilder();
reqBuilder.setChGlsxKey(ByteString.copyFrom(GLPushManager
.getInstance().getmLoginResult().getGlsxkey().getBytes()));
ClientLogoutReq req = reqBuilder.build();
allData = req.toByteArray();// 转换的数据
} catch (Exception e) {
LogUtils.i("TAG", "e = " + e);
}
LogUtils.i("ylg", "请求退出登录");
return ProtocolHandler.getProtocolHead(allData, CmdContants.EXIT_SEND,
CmdContants.FLAGS_F2);
}
/**
* 获取SDK版本
*
* @param flag 0:按照终端类型获取最新版本信息 1按照版本号查询版本信息
* @param type 终端类型 0:ios,1:android
* @return
*/
public static Object buildSendSdkVersion(int flag, int type) {
// TODO Auto-generated method stub
byte[] allData = null;
try {
MsgClient.ClientGetSdkVersionReq.Builder reqBuilder = MsgClient.ClientGetSdkVersionReq
.newBuilder();
reqBuilder.setChSdkVno(ByteString.copyFrom(GLPushManager
.getInstance().getSdkVersion().getBytes()));
reqBuilder.setNFlag(flag);
reqBuilder.setNType(type);
ClientGetSdkVersionReq req = reqBuilder.build();
allData = req.toByteArray();// 转换的数据
} catch (Exception e) {
LogUtils.i("TAG", "e = " + e);
}
LogUtils.i("ylg", "请求获取SDK版本");
return ProtocolHandler.getProtocolHead(allData,
CmdContants.GET_VERSION_SEND, CmdContants.FLAGS_F2);
}
/**
* 回调服务器推送获取请求
*
* @return
*/
public static Object buildSendData(short seq, String msgId,
String currentTime) {
// TODO Auto-generated method stub
byte[] allData = null;
try {
MsgClient.NotifyMsgToClientRsp.Builder reqBuilder = MsgClient.NotifyMsgToClientRsp
.newBuilder();
reqBuilder.setChGlsxKey(ByteString.copyFrom(GLPushManager
.getInstance().getmLoginResult().getGlsxkey().getBytes()));
reqBuilder.setChErrDesc(ByteString.copyFrom("".getBytes()));
reqBuilder.setNRetCode(0);
reqBuilder.setChRvTime(ByteString.copyFrom(currentTime.getBytes()));
reqBuilder.setChMsgId(ByteString.copyFrom(msgId.getBytes()));
NotifyMsgToClientRsp req = reqBuilder.build();
allData = req.toByteArray();// 转换的数据
} catch (Exception e) {
LogUtils.i("TAG", "e = " + e);
}
return ProtocolHandler
.getProtocolHead(allData, CmdContants.SERVER_PUSH_MESSAGE_BACK,
CmdContants.FLAGS_F2, seq);
}
/**
* 重新设置userId
*
* @return
*/
public static Object buildSetUserIdData() {
// TODO Auto-generated method stub
byte[] allData = null;
try {
MsgClient.ClientUpAppUserFlagReq.Builder reqBuilder = MsgClient.ClientUpAppUserFlagReq
.newBuilder();
reqBuilder.setChGlsxKey(ByteString.copyFrom(GLPushManager
.getInstance().getmLoginResult().getGlsxkey().getBytes()));
reqBuilder.setChAppUserFlag(ByteString.copyFrom(GLPushManager
.getInstance().getAppUserId().getBytes()));
ClientUpAppUserFlagReq req = reqBuilder.build();
allData = req.toByteArray();// 转换的数据
} catch (Exception e) {
LogUtils.i("TAG", "e = " + e);
}
LogUtils.i("ylg", "重新设置userId");
return ProtocolHandler.getProtocolHead(allData,
CmdContants.SET_USERID_SEND, CmdContants.FLAGS_F2);
}
/**
* 终端点击消息通知
*
* @return
* @author YFZX-yulg 2016-11-15
*/
public static Object buildSetMsgId(
List<GetOffLineIdItem> mListMsgId) {
byte[] allData = null;
try {
MsgClient.ClientGetMsgContextByMsgIdsReq.Builder reqBuilder = MsgClient.ClientGetMsgContextByMsgIdsReq
.newBuilder();
reqBuilder.setChGlsxKey(ByteString.copyFrom(GLPushManager
.getInstance().getmLoginResult().getGlsxkey().getBytes()));
for (int i = 0; i < mListMsgId.size(); i++) {
MsgClient.MsgId.Builder msgIdBuilder = MsgClient.MsgId
.newBuilder();
msgIdBuilder.setChMsgId(ByteString.copyFrom(mListMsgId.get(i)
.getMsgId().getBytes()));
reqBuilder.addChMsgIds(i, msgIdBuilder);// 加载消息ID集合
}
ClientGetMsgContextByMsgIdsReq req = reqBuilder.build();
allData = req.toByteArray();// 转换的数据
} catch (Exception e) {
LogUtils.i("TAG", "e = " + e);
}
LogUtils.i("ylg", "请求终端点击消息通知");
return ProtocolHandler.getProtocolHead(allData,
CmdContants.CLICK_MSG_SEND,
CmdContants.FLAGS_F2);
}
}