Skip to content

Commit 7b8f071

Browse files
authored
Merge pull request #51 from xuchengpu/verify_code
Add the verification code Alibaba Cloud slider verification function
2 parents caa79d5 + 294b04d commit 7b8f071

File tree

7 files changed

+349
-144
lines changed

7 files changed

+349
-144
lines changed

app/build.gradle.kts

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -47,6 +47,9 @@ android {
4747
// Set appkey from local.properties
4848
buildConfigField("String", "APPKEY", "\"${properties.getProperty("APPKEY")}\"")
4949

50+
//请求验证码秘钥,这里是环信公司的,开发者应该用自己的
51+
buildConfigField("String", "SECRET_KEY", "\"${properties.getProperty("SECRET_KEY")}\"")
52+
5053
// Set push info from local.properties
5154
buildConfigField("String", "MEIZU_PUSH_APPKEY", "\"${properties.getProperty("MEIZU_PUSH_APPKEY")}\"")
5255
buildConfigField("String", "MEIZU_PUSH_APPID", "\"${properties.getProperty("MEIZU_PUSH_APPID")}\"")
@@ -155,8 +158,8 @@ dependencies {
155158
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
156159
implementation("androidx.core:core-ktx:1.10.1")
157160
implementation("androidx.appcompat:appcompat:1.7.0")
158-
implementation("com.google.android.material:material:1.9.0")
159-
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
161+
implementation("com.google.android.material:material:1.12.0")
162+
implementation("androidx.constraintlayout:constraintlayout:2.2.1")
160163
testImplementation("junit:junit:4.13.2")
161164
androidTestImplementation("androidx.test.ext:junit:1.1.5")
162165
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")

app/src/main/AndroidManifest.xml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -95,6 +95,8 @@
9595
<!-- 悬浮窗权限 -->
9696
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />
9797

98+
<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>
99+
98100
<application
99101
android:usesCleartextTraffic="true"
100102
android:allowBackup="true"

app/src/main/kotlin/com/hyphenate/chatdemo/repository/EMClientRepository.kt

Lines changed: 0 additions & 61 deletions
Original file line numberDiff line numberDiff line change
@@ -244,67 +244,6 @@ class EMClientRepository: BaseRepository() {
244244
}
245245
}
246246

247-
/**
248-
* Get verification code from server.
249-
*/
250-
suspend fun getVerificationCode(phoneNumber: String?): Int =
251-
withContext(Dispatchers.IO) {
252-
suspendCoroutine { continuation ->
253-
getVerificationCodeFromServer(
254-
phoneNumber,
255-
onSuccess = {
256-
continuation.resume(ChatError.EM_NO_ERROR)
257-
},
258-
onError = { code, error ->
259-
continuation.resumeWithException(ChatException(code, error))
260-
}
261-
)
262-
}
263-
}
264-
265-
private fun getVerificationCodeFromServer(phoneNumber: String?, onSuccess: OnSuccess, onError: OnError) {
266-
if (phoneNumber.isNullOrEmpty()) {
267-
onError(ChatError.INVALID_PARAM, getContext().getString(R.string.em_login_phone_empty))
268-
return
269-
}
270-
try {
271-
val headers: MutableMap<String, String> = java.util.HashMap()
272-
headers["Content-Type"] = "application/json"
273-
val url = "$SEND_SMS_URL/$phoneNumber/"
274-
EMLog.d("getVerificationCodeFromServe url : ", url)
275-
val response =
276-
HttpClientManager.httpExecute(url, headers, null, HttpClientManager.Method_POST)
277-
val code = response.code
278-
val responseInfo = response.content
279-
if (code == 200) {
280-
onSuccess()
281-
} else {
282-
if (responseInfo != null && responseInfo.isNotEmpty()) {
283-
var errorInfo: String? = null
284-
try {
285-
val responseObject = JSONObject(responseInfo)
286-
errorInfo = responseObject.getString("errorInfo")
287-
if (errorInfo.contains("wait a moment while trying to send")) {
288-
errorInfo =
289-
getContext().getString(R.string.em_login_error_send_code_later)
290-
} else if (errorInfo.contains("exceed the limit of")) {
291-
errorInfo =
292-
getContext().getString(R.string.em_login_error_send_code_limit)
293-
}
294-
} catch (e: JSONException) {
295-
e.printStackTrace()
296-
errorInfo = responseInfo
297-
}
298-
onError(code, errorInfo)
299-
} else {
300-
onError(code, responseInfo)
301-
}
302-
}
303-
} catch (e: java.lang.Exception) {
304-
onError(ChatError.NETWORK_ERROR, e.message)
305-
}
306-
}
307-
308247
/**
309248
* 注销账户
310249
* @return

0 commit comments

Comments
 (0)