瀏覽代碼

修改发送验证码逻辑

Pq 2 年之前
父節點
當前提交
4f80708131

+ 12 - 0
usercenter/src/main/java/com/cooleshow/usercenter/constants/UserConstants.java

@@ -0,0 +1,12 @@
+package com.cooleshow.usercenter.constants;
+
+/**
+ * Author by pq, Date on 2022/5/26.
+ */
+public class UserConstants {
+    public static final String SEND_VERIFY_CODE_TYPE_PASSWD ="PASSWD";//发送验证码type-修改密码
+    public static final String SEND_VERIFY_CODE_TYPE_LOGIN ="LOGIN";//发送验证码type-登录
+    public static final String SEND_VERIFY_CODE_TYPE_REGISTER ="REGISTER";//发送验证码type-注册
+    public static final String SEND_VERIFY_CODE_TYPE_BANK ="BANK";//发送验证码type-绑定银行卡
+
+}

+ 27 - 2
usercenter/src/main/java/com/cooleshow/usercenter/data/api/UserApi.kt

@@ -24,7 +24,7 @@ interface UserApi {
         用户登录
      */
     @FormUrlEncoded
-    @POST("api-auth/usernameLogin")
+    @POST(BaseConstant.AUTH_GROUP + "usernameLogin")
     fun login(@FieldMap req: MutableMap<String?, String?>): Observable<BaseResponse<UserLoginInfo>>
 
 
@@ -33,8 +33,21 @@ interface UserApi {
     */
     @FormUrlEncoded
     @POST(BaseConstant.TEACHER_GROUP + "code/sendSmsCode")
-    fun sendSmsCode(@Field("mobile") mobile: String): Observable<BaseResponse<Object>>
+    fun sendSmsCode(
+        @Field("mobile") mobile: String,
+        @Field("type") type: String
+    ): Observable<BaseResponse<Object>>
+
 
+    /*
+      发送验证码
+   */
+    @FormUrlEncoded
+    @POST(BaseConstant.STUDENT_GROUP + "code/sendSmsCode")
+    fun sendSmsCodeForStu(
+        @Field("mobile") mobile: String,
+        @Field("type") type: String
+    ): Observable<BaseResponse<Object>>
 
     /*
           校验验证码
@@ -46,6 +59,18 @@ interface UserApi {
         @Field("code") code: String
     ): Observable<BaseResponse<Object>>
 
+
+    /*
+         校验验证码
+      */
+    @FormUrlEncoded
+    @POST(BaseConstant.STUDENT_GROUP + "code/verifySmsCode")
+    fun checkVerifyCodeValidityForStu(
+        @Field("phone") phone: String,
+        @Field("code") code: String
+    ): Observable<BaseResponse<Object>>
+
+
     /*
          验证码登录
       */

+ 1 - 1
usercenter/src/main/java/com/cooleshow/usercenter/helper/UserHelper.java

@@ -10,7 +10,7 @@ import com.cooleshow.usercenter.bean.UserInfo;
 import com.cooleshow.usercenter.bean.UserLoginInfo;
 
 /**
- * Author by pq, Date on 2022/4/22.
+ * Author by pq, Date nton 2022/4/22.
  */
 public class UserHelper {
     public static final String USER_TOKEN_KEY = "user_token";

+ 41 - 1
usercenter/src/main/java/com/cooleshow/usercenter/presenter/VerifyLoginPresenter.java

@@ -1,9 +1,11 @@
 package com.cooleshow.usercenter.presenter;
 
+import com.cooleshow.base.common.BaseApplication;
 import com.cooleshow.base.constanst.Constants;
 import com.cooleshow.base.presenter.BasePresenter;
 import com.cooleshow.base.rx.BaseObserver;
 import com.cooleshow.usercenter.bean.UserLoginInfo;
+import com.cooleshow.usercenter.constants.UserConstants;
 import com.cooleshow.usercenter.data.api.UserApi;
 import com.cooleshow.usercenter.presenter.contract.VerifyLoginContract;
 
@@ -21,7 +23,45 @@ public class VerifyLoginPresenter extends BasePresenter<VerifyLoginContract.Veri
         if (getView() != null) {
             getView().showLoading();
         }
-        addSubscribe(create(UserApi.class).sendSmsCode(mobile), new BaseObserver<Object>(getView()) {
+        if (BaseApplication.Companion.isTeacherClient()) {
+            sendVerifyCodeForTeacher(mobile);
+        } else {
+            sendVerifyCodeForStu(mobile);
+        }
+    }
+
+
+    /**
+     * 学生端发送验证码
+     *
+     * @param mobile
+     */
+    private void sendVerifyCodeForStu(String mobile) {
+        addSubscribe(create(UserApi.class).sendSmsCode(mobile, UserConstants.SEND_VERIFY_CODE_TYPE_LOGIN), new BaseObserver<Object>(getView()) {
+            @Override
+            protected void onSuccess(Object data) {
+                if (getView() != null) {
+                    getView().sendVerifyCodeSuccess();
+                }
+            }
+
+            @Override
+            public void onError(Throwable e) {
+                super.onError(e);
+                if (getView() != null) {
+                    getView().sendVerifyCodeFail();
+                }
+            }
+        });
+    }
+
+    /**
+     * 老师端发送验证码
+     *
+     * @param mobile
+     */
+    private void sendVerifyCodeForTeacher(String mobile) {
+        addSubscribe(create(UserApi.class).sendSmsCode(mobile, UserConstants.SEND_VERIFY_CODE_TYPE_LOGIN), new BaseObserver<Object>(getView()) {
             @Override
             protected void onSuccess(Object data) {
                 if (getView() != null) {