Commit 75243275 by 刘鹏

feat : 登录完成

parent 5c8b03ca
......@@ -21,9 +21,9 @@ import java.util.List;
public final class DemoGlobalConfig implements IConfigModule {
String APP_DOMAIN = "https://api.github.com/";
// public static String appEnv = YDLConstants.ENV_AUTO_TEST;
// public static String appEnv = YDLConstants.ENV_TEST;
public static String appEnv = YDLConstants.ENV_TEST;
// public static String appEnv = YDLConstants.ENV_NEW_TEST;//配置未上传到maven库
public static String appEnv = YDLConstants.ENV_PROD;
// public static String appEnv = YDLConstants.ENV_PROD;
@Override
public void injectAppLifecycle(@NotNull Context context, @NotNull List<IAppLifecycles> lifecycles) {
lifecycles.add(new DemoAppLifecycles());
......
package com.ydl.component.rtc;
import android.content.Intent;
import android.graphics.Color;
import android.os.Build;
import android.os.Bundle;
import android.text.TextUtils;
import android.util.Log;
import android.view.View;
import android.view.Window;
import android.view.WindowManager;
import android.widget.Button;
import android.widget.EditText;
import android.widget.Toast;
import androidx.appcompat.app.AppCompatActivity;
import com.blankj.utilcode.util.ToastUtils;
import com.tencent.imsdk.v2.V2TIMCallback;
import com.tencent.imsdk.v2.V2TIMManager;
import com.tencent.imsdk.v2.V2TIMSDKConfig;
import com.tencent.imsdk.v2.V2TIMSDKListener;
import com.tencent.imsdk.v2.V2TIMUserFullInfo;
import com.tencent.imsdk.v2.V2TIMValueCallback;
import com.tencent.liteav.basic.UserModel;
import com.tencent.liteav.basic.UserModelManager;
import com.tencent.qcloud.tuicore.TUILogin;
import com.ydl.component.R;
import com.ydl.component.rtc.debug.GenerateTestUserSig;
import java.util.ArrayList;
import java.util.List;
public class MDTLoginActivity extends AppCompatActivity {
private static final String TAG = "LoginActivity";
private EditText mEditUserId;
private Button mButtonLogin;
@Override
public void onCreate(Bundle savedInstanceState) {
super.onCreate(savedInstanceState);
setContentView(R.layout.activity_login);
initStatusBar();
initView();
}
private void initView() {
mEditUserId = (EditText) findViewById(R.id.et_userId);
initButtonLogin();
}
private void initButtonLogin() {
mButtonLogin = (Button) findViewById(R.id.tv_login);
mButtonLogin.setOnClickListener(new View.OnClickListener() {
@Override
public void onClick(View v) {
login();
}
});
}
private void login() {
String userId = mEditUserId.getText().toString().trim();
if (TextUtils.isEmpty(userId)) {
Toast.makeText(this, R.string.user_id_is_empty, Toast.LENGTH_SHORT).show();
return;
}
final UserModelManager manager = UserModelManager.getInstance();
final UserModel userModel = manager.getUserModel();
userModel.phone = userId;
userModel.userId = userId;
userModel.userSig = GenerateTestUserSig.genTestUserSig(userId);
manager.setUserModel(userModel);
V2TIMSDKConfig config = new V2TIMSDKConfig();
config.setLogLevel(V2TIMSDKConfig.V2TIM_LOG_DEBUG);
TUILogin.init(this, GenerateTestUserSig.SDKAPPID, null, new V2TIMSDKListener() {
@Override
public void onKickedOffline() {
}
@Override
public void onUserSigExpired() {
}
});
TUILogin.login(userModel.userId, userModel.userSig, new V2TIMCallback() {
@Override
public void onError(int code, String msg) {
ToastUtils.showLong("登录IM失败,所有功能不可用[%d]%s", code, msg);
Log.d(TAG, "login fail code: " + code + " msg:" + msg);
}
@Override
public void onSuccess() {
Log.d(TAG, "login onSuccess");
getUserInfo();
}
});
}
private void getUserInfo() {
final UserModelManager manager = UserModelManager.getInstance();
final UserModel userModel = manager.getUserModel();
//先查询用户是否存在
List<String> userIdList = new ArrayList<>();
userIdList.add(userModel.userId);
Log.d(TAG, "setUserInfo: userIdList = " + userIdList);
V2TIMManager.getInstance().getUsersInfo(userIdList, new V2TIMValueCallback<List<V2TIMUserFullInfo>>() {
@Override
public void onError(int code, String msg) {
Log.e(TAG, "get group info list fail, code:" + code + " msg: " + msg);
}
@Override
public void onSuccess(List<V2TIMUserFullInfo> resultList) {
if (resultList == null || resultList.isEmpty()) {
return;
}
V2TIMUserFullInfo result = resultList.get(0);
String userName = result.getNickName();
String userAvatar = result.getFaceUrl();
Log.d(TAG, "onSuccess: userName = " + userName + " , userAvatar = " + userAvatar);
//如果用户名和头像为空,则跳转设置界面进行设置
if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(userAvatar)) {
Intent intent = new Intent(MDTLoginActivity.this, ProfileActivity.class);
startActivity(intent);
finish();
} else {
userModel.userAvatar = userAvatar;
userModel.userName = userName;
manager.setUserModel(userModel);
//如果用户信息不为空,则直接进入主界面
Intent intent = new Intent(MDTLoginActivity.this, MDTMainActivity.class);
startActivity(intent);
finish();
}
}
});
}
private void initStatusBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
Window window = getWindow();
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
window.getDecorView().setSystemUiVisibility(View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
| View.SYSTEM_UI_FLAG_LAYOUT_STABLE);
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS);
window.setStatusBarColor(Color.TRANSPARENT);
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
getWindow().addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS);
}
}
}
package com.ydl.component.rtc
import android.annotation.SuppressLint
import android.content.Intent
import android.graphics.Color
import android.os.Build
import android.os.Bundle
import android.text.TextUtils
import android.util.Log
import android.view.View
import android.view.WindowManager
import android.widget.Button
import android.widget.EditText
import android.widget.Toast
import androidx.appcompat.app.AppCompatActivity
import com.blankj.utilcode.util.ToastUtils
import com.tencent.imsdk.v2.*
import com.tencent.liteav.basic.UserModel
import com.tencent.liteav.basic.UserModelManager
import com.tencent.qcloud.tuicore.TUILogin
import com.ydl.component.R
import com.ydl.component.rtc.bean.UserSigResponse
import com.ydl.component.rtc.http.MDTHttpImpl.Companion.getInstance
import com.ydl.ydlcommon.modular.ModularServiceManager.provide
import com.yidianling.common.tools.ToastUtil
import com.yidianling.user.api.bean.UserResponseBean
import com.yidianling.user.api.service.IUserService
import io.reactivex.android.schedulers.AndroidSchedulers
import io.reactivex.schedulers.Schedulers
import java.util.*
class MDTLoginActivity : AppCompatActivity() {
private var mEditUserId: EditText? = null
private var mButtonLogin: Button? = null
public override fun onCreate(savedInstanceState: Bundle?) {
super.onCreate(savedInstanceState)
setContentView(R.layout.activity_login)
initStatusBar()
initView()
}
private fun initView() {
mEditUserId = findViewById<View>(R.id.et_userId) as EditText
initButtonLogin()
}
private fun initButtonLogin() {
mButtonLogin = findViewById<View>(R.id.tv_login) as Button
mButtonLogin!!.setOnClickListener {
getSigin()
}
}
@SuppressLint("CheckResult")
private fun getSigin() {
var user = provide(
IUserService::class.java
).getUserInfo()
val uid = user?.uid
mEditUserId!!.setText(uid)
val userId = mEditUserId!!.text.toString().trim { it <= ' ' }
if (TextUtils.isEmpty(userId)) {
Toast.makeText(this, R.string.user_id_is_empty, Toast.LENGTH_SHORT).show()
return
}
val manager = UserModelManager.getInstance()
val userModel = manager.userModel
uid?.let {uid ->
getInstance().getSecret(UserSigResponse(uid))
.subscribeOn(Schedulers.io())
.observeOn(AndroidSchedulers.mainThread())
.subscribe({ response ->
val data = response.data
if ("200" == response.code) {
userModel.appId = Integer.valueOf(data.appId)
userModel.phone = userId
userModel.userId = userId
userModel.userSig = data.userSig
userModel.userAvatar =user?.head
userModel.userName =user?.nick_name
manager.userModel = userModel
login(userModel)
} else {
ToastUtil.toastShort(response.msg)
}
}, { error ->
ToastUtil.toastShort(error.message)
})
}
}
private fun login(userModel: UserModel) {
val config = V2TIMSDKConfig()
config.logLevel = V2TIMSDKConfig.V2TIM_LOG_DEBUG
TUILogin.init(this, userModel.appId, null, object : V2TIMSDKListener() {
override fun onKickedOffline() {}
override fun onUserSigExpired() {}
})
TUILogin.login(userModel.userId, userModel.userSig, object : V2TIMCallback {
override fun onError(code: Int, msg: String) {
ToastUtils.showLong("登录IM失败,所有功能不可用[%d]%s", code, msg)
Log.d(TAG, "login fail code: $code msg:$msg")
}
override fun onSuccess() {
Log.d(TAG, "login onSuccess")
userInfo
}
})
}//如果用户信息不为空,则直接进入主界面//如果用户名和头像为空,则跳转设置界面进行设置
//先查询用户是否存在
private val userInfo: Unit
private get() {
val manager = UserModelManager.getInstance()
val userModel = manager.userModel
//先查询用户是否存在
val userIdList: MutableList<String> = ArrayList()
userIdList.add(userModel.userId)
Log.d(TAG, "setUserInfo: userIdList = $userIdList")
V2TIMManager.getInstance()
.getUsersInfo(userIdList, object : V2TIMValueCallback<List<V2TIMUserFullInfo>?> {
override fun onError(code: Int, msg: String) {
Log.e(TAG, "get group info list fail, code:$code msg: $msg")
}
override fun onSuccess(resultList: List<V2TIMUserFullInfo>?) {
if (resultList == null || resultList.isEmpty()) {
return
}
val result = resultList[0]
val userName = result.nickName
val userAvatar = result.faceUrl
Log.d(TAG, "onSuccess: userName = $userName , userAvatar = $userAvatar")
//如果用户名和头像为空,则跳转设置界面进行设置
if (TextUtils.isEmpty(userName) || TextUtils.isEmpty(userAvatar)) {
val intent = Intent(this@MDTLoginActivity, ProfileActivity::class.java)
startActivity(intent)
finish()
} else {
userModel.userAvatar = userAvatar
userModel.userName = userName
manager.userModel = userModel
//如果用户信息不为空,则直接进入主界面
val intent = Intent(this@MDTLoginActivity, MDTMainActivity::class.java)
startActivity(intent)
finish()
}
}
})
}
private fun initStatusBar() {
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.LOLLIPOP) {
val window = window
window.clearFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
window.decorView.systemUiVisibility = (View.SYSTEM_UI_FLAG_LAYOUT_FULLSCREEN
or View.SYSTEM_UI_FLAG_LAYOUT_STABLE)
window.addFlags(WindowManager.LayoutParams.FLAG_DRAWS_SYSTEM_BAR_BACKGROUNDS)
window.statusBarColor = Color.TRANSPARENT
} else if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.KITKAT) {
window.addFlags(WindowManager.LayoutParams.FLAG_TRANSLUCENT_STATUS)
}
}
companion object {
private const val TAG = "LoginActivity"
}
}
\ No newline at end of file
......@@ -142,7 +142,7 @@ public class MDTMainActivity extends AppCompatActivity {
}
private void initData() {
TUICallingImpl.sharedInstance(this).enableFloatWindow(true);
TUICallingImpl.sharedInstance(this).enableFloatWindow(false);
}
protected List<TRTCItemEntity> createTRTCItems() {
......
package com.ydl.component.rtc.bean
/**
* 获取用户密钥
* */
data class UserSigBean(
var appId: String,
var region: String,
var secretId: String,
var userSig: String
)
package com.ydl.component.rtc.bean
/**
* @Author: 刘鹏
* @Description:
* @CreateDate: 2022/4/15 16:37
* -------------------------------
* @UpdateUser:
* @UpdateDate: 2022/4/15 16:37
* @UpdateRemark:
* @Version:
*/
class UserSigResponse(var key: String, var channel: String = "tencent")
\ No newline at end of file
......@@ -86,7 +86,8 @@ public class GenerateTestUserSig {
* 文档:https://cloud.tencent.com/document/product/269/32688#Server
*/
public static String genTestUserSig(String userId) {
return GenTLSSignature(SDKAPPID, userId, EXPIRETIME, null, SECRETKEY);
// return GenTLSSignature(SDKAPPID, userId, EXPIRETIME, null, SECRETKEY);
return "eJyrVgrxCdZLrSjILEpVsjIzMLEwMNABi5WlFilZKRnpGShB*MUp2YkFBZkpSlaGJgYGZiZmJgZGEJnMlNS8ksy0TLAGQ2MDS1NjSzNLmLbMdKCoiVNEmHl6lpt2kEtVoUdaUl5iWGSgV3JuuIVjiYebRZ6XdklEpktquFtJpC1UY0lmLtBFhmYmlpaGppbGprUAOugw0Q__";
}
/**
......
package com.ydl.component.rtc.http
import com.ydl.component.rtc.bean.UserSigBean
import com.ydl.component.rtc.bean.UserSigResponse
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import io.reactivex.Observable
interface MDTHttp {
fun getSecret(bean: UserSigResponse): Observable<BaseAPIResponse<UserSigBean>>
}
\ No newline at end of file
package com.ydl.component.rtc.http
import com.google.gson.Gson
import com.ydl.component.rtc.bean.UserSigBean
import com.ydl.component.rtc.bean.UserSigResponse
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import com.ydl.ydlnet.YDLHttpUtils
import io.reactivex.Observable
import okhttp3.MediaType
import okhttp3.RequestBody
class MDTHttpImpl :MDTHttp {
private var mdtService: MDTService? = null
object Holder {
val INSTANCE = MDTHttpImpl()
}
companion object {
fun getInstance(): MDTHttpImpl {
return Holder.INSTANCE
}
}
private fun getMdtService(): MDTService {
if (mdtService == null) {
mdtService = YDLHttpUtils.obtainApi(MDTService::class.java)
}
return mdtService!!
}
//获取登录信息
override fun getSecret(bean: UserSigResponse): Observable<BaseAPIResponse<UserSigBean>> {
val str = Gson().toJson(bean)
val body: RequestBody =
RequestBody.create(MediaType.parse("application/json; charset=utf-8"), str)
return getMdtService().getSecret(body)
}
}
\ No newline at end of file
package com.ydl.component.rtc.http
import com.ydl.component.rtc.bean.UserSigBean
import com.ydl.ydlcommon.base.config.YDL_DOMAIN
import com.ydl.ydlcommon.base.config.YDL_DOMAIN_JAVA
import com.ydl.ydlcommon.data.http.BaseAPIResponse
import io.reactivex.Observable
import okhttp3.RequestBody
import retrofit2.http.Body
import retrofit2.http.Headers
import retrofit2.http.POST
interface MDTService {
//获取用户密钥
@POST("video/secret")
@Headers(
YDL_DOMAIN + YDL_DOMAIN_JAVA,
"Content-Type:application/json"
)
fun getSecret(@Body body: RequestBody): Observable<BaseAPIResponse<UserSigBean>>
}
......@@ -31,10 +31,6 @@
android:enabled="true"
android:exported="false" />
<service
android:name=".ui.floatwindow.FloatWindowService"
android:enabled="true"
android:exported="false" />
</application>
</manifest>
\ No newline at end of file
......@@ -3,6 +3,7 @@ package com.tencent.liteav.basic;
import java.io.Serializable;
public class UserModel implements Serializable {
public int appId;
public String phone;
public String userId;
public String userSig;
......
......@@ -190,7 +190,7 @@ class HttpConfig {
return Interceptor {
val request: Request = it.request()
val originalResponse: Response = it.proceed(request)
// if (!appDebug){
if (!appDebug){
val code = originalResponse.code()
// 接口返回错误的情况下,埋点告诉服务器原因
if (code != 200) {
......@@ -222,7 +222,7 @@ class HttpConfig {
AliYunRichLogsHelper.getInstance().sendRichLog(AliYunLogConfig.API, "writeMaiDianDatacode$code:$api---params:$params ---- message:$message")
}
}
// }
}
originalResponse
}
}
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment