|
@@ -15,6 +15,7 @@ import cn.yyxx.support.encryption.Md5Utils
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.CoroutineScope
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.Dispatchers
|
|
import kotlinx.coroutines.launch
|
|
import kotlinx.coroutines.launch
|
|
|
|
+import kotlinx.coroutines.runBlocking
|
|
import org.json.JSONException
|
|
import org.json.JSONException
|
|
import org.json.JSONObject
|
|
import org.json.JSONObject
|
|
import java.io.File
|
|
import java.io.File
|
|
@@ -33,119 +34,169 @@ class SdkRequest {
|
|
}
|
|
}
|
|
|
|
|
|
fun userLogin(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun userLogin(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
if (jsonObject.getInt("login_type") == LoginType.TYPE_ACCOUNT_LOGIN) {
|
|
if (jsonObject.getInt("login_type") == LoginType.TYPE_ACCOUNT_LOGIN) {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_LOGIN)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_LOGIN)
|
|
} else {
|
|
} else {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_THIRD_PART_LOGIN)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_THIRD_PART_LOGIN)
|
|
}
|
|
}
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "user login has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
fun userRegister(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun userRegister(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_REGISTER)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_REGISTER)
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "user register has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
|
|
|
|
fun bindAccount(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun bindAccount(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_BIND_ACCOUNT)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_BIND_ACCOUNT)
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "bind account has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
|
|
+
|
|
}
|
|
}
|
|
|
|
|
|
fun bindPhone(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun bindPhone(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_BIND_PHONE)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_BIND_PHONE)
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "bind phone has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
fun bindEmail(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun bindEmail(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_BIND_EMAIL)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_BIND_EMAIL)
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "bind email has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
fun getPhoneCaptcha(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun getPhoneCaptcha(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_GET_PHONE_CAPTCHA)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_GET_PHONE_CAPTCHA)
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "get phone captcha has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
fun getEmailCaptcha(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun getEmailCaptcha(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_GET_EMAIL_CAPTCHA)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_GET_EMAIL_CAPTCHA)
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "get email captcha has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
fun forgetUserPwdByPhone(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun forgetUserPwdByPhone(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_FORGET_PWD_BY_PHONE)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_FORGET_PWD_BY_PHONE)
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "forget pwd by phone has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
fun forgetUserPwdByEmail(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun forgetUserPwdByEmail(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_FORGET_PWD_BY_EMAIL)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_FORGET_PWD_BY_EMAIL)
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "forget pwd by email has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
fun modifyUserPwd(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
fun modifyUserPwd(context: Context, jsonObject: JSONObject, callback: (ResultInfo) -> Unit) {
|
|
- try {
|
|
|
|
|
|
+ kotlin.runCatching {
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_MODIFY_PWD)
|
|
jsonObject.put("route_path", Host.BASIC_ROUTE_MODIFY_PWD)
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
- }
|
|
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
- }
|
|
|
|
-
|
|
|
|
- fun submitRoleData(context: Context, timing: Int, roleInfo: SdkRoleInfo, callback: (ResultInfo) -> Unit) {
|
|
|
|
- val jsonObject = JSONObject()
|
|
|
|
- try {
|
|
|
|
- jsonObject.put("route_path", Host.BASIC_ROUTE_SUBMIT_ROLE_INFO)
|
|
|
|
- jsonObject.put("report_type", timing)
|
|
|
|
- jsonObject.put("uid", roleInfo.userId)
|
|
|
|
- jsonObject.put("role_id", roleInfo.roleId)
|
|
|
|
- jsonObject.put("role_name", roleInfo.roleName)
|
|
|
|
- jsonObject.put("role_level", roleInfo.roleLevel)
|
|
|
|
- jsonObject.put("role_ctime", roleInfo.roleCTime)
|
|
|
|
- jsonObject.put("server_id", roleInfo.serverId)
|
|
|
|
- jsonObject.put("server_name", roleInfo.serverName)
|
|
|
|
- jsonObject.put("vip_level", roleInfo.vipLevel)
|
|
|
|
- jsonObject.put("balance", roleInfo.balance)
|
|
|
|
- jsonObject.put("total_purchase", roleInfo.totalPurchase)
|
|
|
|
- } catch (e: JSONException) {
|
|
|
|
- e.printStackTrace()
|
|
|
|
|
|
+ }.onFailure {
|
|
|
|
+ it.printStackTrace()
|
|
|
|
+ val msg = if (TextUtils.isEmpty(it.message)) {
|
|
|
|
+ "modify pwd has some error"
|
|
|
|
+ } else {
|
|
|
|
+ it.message!!
|
|
|
|
+ }
|
|
|
|
+ callback(ResultInfo(-1, msg))
|
|
|
|
+ }.onSuccess {
|
|
|
|
+ VolleyRequest.post(context, jsonObject, callback)
|
|
}
|
|
}
|
|
- VolleyRequest.post(context, jsonObject, callback)
|
|
|
|
}
|
|
}
|
|
|
|
|
|
fun downloadImageFile(context: Context, url: String) {
|
|
fun downloadImageFile(context: Context, url: String) {
|