NIMSDK-AOS  10.8.10
QChatLoginParam.java
浏览该文件的文档.
1 package com.netease.nimlib.sdk.qchat.param;
2 
3 import android.text.TextUtils;
4 
5 import androidx.annotation.NonNull;
6 
7 import com.netease.nimlib.SDKCache;
8 import com.netease.nimlib.SDKCacheUI;
10 
11 import java.util.List;
12 
13 /**
14  * "圈组登录"接口入参
15  */
16 public class QChatLoginParam {
17 
18  /**
19  * 圈组登录独立模式回调
20  */
21  public interface QChatLoginCallback {
22 
23  /**
24  * 获取link地址列表
25  * @param account 账户名
26  * @return
27  */
28  List<String> getQChatLinkAddresses(final String account);
29  }
30 
31  /**
32  * 独立模式获取link地址列表回调
33  */
34  private final QChatLoginCallback loginCallback;
35 
36  /**
37  * 用户名
38  */
39  private final String account;
40 
41  /**
42  * 登录token
43  */
44  private final String token;
45  /**
46  * appkey 目前只支持传和IM模块相同的AppKey
47  */
48  private String appKey;
49  /**
50  * 鉴权方式,0表示最初的loginToken的校验方式,1表示基于appSecret计算的token鉴权方式,默认0
51  */
52  private final QChatAuthType _authType;
53  /**
54  * 登录自定义字段,用于提交给用户的第三方回调服务进行登录检测,不会同步给其他端
55  */
56  private String loginExt;
57  /**
58  * 自定义客户端类型
59  */
60  private Integer customClientType;
61  /**
62  * 自定义推送文案类型
63  */
64  private String customPushContentType;
65  /**
66  * 客户端自定义tag,登录时多端同步改字段
67  */
68  private String customTag;
69 
70 
71  /**
72  * 获取appKey
73  *
74  * @return
75  */
76  public String getAppKey() {
77  return appKey;
78  }
79 
80 
81  /**
82  * 获取用户账号
83  *
84  * @return 账号
85  */
86  public String getAccount() {
87  return account;
88  }
89 
90  /**
91  * 获取用户token
92  *
93  * @return 登录口令
94  */
95  public String getToken() {
96  return token;
97  }
98 
99  /**
100  * 获取鉴权方式
101  * @return
102  */
103  @NonNull
105  return _authType;
106  }
107 
108  /**
109  * 获取登录自定义字段
110  * @return
111  */
112  public String getLoginExt() {
113  return loginExt;
114  }
115 
116  /**
117  * 设置登录自定义字段
118  * @param loginExt
119  */
120  public void setLoginExt(String loginExt) {
121  this.loginExt = loginExt;
122  }
123 
124  /**
125  * 获取自定义客户端类型
126  * @return
127  */
128  public Integer getCustomClientType() {
129  return customClientType;
130  }
131 
132  /**
133  * 设置自定义客户端类型
134  * @param customClientType
135  */
136  public void setCustomClientType(int customClientType) {
137  this.customClientType = customClientType;
138  }
139 
140  /**
141  * 获取自定义Tag
142  * @return
143  */
144  public String getCustomTag() {
145  return customTag;
146  }
147 
148  /**
149  * 设置自定义Tag
150  * @param customTag
151  */
152  public void setCustomTag(String customTag) {
153  this.customTag = customTag;
154  }
155 
156  /**
157  * 获取自定义推送文案类型
158  * @return
159  */
160  public String getCustomPushContentType() {
161  return customPushContentType;
162  }
163 
164  /**
165  * 设置自定义推送文案类型,离线推送不显示详情时,要显示的文案对应的类型名称
166  * @param customPushContentType
167  */
168  public void setCustomPushContentType(String customPushContentType) {
169  this.customPushContentType = customPushContentType;
170  }
171 
172  /**
173  * 获取圈组登录独立模式回调
174  * @return
175  */
177  return loginCallback;
178  }
179 
180  /**
181  * 非独立模式下,圈组登录参数的构造函数,
182  * 不需要传入account、token、appKey、authType、loginCallback
183  * account、token、appKey、authType从IM模块获取,loginCallback设置为空
184  * 其他参数通过setter方法设置
185  */
186  public QChatLoginParam() {
187  this.account = SDKCacheUI.getAuthInfo() == null ? "" : SDKCacheUI.getAuthInfo().getAccount();
188  this.token = SDKCacheUI.getAuthInfo() == null ? "" : SDKCacheUI.getAuthInfo().getToken();
189  this.appKey = SDKCache.getAppKey();
190 
191  int authType = SDKCacheUI.getAuthInfo() == null ? QChatAuthType.DEFAULT.getValue() : SDKCacheUI.getAuthInfo().getAuthType();
192  if (authType > QChatAuthType.DYNAMIC.getValue()) {
193  this._authType = QChatAuthType.DEFAULT;
194  } else {
195  this._authType = QChatAuthType.typeOfValue(authType);
196  }
197 
198  this.loginCallback = null;
199  }
200 
201  /**
202  * 独立模式下,圈组登录参数的构造函数,
203  * 需要传入account、token、appKey、authType、loginCallback
204  *
205  * @param account 账户名
206  * @param token 登录token,@NonNull,authType为DYNAMIC时传入空字符串""
207  * @param appKey appKey
208  * @param authType 鉴权模式
209  * @param callback 独立模式使用,外部设置link地址
210  */
211  private QChatLoginParam(@NonNull String account, @NonNull String token, @NonNull String appKey, QChatAuthType authType, QChatLoginCallback callback) {
212  this.loginCallback = callback;
213  this.account = account;
214  this.token = token;
215  this.appKey = appKey;
216  this._authType = authType;
217  }
218 
219  /**
220  * 数据是否有效,有效时才会进行登录操作,否则返回RES_EPARAM
221  * @return
222  */
223  public boolean isValid() {
224  if (_authType == QChatAuthType.DEFAULT) {
225  return !TextUtils.isEmpty(account) && !TextUtils.isEmpty(token) && !TextUtils.isEmpty(appKey);
226  }
227 
228  if (_authType == QChatAuthType.DYNAMIC) {
229  return !TextUtils.isEmpty(account) && !TextUtils.isEmpty(appKey);
230  }
231 
232  return false;
233  }
234 }
Integer getCustomClientType()
获取自定义客户端类型
String getCustomPushContentType()
获取自定义推送文案类型
void setCustomTag(String customTag)
设置自定义Tag
void setCustomPushContentType(String customPushContentType)
设置自定义推送文案类型,离线推送不显示详情时,要显示的文案对应的类型名称
List< String > getQChatLinkAddresses(final String account)
获取link地址列表
QChatLoginCallback getLoginCallback()
获取圈组登录独立模式回调
void setCustomClientType(int customClientType)
设置自定义客户端类型
QChatAuthType getAuthType()
获取鉴权方式
String getLoginExt()
获取登录自定义字段
static QChatAuthType typeOfValue(int value)
void setLoginExt(String loginExt)
设置登录自定义字段
QChatLoginParam()
非独立模式下,圈组登录参数的构造函数, 不需要传入account、token、appKey、authType、loginCallback acco...
boolean isValid()
数据是否有效,有效时才会进行登录操作,否则返回RES_EPARAM