Commit 7e2d34cac10150f64ce912deeedda229568c8e8a
1 parent
918131e1
添加获取token与鉴权接口
Showing
13 changed files
with
75 additions
and
53 deletions
.idea/misc.xml
| @@ -37,7 +37,7 @@ | @@ -37,7 +37,7 @@ | ||
| 37 | <ConfirmationsSetting value="0" id="Add" /> | 37 | <ConfirmationsSetting value="0" id="Add" /> |
| 38 | <ConfirmationsSetting value="0" id="Remove" /> | 38 | <ConfirmationsSetting value="0" id="Remove" /> |
| 39 | </component> | 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 | <output url="file://$PROJECT_DIR$/build/classes" /> | 41 | <output url="file://$PROJECT_DIR$/build/classes" /> |
| 42 | </component> | 42 | </component> |
| 43 | <component name="ProjectType"> | 43 | <component name="ProjectType"> |
IMLib/build/intermediates/incremental/mergeDebugAndroidTestResources/compile-file-map.properties
IMLib/build/intermediates/incremental/mergeDebugResources/compile-file-map.properties
IMLib/build/intermediates/incremental/packageDebugResources/compile-file-map.properties
IMLib/build/intermediates/incremental/packageReleaseResources/compile-file-map.properties
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,13 +63,12 @@ public class Chat implements IChat { | ||
| 63 | private OnResultListener mOnResultListener; | 63 | private OnResultListener mOnResultListener; |
| 64 | private OnLatestMessageListener mOnLatestMessageListener; | 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 | private String sid; | 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 | private static Chat chat; | 74 | private static Chat chat; |
| @@ -131,9 +130,11 @@ public class Chat implements IChat { | @@ -131,9 +130,11 @@ public class Chat implements IChat { | ||
| 131 | @Override | 130 | @Override |
| 132 | public void onError(Call call, Exception e) { | 131 | public void onError(Call call, Exception e) { |
| 133 | if (!NetUtil.checkNetwork(Config.getContext())) { | 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 | } else { | 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 | if (e != null) Log.e("Chat", "error ", e); | 139 | if (e != null) Log.e("Chat", "error ", e); |
| 139 | 140 | ||
| @@ -142,13 +143,13 @@ public class Chat implements IChat { | @@ -142,13 +143,13 @@ public class Chat implements IChat { | ||
| 142 | @Override | 143 | @Override |
| 143 | public void onResponse(DataEntity dataEntity, Exception e) { | 144 | public void onResponse(DataEntity dataEntity, Exception e) { |
| 144 | if (dataEntity != null && "0".equals(dataEntity.getErrorCode())) { | 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 | token = dataEntity.getData().getToken(); | 148 | token = dataEntity.getData().getToken(); |
| 147 | - Log.e("DemoView", token); | ||
| 148 | connect(token); | 149 | connect(token); |
| 149 | } else if (dataEntity != null && !TextUtils.isEmpty(dataEntity.getErrorCode())) { | 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 | } else { | 153 | } else { |
| 153 | onError(null, e); | 154 | onError(null, e); |
| 154 | } | 155 | } |
| @@ -158,6 +159,7 @@ public class Chat implements IChat { | @@ -158,6 +159,7 @@ public class Chat implements IChat { | ||
| 158 | 159 | ||
| 159 | //连接融云服务器 | 160 | //连接融云服务器 |
| 160 | private void connect(String token) { | 161 | private void connect(String token) { |
| 162 | + Log.e("DemoView", token); | ||
| 161 | RongIMClient.connect(token, new RongIMClient.ConnectCallback() { | 163 | RongIMClient.connect(token, new RongIMClient.ConnectCallback() { |
| 162 | @Override | 164 | @Override |
| 163 | public void onTokenIncorrect() { | 165 | public void onTokenIncorrect() { |
| @@ -192,9 +194,11 @@ public class Chat implements IChat { | @@ -192,9 +194,11 @@ public class Chat implements IChat { | ||
| 192 | @Override | 194 | @Override |
| 193 | public void onError(Call call, Exception e) { | 195 | public void onError(Call call, Exception e) { |
| 194 | if (!NetUtil.checkNetwork(Config.getContext())) { | 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 | } else { | 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 | if (e != null) Log.e("Chat", "error ", e); | 203 | if (e != null) Log.e("Chat", "error ", e); |
| 200 | } | 204 | } |
| @@ -202,12 +206,13 @@ public class Chat implements IChat { | @@ -202,12 +206,13 @@ public class Chat implements IChat { | ||
| 202 | @Override | 206 | @Override |
| 203 | public void onResponse(DataEntity dataEntity, Exception e) { | 207 | public void onResponse(DataEntity dataEntity, Exception e) { |
| 204 | if (dataEntity != null && "0".equals(dataEntity.getErrorCode())) { | 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 | joinExistChatroom(roomId, defMessageCount); | 211 | joinExistChatroom(roomId, defMessageCount); |
| 208 | } else if (dataEntity != null && !TextUtils.isEmpty(dataEntity.getErrorCode())) { | 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 | } else { | 216 | } else { |
| 212 | onError(null, e); | 217 | onError(null, e); |
| 213 | } | 218 | } |
| @@ -221,9 +226,11 @@ public class Chat implements IChat { | @@ -221,9 +226,11 @@ public class Chat implements IChat { | ||
| 221 | @Override | 226 | @Override |
| 222 | public void onError(Call call, Exception e) { | 227 | public void onError(Call call, Exception e) { |
| 223 | if (!NetUtil.checkNetwork(Config.getContext())) { | 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 | } else { | 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 | if (e != null) Log.e("Chat", "error ", e); | 235 | if (e != null) Log.e("Chat", "error ", e); |
| 229 | } | 236 | } |
| @@ -231,12 +238,12 @@ public class Chat implements IChat { | @@ -231,12 +238,12 @@ public class Chat implements IChat { | ||
| 231 | @Override | 238 | @Override |
| 232 | public void onResponse(DataEntity dataEntity, Exception e) { | 239 | public void onResponse(DataEntity dataEntity, Exception e) { |
| 233 | if (dataEntity != null && "0".equals(dataEntity.getErrorCode())) { | 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 | joinChatroom(roomId, defMessageCount); | 243 | joinChatroom(roomId, defMessageCount); |
| 237 | } else if (dataEntity != null && !TextUtils.isEmpty(dataEntity.getErrorCode())) { | 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 | } else { | 247 | } else { |
| 241 | onError(null, e); | 248 | onError(null, e); |
| 242 | } | 249 | } |
| @@ -543,13 +550,13 @@ public class Chat implements IChat { | @@ -543,13 +550,13 @@ public class Chat implements IChat { | ||
| 543 | this.mOnLatestMessageListener = listener; | 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 | private UserInfo getCurrentUser() { | 561 | private UserInfo getCurrentUser() { |
| 555 | return currentUser; | 562 | return currentUser; |
IMLib/src/main/java/io.rong.imlib/ChatUtil.java
| @@ -80,12 +80,8 @@ public class ChatUtil { | @@ -80,12 +80,8 @@ public class ChatUtil { | ||
| 80 | Chat.getInstance().setOnLatestMessageListener(listener); | 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 | public static void modifyUser(String userName, String headUrl) { | 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,24 +22,30 @@ public interface IChat { | ||
| 22 | int TOKEN_INCORRECT = 4; | 22 | int TOKEN_INCORRECT = 4; |
| 23 | int SERVER_INVALID = 5; | 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 | int SUCCESS_JOIN_CHATROOM = 100002; | 29 | int SUCCESS_JOIN_CHATROOM = 100002; |
| 28 | int SUCCESS_JOIN_EXIST_CHATROOM = 100003; | 30 | int SUCCESS_JOIN_EXIST_CHATROOM = 100003; |
| 29 | int SUCCESS_QUIT_CHATROOM = 100004; | 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 | String PRIVATE = "private"; | 37 | String PRIVATE = "private"; |
| 34 | String CHATROOM = "chatRoom"; | 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 | String MSG_SUCCESS_JOIN_CHATROOM = "加入聊天室成功"; | 46 | String MSG_SUCCESS_JOIN_CHATROOM = "加入聊天室成功"; |
| 39 | String MSG_SUCCESS_JOIN_EXIST_CHATROOM = "加入已存在聊天室成功"; | 47 | String MSG_SUCCESS_JOIN_EXIST_CHATROOM = "加入已存在聊天室成功"; |
| 40 | String MSG_SUCCESS_QUIT_CHATROOM = "退出聊天室成功"; | 48 | String MSG_SUCCESS_QUIT_CHATROOM = "退出聊天室成功"; |
| 41 | - String MSG_SUCCESS_SEND_MESSAGE = "发送消息成功"; | ||
| 42 | - String MSG_RECEIVE = "接收消息"; | ||
| 43 | 49 | ||
| 44 | String STATUS_NETWORK_UNAVAILABLE = "Network is unavailable."; | 50 | String STATUS_NETWORK_UNAVAILABLE = "Network is unavailable."; |
| 45 | String STATUS_CONNECTED = "Connect Success."; | 51 | String STATUS_CONNECTED = "Connect Success."; |
| @@ -99,9 +105,9 @@ public interface IChat { | @@ -99,9 +105,9 @@ public interface IChat { | ||
| 99 | //从本地获取私聊历史消息 | 105 | //从本地获取私聊历史消息 |
| 100 | void getLatestMessages(String targetId, int count); | 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 | void setOnLatestMessageListener(OnLatestMessageListener listener); | 113 | void setOnLatestMessageListener(OnLatestMessageListener listener); |
| @@ -156,12 +162,14 @@ public interface IChat { | @@ -156,12 +162,14 @@ public interface IChat { | ||
| 156 | void onError(int what, String extra); | 162 | void onError(int what, String extra); |
| 157 | } | 163 | } |
| 158 | 164 | ||
| 159 | - interface OnErrorListener { | 165 | + interface OnCNChatListener { |
| 160 | void onError(int what, String extra); | 166 | void onError(int what, String extra); |
| 161 | - } | ||
| 162 | 167 | ||
| 163 | - interface OnInfoListener { | ||
| 164 | void onInfo(int what, String extra); | 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 | package io.rong.imlib.model; | 1 | package io.rong.imlib.model; |
| 2 | 2 | ||
| 3 | +import com.cnlive.libs.util.model.BaseData; | ||
| 4 | + | ||
| 3 | /** | 5 | /** |
| 4 | * Created by Lynn on 3/2/2017. | 6 | * Created by Lynn on 3/2/2017. |
| 5 | */ | 7 | */ |
| @@ -16,7 +18,7 @@ public class DataEntity extends ErrorMessage { | @@ -16,7 +18,7 @@ public class DataEntity extends ErrorMessage { | ||
| 16 | this.data = data; | 18 | this.data = data; |
| 17 | } | 19 | } |
| 18 | 20 | ||
| 19 | - public class TokenData { | 21 | + public static class TokenData extends BaseData { |
| 20 | private String sid; | 22 | private String sid; |
| 21 | private String token; | 23 | private String token; |
| 22 | 24 | ||
| @@ -35,5 +37,14 @@ public class DataEntity extends ErrorMessage { | @@ -35,5 +37,14 @@ public class DataEntity extends ErrorMessage { | ||
| 35 | public void setToken(String token) { | 37 | public void setToken(String token) { |
| 36 | this.token = token; | 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,7 +19,7 @@ import io.rong.imlib.model.DataEntity; | ||
| 19 | public class HttpRequest { | 19 | public class HttpRequest { |
| 20 | private static final String BASE_URL = "https://api.cnlive.com/open/api2"; | 20 | private static final String BASE_URL = "https://api.cnlive.com/open/api2"; |
| 21 | private static final String URL_GET_TOKEN = BASE_URL + "/im_chat/getToken"; | 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 | public static void getToken(CNUserInfo userInfo, GenericsCallback<DataEntity> callback) { | 24 | public static void getToken(CNUserInfo userInfo, GenericsCallback<DataEntity> callback) { |
| 25 | Map<String, String> params = new HashMap<>(); | 25 | Map<String, String> params = new HashMap<>(); |