Commit 7e2d34cac10150f64ce912deeedda229568c8e8a

Authored by 王琳
1 parent 918131e1

添加获取token与鉴权接口

.idea/misc.xml
... ... @@ -37,7 +37,7 @@
37 37 <ConfirmationsSetting value="0" id="Add" />
38 38 <ConfirmationsSetting value="0" id="Remove" />
39 39 </component>
40   - <component name="ProjectRootManager" version="2" languageLevel="JDK_1_7" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
  40 + <component name="ProjectRootManager" version="2" languageLevel="JDK_1_8" default="true" assert-keyword="true" jdk-15="true" project-jdk-name="1.8" project-jdk-type="JavaSDK">
41 41 <output url="file://$PROJECT_DIR$/build/classes" />
42 42 </component>
43 43 <component name="ProjectType">
... ...
IMLib/build/intermediates/incremental/mergeDebugAndroidTestResources/compile-file-map.properties
1   -#Thu Mar 02 15:05:54 CST 2017
  1 +#Thu Mar 02 16:41:59 CST 2017
... ...
IMLib/build/intermediates/incremental/mergeDebugResources/compile-file-map.properties
1   -#Thu Mar 02 15:05:52 CST 2017
  1 +#Thu Mar 02 16:41:58 CST 2017
... ...
IMLib/build/intermediates/incremental/packageDebugResources/compile-file-map.properties
1   -#Thu Mar 02 15:05:54 CST 2017
  1 +#Thu Mar 02 16:41:59 CST 2017
... ...
IMLib/build/intermediates/incremental/packageReleaseResources/compile-file-map.properties
1   -#Thu Mar 02 15:05:54 CST 2017
  1 +#Thu Mar 02 16:42:00 CST 2017
... ...
IMLib/build/intermediates/res/resources-debug-androidTest.ap_
No preview for this file type
IMLib/build/outputs/aar/IMLib-debug.aar
No preview for this file type
IMLib/build/outputs/aar/IMLib-release.aar
No preview for this file type
IMLib/src/main/java/io.rong.imlib/Chat.java
... ... @@ -63,13 +63,12 @@ public class Chat implements IChat {
63 63 private OnResultListener mOnResultListener;
64 64 private OnLatestMessageListener mOnLatestMessageListener;
65 65  
66   - private OnErrorListener mOnErrorListener;
67   - private OnInfoListener mOnInfoListener;
  66 + private OnCNChatListener mOnCNListener;
  67 +// private OnInfoListener mOnInfoListener;
68 68  
69 69 private String sid;
70 70  
71   - private static String APP_KEY = "e5t4ouvpe5qea";
72   - private static String APP_SECRET = "N16VJFIPE22p";
  71 + private static String APP_KEY = "8brlm7uf8bqz3";
73 72  
74 73  
75 74 private static Chat chat;
... ... @@ -131,9 +130,11 @@ public class Chat implements IChat {
131 130 @Override
132 131 public void onError(Call call, Exception e) {
133 132 if (!NetUtil.checkNetwork(Config.getContext())) {
134   - if (mOnErrorListener != null) mOnErrorListener.onError(-0x1009, "网络连接失败");
  133 + if (mOnCNListener != null)
  134 + mOnCNListener.onError(IChat.ERROR_GET_TOKEN_NETWORK, IChat.MSG_GET_TOKEN_NETWORK);
135 135 } else {
136   - if (mOnErrorListener != null) mOnErrorListener.onError(-0x1010, "内部错误");
  136 + if (mOnCNListener != null)
  137 + mOnCNListener.onError(IChat.ERROR_GET_TOKEN_OTHER, IChat.MSG_GET_TOKEN_OTHER);
137 138 }
138 139 if (e != null) Log.e("Chat", "error ", e);
139 140  
... ... @@ -142,13 +143,13 @@ public class Chat implements IChat {
142 143 @Override
143 144 public void onResponse(DataEntity dataEntity, Exception e) {
144 145 if (dataEntity != null && "0".equals(dataEntity.getErrorCode())) {
145   - if (mOnInfoListener != null) mOnInfoListener.onInfo(0x2001, "获取token成功");
  146 + if (mOnCNListener != null)
  147 + mOnCNListener.onInfo(SUCCESS_GET_TOKEN, dataEntity.getErrorMessage());
146 148 token = dataEntity.getData().getToken();
147   - Log.e("DemoView", token);
148 149 connect(token);
149 150 } else if (dataEntity != null && !TextUtils.isEmpty(dataEntity.getErrorCode())) {
150   - if (mOnErrorListener != null)
151   - mOnErrorListener.onError(-0x1008, dataEntity.getErrorMessage());
  151 + if (mOnCNListener != null)
  152 + mOnCNListener.onError(IChat.ERROR_GET_TOKEN, IChat.MSG_GET_TOKEN + dataEntity.getErrorMessage());
152 153 } else {
153 154 onError(null, e);
154 155 }
... ... @@ -158,6 +159,7 @@ public class Chat implements IChat {
158 159  
159 160 //连接融云服务器
160 161 private void connect(String token) {
  162 + Log.e("DemoView", token);
161 163 RongIMClient.connect(token, new RongIMClient.ConnectCallback() {
162 164 @Override
163 165 public void onTokenIncorrect() {
... ... @@ -192,9 +194,11 @@ public class Chat implements IChat {
192 194 @Override
193 195 public void onError(Call call, Exception e) {
194 196 if (!NetUtil.checkNetwork(Config.getContext())) {
195   - if (mOnErrorListener != null) mOnErrorListener.onError(-0x1009, "网络连接失败");
  197 + if (mOnCNListener != null)
  198 + mOnCNListener.onError(ERROR_CHECK_AUTH_NETWORK, MSG_CHECK_AUTH_NETWORK);
196 199 } else {
197   - if (mOnErrorListener != null) mOnErrorListener.onError(-0x1010, "内部错误");
  200 + if (mOnCNListener != null)
  201 + mOnCNListener.onError(ERROR_CHECK_AUTH_OTHER, MSG_CHECK_AUTH_OTHER);
198 202 }
199 203 if (e != null) Log.e("Chat", "error ", e);
200 204 }
... ... @@ -202,12 +206,13 @@ public class Chat implements IChat {
202 206 @Override
203 207 public void onResponse(DataEntity dataEntity, Exception e) {
204 208 if (dataEntity != null && "0".equals(dataEntity.getErrorCode())) {
205   - if (mOnInfoListener != null)
206   - mOnInfoListener.onInfo(0x2001, dataEntity.getErrorMessage());
  209 + if (mOnCNListener != null)
  210 + mOnCNListener.onInfo(SUCCESS_CHECK_AUTH, dataEntity.getErrorMessage());
207 211 joinExistChatroom(roomId, defMessageCount);
208 212 } else if (dataEntity != null && !TextUtils.isEmpty(dataEntity.getErrorCode())) {
209   - if (mOnErrorListener != null)
210   - mOnErrorListener.onError(-0x1008, dataEntity.getErrorMessage());
  213 + if (mOnCNListener != null)
  214 + mOnCNListener.onError(ERROR_CHECK_AUTH, MSG_CHECK_AUTH + dataEntity.getErrorMessage());
  215 +
211 216 } else {
212 217 onError(null, e);
213 218 }
... ... @@ -221,9 +226,11 @@ public class Chat implements IChat {
221 226 @Override
222 227 public void onError(Call call, Exception e) {
223 228 if (!NetUtil.checkNetwork(Config.getContext())) {
224   - if (mOnErrorListener != null) mOnErrorListener.onError(-0x1009, "网络连接失败");
  229 + if (mOnCNListener != null)
  230 + mOnCNListener.onError(ERROR_CHECK_AUTH_NETWORK, MSG_CHECK_AUTH_NETWORK);
225 231 } else {
226   - if (mOnErrorListener != null) mOnErrorListener.onError(-0x1010, "内部错误");
  232 + if (mOnCNListener != null)
  233 + mOnCNListener.onError(ERROR_CHECK_AUTH_OTHER, MSG_CHECK_AUTH_OTHER);
227 234 }
228 235 if (e != null) Log.e("Chat", "error ", e);
229 236 }
... ... @@ -231,12 +238,12 @@ public class Chat implements IChat {
231 238 @Override
232 239 public void onResponse(DataEntity dataEntity, Exception e) {
233 240 if (dataEntity != null && "0".equals(dataEntity.getErrorCode())) {
234   - if (mOnInfoListener != null)
235   - mOnInfoListener.onInfo(0x2001, dataEntity.getErrorMessage());
  241 + if (mOnCNListener != null)
  242 + mOnCNListener.onInfo(SUCCESS_CHECK_AUTH, dataEntity.getErrorMessage());
236 243 joinChatroom(roomId, defMessageCount);
237 244 } else if (dataEntity != null && !TextUtils.isEmpty(dataEntity.getErrorCode())) {
238   - if (mOnErrorListener != null)
239   - mOnErrorListener.onError(-0x1008, dataEntity.getErrorMessage());
  245 + if (mOnCNListener != null)
  246 + mOnCNListener.onError(ERROR_CHECK_AUTH, MSG_CHECK_AUTH + dataEntity.getErrorMessage());
240 247 } else {
241 248 onError(null, e);
242 249 }
... ... @@ -543,13 +550,13 @@ public class Chat implements IChat {
543 550 this.mOnLatestMessageListener = listener;
544 551 }
545 552  
546   - public void setOnErrorListener(OnErrorListener listener) {
547   - this.mOnErrorListener = listener;
  553 + public void setOnCNChatListener(OnCNChatListener listener) {
  554 + this.mOnCNListener = listener;
548 555 }
549 556  
550   - public void setOnInfoListener(OnInfoListener listener) {
551   - this.mOnInfoListener = listener;
552   - }
  557 +// public void setOnInfoListener(OnInfoListener listener) {
  558 +// this.mOnInfoListener = listener;
  559 +// }
553 560  
554 561 private UserInfo getCurrentUser() {
555 562 return currentUser;
... ...
IMLib/src/main/java/io.rong.imlib/ChatUtil.java
... ... @@ -80,12 +80,8 @@ public class ChatUtil {
80 80 Chat.getInstance().setOnLatestMessageListener(listener);
81 81 }
82 82  
83   - public static void setOnErrorListener(IChat.OnErrorListener listener) {
84   - Chat.getInstance().setOnErrorListener(listener);
85   - }
86   -
87   - public static void setOnInfoListener(IChat.OnInfoListener listener) {
88   - Chat.getInstance().setOnInfoListener(listener);
  83 + public static void setOnCNChatListener(IChat.OnCNChatListener listener) {
  84 + Chat.getInstance().setOnCNChatListener(listener);
89 85 }
90 86  
91 87 public static void modifyUser(String userName, String headUrl) {
... ...
IMLib/src/main/java/io.rong.imlib/base/IChat.java
... ... @@ -22,24 +22,30 @@ public interface IChat {
22 22 int TOKEN_INCORRECT = 4;
23 23 int SERVER_INVALID = 5;
24 24  
25   - int ERROR_TOKEN_INCORRECT = -100000;
26   - int SUCCESS_CONNECT = 100001;
  25 + int SUCCESS_GET_TOKEN = 10000;
  26 + int ERROR_GET_TOKEN = -100000;
  27 + int ERROR_GET_TOKEN_NETWORK = -10001;
  28 + int ERROR_GET_TOKEN_OTHER = -10002;
27 29 int SUCCESS_JOIN_CHATROOM = 100002;
28 30 int SUCCESS_JOIN_EXIST_CHATROOM = 100003;
29 31 int SUCCESS_QUIT_CHATROOM = 100004;
30   - int SUCCESS_SEND_MESSAGE = 100005;
31   - int RECEIVE = 100006;
  32 + int SUCCESS_CHECK_AUTH = 100005;
  33 + int ERROR_CHECK_AUTH_NETWORK = -10005;
  34 + int ERROR_CHECK_AUTH_OTHER = -10006;
  35 + int ERROR_CHECK_AUTH = -10007;
32 36  
33 37 String PRIVATE = "private";
34 38 String CHATROOM = "chatRoom";
35 39  
36   - String MSG_TOKEN_INCORRECT = "Token错误";
37   - String MSG_SUCCESS_CONNECT = "连接成功";
  40 + String MSG_GET_TOKEN_NETWORK = "获取token时网络连接错误";
  41 + String MSG_GET_TOKEN_OTHER = "获取token时内部错误";
  42 + String MSG_GET_TOKEN = "获取Token失败";
  43 + String MSG_CHECK_AUTH_NETWORK = "鉴权时网络连接错误";
  44 + String MSG_CHECK_AUTH_OTHER = "鉴权时内部错误";
  45 + String MSG_CHECK_AUTH = "鉴权失败";
38 46 String MSG_SUCCESS_JOIN_CHATROOM = "加入聊天室成功";
39 47 String MSG_SUCCESS_JOIN_EXIST_CHATROOM = "加入已存在聊天室成功";
40 48 String MSG_SUCCESS_QUIT_CHATROOM = "退出聊天室成功";
41   - String MSG_SUCCESS_SEND_MESSAGE = "发送消息成功";
42   - String MSG_RECEIVE = "接收消息";
43 49  
44 50 String STATUS_NETWORK_UNAVAILABLE = "Network is unavailable.";
45 51 String STATUS_CONNECTED = "Connect Success.";
... ... @@ -99,9 +105,9 @@ public interface IChat {
99 105 //从本地获取私聊历史消息
100 106 void getLatestMessages(String targetId, int count);
101 107  
102   - void setOnErrorListener(OnErrorListener listener);
  108 + void setOnCNChatListener(OnCNChatListener listener);
103 109  
104   - void setOnInfoListener(OnInfoListener listener);
  110 +// void setOnInfoListener(OnInfoListener listener);
105 111  
106 112 //获取历史消息监听
107 113 void setOnLatestMessageListener(OnLatestMessageListener listener);
... ... @@ -156,12 +162,14 @@ public interface IChat {
156 162 void onError(int what, String extra);
157 163 }
158 164  
159   - interface OnErrorListener {
  165 + interface OnCNChatListener {
160 166 void onError(int what, String extra);
161   - }
162 167  
163   - interface OnInfoListener {
164 168 void onInfo(int what, String extra);
165 169 }
166 170  
  171 +// interface OnInfoListener {
  172 +// void onInfo(int what, String extra);
  173 +// }
  174 +
167 175 }
... ...
IMLib/src/main/java/io.rong.imlib/model/DataEntity.java
1 1 package io.rong.imlib.model;
2 2  
  3 +import com.cnlive.libs.util.model.BaseData;
  4 +
3 5 /**
4 6 * Created by Lynn on 3/2/2017.
5 7 */
... ... @@ -16,7 +18,7 @@ public class DataEntity extends ErrorMessage {
16 18 this.data = data;
17 19 }
18 20  
19   - public class TokenData {
  21 + public static class TokenData extends BaseData {
20 22 private String sid;
21 23 private String token;
22 24  
... ... @@ -35,5 +37,14 @@ public class DataEntity extends ErrorMessage {
35 37 public void setToken(String token) {
36 38 this.token = token;
37 39 }
  40 +
  41 +
  42 + }
  43 +
  44 + @Override
  45 + public String toString() {
  46 + return "DataEntity{" +
  47 + "data=" + data +
  48 + '}';
38 49 }
39 50 }
... ...
IMLib/src/main/java/io.rong.imlib/network/HttpRequest.java
... ... @@ -19,7 +19,7 @@ import io.rong.imlib.model.DataEntity;
19 19 public class HttpRequest {
20 20 private static final String BASE_URL = "https://api.cnlive.com/open/api2";
21 21 private static final String URL_GET_TOKEN = BASE_URL + "/im_chat/getToken";
22   - private static final String URL_ROOM_AUTH_CHECK = "/im_chat/user/checkOnline";
  22 + private static final String URL_ROOM_AUTH_CHECK = BASE_URL + "/im_chat/user/checkOnline";
23 23  
24 24 public static void getToken(CNUserInfo userInfo, GenericsCallback<DataEntity> callback) {
25 25 Map<String, String> params = new HashMap<>();
... ...