You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

211 lines
6.6 KiB

//
// DMessage.m
// watch
//
// Created by xTT on 2017/7/22.
// Copyright © 2017xTT. All rights reserved.
//
#import "DMessage.h"
#import "User.h"
@implementation DMessage
+ (NSDictionary *)mj_replacedKeyFromPropertyName {
return @{@"msgId":@"id"};
}
//MARK : ---------------公共接口--------------
+ (void)getObjsWithID:(NSString *)ID
url:(NSString*)url
success:(void (^)(NSMutableArray *arr))success
failure:(void (^)(NSError *error))failure{
// add by lsz 21-12-28 @try{}@catch{}
@try {
NSMutableDictionary *parameters = [NSMutableDictionary dictionary];
if (ID) {
NSDictionary *tmp = @{@"id":@{@"lt":ID}};
[parameters setObject:tmp.mj_JSONString forKey:@"query"];
[parameters setObject:@"id" forKey:@"sortKey"];
}
[xMyHttp URL:url
method:@"GET" parameters:parameters
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) {
NSMutableArray *arr = [DMessage mj_objectArrayWithKeyValuesArray:responseObject[@"messages"]];
success(arr);
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure(error);
}
}];
} @catch (NSException *exception) {
if (failure) {
NSDictionary *userInfo = @{NSLocalizedDescriptionKey:@"公共接口异常"};
NSError *error = [NSError errorWithDomain:@"com.ecellsz.lekang" code:-1 userInfo:userInfo];
failure(error);
}
}
}
+ (void)delectTrackWithMessageIds:(NSArray*)messageIds
url:(NSString*)url
success:(void (^)(id responseObject))success
failure:(void (^)(void))failure{
NSMutableDictionary *parameter = [NSMutableDictionary dictionary];
if(messageIds && messageIds.count > 0){
[parameter setValue:[messageIds mj_JSONString] forKey:@"messageIds"];
}
[xMyHttp URL:url
method:@"DELETE"
parameters:parameter
success:^(NSURLSessionDataTask *task, id responseObject) {
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) {
if(success){
success(responseObject);
}
}else{
if(failure){
failure();
}
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if(failure){
failure();
}
}];
}
//MAKR: --------------公共接口-------------
//获取 提醒 的接口
+(void)getObjsWithID:(NSString *)ID
success:(void (^)(NSMutableArray *))success
failure:(void (^)(NSError *))failure{
NSString *urlStr = [MyHttp getURL:@"getway/accounts/[openid]/message"
objArr:@[cUser]];
[self getObjsWithID:ID
url:urlStr success:^(NSMutableArray *arr) {
success(arr);
} failure:^(NSError *error) {
failure(error);
}];
}
//删除提醒的接口
+ (void)delectTrackWithMessageIds:(NSArray *)messageIds
success:(void (^)(id))success
failure:(void (^)(void))failure{
NSString *url = [MyHttp getURL:@"getway/accounts/[openid]/message"
objArr:@[cUser]];
[self delectTrackWithMessageIds:messageIds url:url success:^(id responseObject) {
success(responseObject);
} failure:^{
failure();
}];
}
/**
获取关注记录数据
*/
+ (void)getAttentionsWithID:(NSString *)ID
success:(void (^)(NSMutableArray *arr))success
failure:(void (^)(NSError *error))failure{
NSString *urlStr = [MyHttp getURL:@"getway/accounts/[openid]/attention"
objArr:@[cUser]];
[self getObjsWithID:ID
url:urlStr success:^(NSMutableArray *arr) {
success(arr);
} failure:^(NSError *error) {
failure(error);
}];
}
/**
删除关注记录数据
*/
+ (void)delectAttentionsWithMessageIds:(NSArray *)messageIds
success:(void (^)(id))success
failure:(void (^)(void))failure{
NSString *url = [MyHttp getURL:@"getway/accounts/[openid]/attention"
objArr:@[cUser]];
[self delectTrackWithMessageIds:messageIds url:url success:^(id responseObject) {
success(responseObject);
} failure:^{
failure();
}];
}
/**
处理关注记录数据(管理员)
@param params 参数
@param success 成功
@param failure 失败
*/
+(void)manageAttentionWithParams:(NSDictionary*)params
success:(void (^)(void))success
failure:(void (^)(void))failure{
NSString *url = [MyHttp getURL:@"getway/accounts/[openid]/attention"
objArr:@[cUser]];
[xMyHttp URL:url
method:@"POST" parameters:params
success:^(NSURLSessionDataTask *task, id responseObject)
{
if ([responseObject[@"code"] intValue] == HTTP_SUCCESS) {
success();
}
} failure:^(NSURLSessionDataTask *task, NSError *error) {
if (failure) {
failure();
}
}];
}
/**
获取通知数据
*/
+ (void)getNotificationWithID:(NSString *)ID
success:(void (^)(NSMutableArray *arr))success
failure:(void (^)(NSError *error))failure{
NSString *urlStr = [MyHttp getURL:@"getway/accounts/[openid]/notification"
objArr:@[cUser]];
[self getObjsWithID:ID
url:urlStr success:^(NSMutableArray *arr) {
success(arr);
} failure:^(NSError *error) {
failure(error);
}];
}
/**
删除通知数据
*/
+ (void)delectNotificationWithMessageIds:(NSArray *)messageIds
success:(void (^)(id))success
failure:(void (^)(void))failure{
NSString *url = [MyHttp getURL:@"getway/accounts/[openid]/notification"
objArr:@[cUser]];
[self delectTrackWithMessageIds:messageIds url:url success:^(id responseObject) {
success(responseObject);
} failure:^{
failure();
}];
}
@end