Skip to content

Add the verification code Alibaba Cloud slider verification function #51

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 2 commits into from
Jun 5, 2025
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 5 additions & 2 deletions app/build.gradle.kts
Original file line number Diff line number Diff line change
Expand Up @@ -47,6 +47,9 @@ android {
// Set appkey from local.properties
buildConfigField("String", "APPKEY", "\"${properties.getProperty("APPKEY")}\"")

//请求验证码秘钥,这里是环信公司的,开发者应该用自己的
buildConfigField("String", "SECRET_KEY", "\"${properties.getProperty("SECRET_KEY")}\"")

// Set push info from local.properties
buildConfigField("String", "MEIZU_PUSH_APPKEY", "\"${properties.getProperty("MEIZU_PUSH_APPKEY")}\"")
buildConfigField("String", "MEIZU_PUSH_APPID", "\"${properties.getProperty("MEIZU_PUSH_APPID")}\"")
Expand Down Expand Up @@ -155,8 +158,8 @@ dependencies {
implementation(fileTree(mapOf("dir" to "libs", "include" to listOf("*.jar", "*.aar"))))
implementation("androidx.core:core-ktx:1.10.1")
implementation("androidx.appcompat:appcompat:1.7.0")
implementation("com.google.android.material:material:1.9.0")
implementation("androidx.constraintlayout:constraintlayout:2.1.4")
implementation("com.google.android.material:material:1.12.0")
implementation("androidx.constraintlayout:constraintlayout:2.2.1")
testImplementation("junit:junit:4.13.2")
androidTestImplementation("androidx.test.ext:junit:1.1.5")
androidTestImplementation("androidx.test.espresso:espresso-core:3.5.1")
Expand Down
2 changes: 2 additions & 0 deletions app/src/main/AndroidManifest.xml
Original file line number Diff line number Diff line change
Expand Up @@ -95,6 +95,8 @@
<!-- 悬浮窗权限 -->
<uses-permission android:name="android.permission.SYSTEM_ALERT_WINDOW" />

<uses-permission android:name="android.permission.ACCESS_NETWORK_STATE"/>

<application
android:usesCleartextTraffic="true"
android:allowBackup="true"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -244,67 +244,6 @@ class EMClientRepository: BaseRepository() {
}
}

/**
* Get verification code from server.
*/
suspend fun getVerificationCode(phoneNumber: String?): Int =
withContext(Dispatchers.IO) {
suspendCoroutine { continuation ->
getVerificationCodeFromServer(
phoneNumber,
onSuccess = {
continuation.resume(ChatError.EM_NO_ERROR)
},
onError = { code, error ->
continuation.resumeWithException(ChatException(code, error))
}
)
}
}

private fun getVerificationCodeFromServer(phoneNumber: String?, onSuccess: OnSuccess, onError: OnError) {
if (phoneNumber.isNullOrEmpty()) {
onError(ChatError.INVALID_PARAM, getContext().getString(R.string.em_login_phone_empty))
return
}
try {
val headers: MutableMap<String, String> = java.util.HashMap()
headers["Content-Type"] = "application/json"
val url = "$SEND_SMS_URL/$phoneNumber/"
EMLog.d("getVerificationCodeFromServe url : ", url)
val response =
HttpClientManager.httpExecute(url, headers, null, HttpClientManager.Method_POST)
val code = response.code
val responseInfo = response.content
if (code == 200) {
onSuccess()
} else {
if (responseInfo != null && responseInfo.isNotEmpty()) {
var errorInfo: String? = null
try {
val responseObject = JSONObject(responseInfo)
errorInfo = responseObject.getString("errorInfo")
if (errorInfo.contains("wait a moment while trying to send")) {
errorInfo =
getContext().getString(R.string.em_login_error_send_code_later)
} else if (errorInfo.contains("exceed the limit of")) {
errorInfo =
getContext().getString(R.string.em_login_error_send_code_limit)
}
} catch (e: JSONException) {
e.printStackTrace()
errorInfo = responseInfo
}
onError(code, errorInfo)
} else {
onError(code, responseInfo)
}
}
} catch (e: java.lang.Exception) {
onError(ChatError.NETWORK_ERROR, e.message)
}
}

/**
* 注销账户
* @return
Expand Down
Loading