123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- //
- // YOUPAILCIMTool.m
- // LiveChat
- //
- // Created by 张灿 on 2018/9/28.
- // Copyright © 2018年 caicai. All rights reserved.
- //
- #import "YOUPAILCIMTool.h"
- #import "YOUPAILCVerifyBigCastVC.h"
- #import "LZAlertWindow.h"
- #import "UIViewController+TFPresent.h"
- #import "YOUPAILZVipVC.h"
- @implementation YOUPAILCIMTool
- + (void)sendMessage:(NIMMessage*)message sessionid:(NSString*)sessionid completion:(sendMessageBlock)sendBlock{
-
- NSString *msgType;
- NSString *content = @"";
- if (message.messageType ==NIMMessageTypeText) {
- msgType = @"1";
- content = message.text;
- }else if(message.messageType == NIMMessageTypeAudio){
- msgType = @"2";
- }else if(message.messageType == NIMMessageTypeImage){
- msgType = @"3";
- }else if(message.messageType == NIMMessageTypeVideo){
- msgType = @"4";
- }else{
- msgType =@"100";//代表自定义消息类型
- }
-
- if ([LCSaveData getIMPrice] > 0 && [LCSaveModel getUserModel].youpaipuserinfo.youpaipvip == 0 && [LCSaveModel getUserModel].youpaipuserinfo.youpaipis_anchor != 1 && ![[LCSaveData getServiceIdArr] containsObject:sessionid]) {
- // if (![LCSaveData getPayIMNotTip]) {
- //
- //// NSString* tipStr = [NSString stringWithFormat:@"一条消息扣费%zd钻石,",[LCSaveData getIMPrice]];
- //
- // if([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender==1){
- // tipStr = [NSString stringWithFormat:@"%@%@",tipStr,@"成为女神即可免费私信哦!"];
- // }else{
- // tipStr = [NSString stringWithFormat:@"%@%@",tipStr,@"成为伯爵及以上贵族即可免费私信哦!"];
- // }
- // NSString *confimActionStr = @"去开通";
- // if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 1) {
- // confimActionStr = @"去认证";
- // }
- //
- // LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"继续发送" handler:^(LZAlertAction *action) {
- // [LCSaveData savePayIMNotTip:YES];
- // [self sendIM:message sessionid:sessionid msgType:msgType content:content completion:sendBlock];
- // }];
- // cancelAction.cornerRadius = 24.0f;
- // cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
- // LZAlertAction *confimAction = [LZAlertAction actionWithTitle:confimActionStr handler:^(LZAlertAction *action) {
- // if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender==1) {
- // YOUPAILCVerifyBigCastVC* verifyBigCast = [[YOUPAILCVerifyBigCastVC alloc]init];
- // [[LCTools getCurrentVC].navigationController pushViewController:verifyBigCast animated:YES];
- // }else{
- // YOUPAILZVipVC* setting = [[YOUPAILZVipVC alloc]init];
- // [[LCTools getCurrentVC].navigationController pushViewController:setting animated:YES];
- // }
- // }];
- // confimAction.cornerRadius = 24.0f;
- // confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
- // LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:tipStr action:@[cancelAction,confimAction]];
- // [[LCTools getCurrentVC] TFPresentVC:alert completion:^{}];
- // }
- // else{
- [self sendIM:message sessionid:sessionid msgType:msgType content:content completion:sendBlock];
- // }
- }else{
- [self sendIM:message sessionid:sessionid msgType:msgType content:content completion:sendBlock];
- }
-
-
-
- }
- + (void)sendIM:(NIMMessage*)message sessionid:(NSString*)sessionid msgType:(NSString *)msgType content:(NSString *)content completion:(sendMessageBlock)sendBlock{
- [LCHttpHelper requestWithURLString:SendIM parameters:@{@"to_uid":sessionid,@"type":msgType,@"content":content,@"msgId":message.messageId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
- NSDictionary* dict = (NSDictionary*)responseObject;
- NSInteger code = [[dict objectForKey:@"code"] integerValue];
- if (code==0) {//成功
- NSDictionary* data = [dict objectForKey:@"data"];
- if([LCSaveModel getUserModel]){
- message.apnsPayload = @{@"userId":[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id};
- }
-
- NIMMessageSetting* setting = [[NIMMessageSetting alloc]init];
- setting.apnsEnabled = YES;
- setting.apnsWithPrefix = NO;
- message.setting = setting;
- if (message.messageType == NIMMessageTypeText) {
- message.apnsContent = @"收到一条信息";
- }else if(message.messageType == NIMMessageTypeImage){
- message.apnsContent = @"收到一张图片";
- }else if(message.messageType == NIMMessageTypeAudio){
- message.apnsContent = @"收到一段语音";
- }else if(message.messageType == NIMMessageTypeVideo){
- message.apnsContent = @"收到一段小视频";
- }
-
-
-
- // NSInteger cut= [[data objectForKey:@"is_cut"]integerValue]; //0不扣费 1扣费
- // NSInteger cut_coin= [[data objectForKey:@"cut_coin"]integerValue]; //扣除的虾币数
- // NSInteger coin= [[data objectForKey:@"coin"]integerValue]; //剩余虾币数
-
- NSInteger filter = [[data objectForKey:@"filter"]integerValue]; //是否过滤掉
- if (sendBlock) {
- message.remoteExt = data;
- if (message.messageType == NIMMessageTypeText) {
- message.text = message.text;
- }
- //modify by leo 添加违规替代字段 只有文本消息有
- if (message.messageType == NIMMessageTypeText)
- sendBlock(message,filter,[data objectForKey:@"content"]);
- else
- sendBlock(message,filter,@"");
- }
- }
- } failure:^(NSError *error) {
-
- }];
- }
- - (void)sendLocalNotificationWithMessage:(NIMMessage *)message {
-
- }
- @end
|