ソースを参照

推送register ID相关

Steven 1 年間 前
コミット
953a9f8af4

+ 9 - 0
KulexiuForStudent/KulexiuForStudent/Common/Base/KSNetworkingManager.h

@@ -995,6 +995,15 @@ NS_ASSUME_NONNULL_BEGIN
 /// @param success 成功
 /// @param faliure 失败
 + (void)userMusicRemoveRequest:(NSString *)post musicId:(NSString *)musicId success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure;
+
+/// 更新极光推送设备id
+/// @param post post
+/// @param pushDeviceId 推送id
+/// @param access_token token
+/// @param success 成功
+/// @param faliure 失败
++ (void)updateRemotePushInfoRequest:(NSString *)post pushDeviceId:(NSString *)pushDeviceId access_token:(NSString *)access_token success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure;
+
 @end
 
 NS_ASSUME_NONNULL_END

+ 33 - 0
KulexiuForStudent/KulexiuForStudent/Common/Base/KSNetworkingManager.m

@@ -34,6 +34,10 @@
     else {
         [[VoNetworking sharedManager] configHttpHeader:@{@"Content-Type":@"application/x-www-form-urlencoded"}];
     }
+    NSInteger tenantId = [UserDefaultObjectForKey(TENANT_ID) integerValue];
+    if (tenantId > 0) {
+        [[VoNetworking sharedManager] addHttpHeader:[NSString stringWithFormat:@"%zd", tenantId] forKey:@"coopId"];
+    }
 }
 
 + (void)clearRequestHeader {
@@ -58,6 +62,19 @@
     [self configRequestHeader];
 }
 
+// 设置json提交方式
++ (void)configRequestMethodJSONWithToken:(NSString *)token {
+    [VoNetworking sharedManager].httpSessionManager.requestSerializer = [AFJSONRequestSerializer serializer];
+    [[VoNetworking sharedManager] configHttpHeader:@{@"Content-Type":@"application/json"}];
+    if (![NSString isEmptyString:token]) {
+        [[VoNetworking sharedManager] configHttpHeader:@{@"Authorization":[NSString stringWithFormat:@"%@ %@", UserDefault(Token_type), token]}];
+    }
+    NSInteger tenantId = [UserDefaultObjectForKey(TENANT_ID) integerValue];
+    if (tenantId > 0) {
+        [[VoNetworking sharedManager] addHttpHeader:[NSString stringWithFormat:@"%zd", tenantId] forKey:@"coopId"];
+    }
+}
+
 + (NSString *)returnNoContainGroupId:(NSString *)groupId {
     if (![NSString isEmptyString:groupId]) {
         if ([groupId containsString:@"S"] || [groupId containsString:@"I"]) {
@@ -1908,4 +1925,20 @@
     [parm setValue:musicId forKey:@"id"];
     [self request:post andWithUrl:url and:parm success:success faliure:faliure];
 }
+
+/// 更新极光推送设备id
+/// @param post post
+/// @param pushDeviceId 推送id
+/// @param access_token token
+/// @param success 成功
+/// @param faliure 失败
++ (void)updateRemotePushInfoRequest:(NSString *)post pushDeviceId:(NSString *)pushDeviceId access_token:(NSString *)access_token success:(void(^)(NSDictionary *dic))success faliure:(void(^)(NSError *error))faliure {
+    [self configRequestMethodJSONWithToken:access_token];
+    
+    NSString *url = [NSString stringWithFormat:@"%@%@%@", hostURL, @"/api-student", @"/user/updateImUserInfo"];
+    NSMutableDictionary *parm = [NSMutableDictionary dictionary];
+    [parm setValue:pushDeviceId forKey:@"imDeviceId"];
+    [self request:post andWithUrl:url and:parm success:success faliure:faliure];
+}
+
 @end

+ 19 - 19
KulexiuForStudent/KulexiuForStudent/Common/Define/KSDomain.h

@@ -18,31 +18,31 @@
 
 // 开发环境
 
-//#define hostURL (@"https://dev.colexiu.com")
-//#define SEALCLASSHOST (@"https://dev.colexiu.com/api-classroom")
-//#define WEBHOST (@"https://dev.colexiu.com/student")
-//#define TENANT_WEBHOST (@"https://dev.colexiu.com/tenant")
-//#define SOCKET_URL (@"wss://dev.colexiu.com/audioAnalysis")
-//#define JSPUSH_ENVIRONMENT (NO)
-//#define RCIM_KEY (@"0vnjpoad0jbdz")
-//#define SUBMIT_UUID (NO)
-//#define CONFIG_TXSDKAPPID (1400805079)
-//#define TXOfflinePushCertificateIDForAPNS (39557)
-
-
-// 测试环境
-
-#define hostURL (@"https://test.colexiu.com")
-#define SEALCLASSHOST (@"https://test.colexiu.com/api-classroom")
-#define WEBHOST (@"https://test.colexiu.com/student")
-#define TENANT_WEBHOST (@"https://test.colexiu.com/tenant")
-#define SOCKET_URL (@"wss://test.colexiu.com/audioAnalysis")
+#define hostURL (@"https://dev.colexiu.com")
+#define SEALCLASSHOST (@"https://dev.colexiu.com/api-classroom")
+#define WEBHOST (@"https://dev.colexiu.com/student")
+#define TENANT_WEBHOST (@"https://dev.colexiu.com/tenant")
+#define SOCKET_URL (@"wss://dev.colexiu.com/audioAnalysis")
 #define JSPUSH_ENVIRONMENT (NO)
 #define RCIM_KEY (@"0vnjpoad0jbdz")
 #define SUBMIT_UUID (NO)
 #define CONFIG_TXSDKAPPID (1400805079)
 #define TXOfflinePushCertificateIDForAPNS (39557)
 
+
+// 测试环境
+
+//#define hostURL (@"https://test.colexiu.com")
+//#define SEALCLASSHOST (@"https://test.colexiu.com/api-classroom")
+//#define WEBHOST (@"https://test.colexiu.com/student")
+//#define TENANT_WEBHOST (@"https://test.colexiu.com/tenant")
+//#define SOCKET_URL (@"wss://test.colexiu.com/audioAnalysis")
+//#define JSPUSH_ENVIRONMENT (NO)
+//#define RCIM_KEY (@"0vnjpoad0jbdz")
+//#define SUBMIT_UUID (NO)
+//#define CONFIG_TXSDKAPPID (1400805079)
+//#define TXOfflinePushCertificateIDForAPNS (39557)
+
 // 预生产
 //#define hostURL (@"https://ponline.colexiu.com")
 //#define SEALCLASSHOST (@"https://ponline.colexiu.com/api-classroom")

+ 22 - 0
KulexiuForStudent/KulexiuForStudent/Module/Login/Model/UserInfoManager.m

@@ -166,8 +166,15 @@
             }
             
             if (needConnect) {
+                NSString *access_token = UserDefault(TokenKey);
                 // 设置推送别名
                 [JPUSHService setAlias:UserDefault(UIDKey) completion:nil seq:0];
+                // 上传registrationID
+                [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
+                    if (![NSString isEmptyString:registrationID] && ![NSString isEmptyString:access_token]) {
+                        [self saveRegisterId:registrationID accessToken:access_token];
+                    }
+                }];
                 [Bugly setUserIdentifier:UserDefault(UIDKey)];
                 [self connectIM];
             }
@@ -341,8 +348,15 @@
             [[NSUserDefaults standardUserDefaults] synchronize];
             // 请求头
             [self addRequestHeader];
+            NSString *access_token = UserDefault(TokenKey);
             // 设置推送别名
             [JPUSHService setAlias:UserDefault(UIDKey) completion:nil seq:0];
+            // 上传registrationID
+            [JPUSHService registrationIDCompletionHandler:^(int resCode, NSString *registrationID) {
+                if (![NSString isEmptyString:registrationID] && ![NSString isEmptyString:access_token]) {
+                    [self saveRegisterId:registrationID accessToken:access_token];
+                }
+            }];
             [Bugly setUserIdentifier:UserDefault(UIDKey)];
             [self connectIM];
             [self startUMCountAndLoginCount];
@@ -384,4 +398,12 @@
 - (void)dealloc {
     [[NSNotificationCenter defaultCenter] removeObserver:self];
 }
+
+- (void)saveRegisterId:(NSString *)registerId accessToken:(NSString *)accessToken {
+    [KSNetworkingManager updateRemotePushInfoRequest:KS_POST pushDeviceId:registerId access_token:accessToken success:^(NSDictionary * _Nonnull dic) {
+        NSLog(@"---");
+    } faliure:^(NSError * _Nonnull error) {
+        NSLog(@"---");
+    }];
+}
 @end