Browse Source

增加推送ID同步接口

Pq 1 year ago
parent
commit
c46b157ecc

+ 23 - 0
institution/src/main/java/com/cooleshow/institution/stu/presenter/MainPresenter.java

@@ -1,5 +1,8 @@
 package com.cooleshow.institution.stu.presenter;
 
+import android.text.TextUtils;
+
+import com.cooleshow.base.common.BaseConstant;
 import com.cooleshow.base.presenter.BasePresenter;
 import com.cooleshow.base.rx.BaseObserver;
 import com.cooleshow.base.utils.RequestBodyUtil;
@@ -45,4 +48,24 @@ public class MainPresenter extends BasePresenter<MainContract.MainContractView>
             }
         });
     }
+
+    /**
+     * @param
+     */
+    public void notifyUserPushId(String registerId) {
+        if (TextUtils.isEmpty(registerId)) {
+            return;
+        }
+        JSONObject jsonObject = new JSONObject();
+        try {
+            jsonObject.put("imDeviceId", registerId);
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        addSubscribe(create(UserApi.class).notifyUserPushId(BaseConstant.CLIENT_API_GROUP_NAME, RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<Object>(getView()) {
+            @Override
+            protected void onSuccess(Object data) {
+            }
+        });
+    }
 }

+ 4 - 0
institution/src/main/java/com/cooleshow/institution/stu/ui/main/MainActivity.java

@@ -302,10 +302,14 @@ public class MainActivity extends BaseMVPActivity<ActivityInstitutionMainLayoutB
     private void bindPushId() {
         String userId = UserHelper.getUserId();
         if (isNeedSetPushId && UserHelper.isLogin() && !TextUtils.isEmpty(userId)) {
+            BaseApplication.registrationId=JPushInterface.getRegistrationID(getApplicationContext());
             LogUtils.i("pq", "registrationId:" + BaseApplication.registrationId);
             JPushInterface.setAlias(getApplicationContext(), 1, userId);
             CrashReport.setDeviceId(getApplicationContext(), userId);
             isNeedSetPushId = false;
+            if (presenter != null) {
+                presenter.notifyUserPushId(BaseApplication.registrationId);
+            }
         }
     }
 

+ 28 - 0
student/src/main/java/com/cooleshow/student/presenter/main/MainPresenter.java

@@ -1,11 +1,19 @@
 package com.cooleshow.student.presenter.main;
 
+import android.text.TextUtils;
+
+import com.cooleshow.base.common.BaseConstant;
 import com.cooleshow.base.presenter.BasePresenter;
 import com.cooleshow.base.rx.BaseObserver;
+import com.cooleshow.base.utils.RequestBodyUtil;
 import com.cooleshow.student.api.APIService;
 import com.cooleshow.student.contract.MainContract;
 import com.cooleshow.usercenter.bean.StudentUserInfo;
 import com.cooleshow.usercenter.bean.UserInfo;
+import com.cooleshow.usercenter.data.api.UserApi;
+
+import org.json.JSONException;
+import org.json.JSONObject;
 
 
 /**
@@ -31,4 +39,24 @@ public class MainPresenter extends BasePresenter<MainContract.MainView> implemen
             }
         });
     }
+
+    /**
+     * @param
+     */
+    public void notifyUserPushId(String registerId) {
+        if (TextUtils.isEmpty(registerId)) {
+            return;
+        }
+        JSONObject jsonObject = new JSONObject();
+        try {
+            jsonObject.put("imDeviceId", registerId);
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        addSubscribe(create(UserApi.class).notifyUserPushId(BaseConstant.CLIENT_API_GROUP_NAME, RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<Object>(getView()) {
+            @Override
+            protected void onSuccess(Object data) {
+            }
+        });
+    }
 }

+ 4 - 0
student/src/main/java/com/cooleshow/student/ui/main/MainActivity.java

@@ -412,10 +412,14 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
     private void bindPushId() {
         if (isNeedSetPushId && UserHelper.isLogin() && !TextUtils.isEmpty(UserHelper.getUserId())) {
             String userId = UserHelper.getUserId();
+            BaseApplication.registrationId=JPushInterface.getRegistrationID(getApplicationContext());
             LogUtils.i("pq", "registrationId:" + BaseApplication.registrationId);
             JPushInterface.setAlias(getApplicationContext(), 1, userId);
             CrashReport.setDeviceId(getApplicationContext(), userId);
             isNeedSetPushId = false;
+            if (presenter != null) {
+                presenter.notifyUserPushId(BaseApplication.registrationId);
+            }
         }
     }
 

+ 28 - 0
teacher/src/main/java/com/cooleshow/teacher/presenter/main/MainPresenter.java

@@ -1,13 +1,21 @@
 package com.cooleshow.teacher.presenter.main;
 
+import android.text.TextUtils;
+
+import com.cooleshow.base.common.BaseConstant;
 import com.cooleshow.base.presenter.BasePresenter;
 import com.cooleshow.base.rx.BaseObserver;
+import com.cooleshow.base.utils.RequestBodyUtil;
 import com.cooleshow.teacher.api.APIService;
 import com.cooleshow.teacher.bean.TeacherPromoteIncomeBean;
 import com.cooleshow.teacher.contract.HomeContract;
 import com.cooleshow.teacher.contract.MainContract;
 import com.cooleshow.usercenter.bean.TeacherUserInfo;
 import com.cooleshow.usercenter.bean.UserInfo;
+import com.cooleshow.usercenter.data.api.UserApi;
+
+import org.json.JSONException;
+import org.json.JSONObject;
 
 /**
  * Author by pq, Date on 2022/4/20.
@@ -40,4 +48,24 @@ public class MainPresenter extends BasePresenter<MainContract.MainView> implemen
             }
         });
     }
+
+    /**
+     * @param
+     */
+    public void notifyUserPushId(String registerId) {
+        if (TextUtils.isEmpty(registerId)) {
+            return;
+        }
+        JSONObject jsonObject = new JSONObject();
+        try {
+            jsonObject.put("imDeviceId", registerId);
+        } catch (JSONException e) {
+            e.printStackTrace();
+        }
+        addSubscribe(create(UserApi.class).notifyUserPushId(BaseConstant.CLIENT_API_GROUP_NAME, RequestBodyUtil.convertToRequestBodyJson(jsonObject.toString())), new BaseObserver<Object>(getView()) {
+            @Override
+            protected void onSuccess(Object data) {
+            }
+        });
+    }
 }

+ 4 - 0
teacher/src/main/java/com/cooleshow/teacher/ui/main/MainActivity.java

@@ -389,10 +389,14 @@ public class MainActivity extends BaseMVPActivity<ActivityMainBinding, MainPrese
     private void bindPushId() {
         if (isNeedSetPushId && UserHelper.isLogin() && !TextUtils.isEmpty(UserHelper.getUserId())) {
             String userId = UserHelper.getUserId();
+            BaseApplication.registrationId=JPushInterface.getRegistrationID(getApplicationContext());
             LogUtils.i("pq", "registrationId:" + BaseApplication.registrationId);
             JPushInterface.setAlias(getApplicationContext(), 1, userId);
             CrashReport.setDeviceId(getApplicationContext(), userId);
             isNeedSetPushId = false;
+            if (presenter != null) {
+                presenter.notifyUserPushId(BaseApplication.registrationId);
+            }
         }
     }
 

+ 3 - 0
usercenter/src/main/java/com/cooleshow/usercenter/data/api/UserApi.kt

@@ -224,4 +224,7 @@ interface UserApi {
      */
     @POST(BaseConstant.AUTH_GROUP + "user/checkVerityCode")
     fun checkSmsCode(@Body body: RequestBody): Observable<BaseResponse<Any?>?>?
+
+    @POST("{group_name}"+"/user/updateImUserInfo")
+    fun notifyUserPushId(@Path("group_name") group_name :String,@Body body: RequestBody?): Observable<BaseResponse<Object>?>?
 }