YOUPAILCIMTool.m 6.2 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. //
  2. // YOUPAILCIMTool.m
  3. // LiveChat
  4. //
  5. // Created by 张灿 on 2018/9/28.
  6. // Copyright © 2018年 caicai. All rights reserved.
  7. //
  8. #import "YOUPAILCIMTool.h"
  9. #import "YOUPAILCVerifyBigCastVC.h"
  10. #import "LZAlertWindow.h"
  11. #import "UIViewController+TFPresent.h"
  12. #import "YOUPAILZVipVC.h"
  13. @implementation YOUPAILCIMTool
  14. + (void)sendMessage:(NIMMessage*)message sessionid:(NSString*)sessionid completion:(sendMessageBlock)sendBlock{
  15. NSString *msgType;
  16. NSString *content = @"";
  17. if (message.messageType ==NIMMessageTypeText) {
  18. msgType = @"1";
  19. content = message.text;
  20. }else if(message.messageType == NIMMessageTypeAudio){
  21. msgType = @"2";
  22. }else if(message.messageType == NIMMessageTypeImage){
  23. msgType = @"3";
  24. }else if(message.messageType == NIMMessageTypeVideo){
  25. msgType = @"4";
  26. }else{
  27. msgType =@"100";//代表自定义消息类型
  28. }
  29. if ([LCSaveData getIMPrice] > 0 && [LCSaveModel getUserModel].youpaipuserinfo.youpaipvip == 0 && [LCSaveModel getUserModel].youpaipuserinfo.youpaipis_anchor != 1 && ![[LCSaveData getServiceIdArr] containsObject:sessionid]) {
  30. // if (![LCSaveData getPayIMNotTip]) {
  31. //
  32. //// NSString* tipStr = [NSString stringWithFormat:@"一条消息扣费%zd钻石,",[LCSaveData getIMPrice]];
  33. //
  34. // if([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender==1){
  35. // tipStr = [NSString stringWithFormat:@"%@%@",tipStr,@"成为女神即可免费私信哦!"];
  36. // }else{
  37. // tipStr = [NSString stringWithFormat:@"%@%@",tipStr,@"成为伯爵及以上贵族即可免费私信哦!"];
  38. // }
  39. // NSString *confimActionStr = @"去开通";
  40. // if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender == 1) {
  41. // confimActionStr = @"去认证";
  42. // }
  43. //
  44. // LZAlertAction *cancelAction = [LZAlertAction actionWithTitle:@"继续发送" handler:^(LZAlertAction *action) {
  45. // [LCSaveData savePayIMNotTip:YES];
  46. // [self sendIM:message sessionid:sessionid msgType:msgType content:content completion:sendBlock];
  47. // }];
  48. // cancelAction.cornerRadius = 24.0f;
  49. // cancelAction.bgColor = HexColorFromRGB(0x9F9DA5);
  50. // LZAlertAction *confimAction = [LZAlertAction actionWithTitle:confimActionStr handler:^(LZAlertAction *action) {
  51. // if ([LCSaveModel getUserModel].youpaipuserinfo.youpaipgender==1) {
  52. // YOUPAILCVerifyBigCastVC* verifyBigCast = [[YOUPAILCVerifyBigCastVC alloc]init];
  53. // [[LCTools getCurrentVC].navigationController pushViewController:verifyBigCast animated:YES];
  54. // }else{
  55. // YOUPAILZVipVC* setting = [[YOUPAILZVipVC alloc]init];
  56. // [[LCTools getCurrentVC].navigationController pushViewController:setting animated:YES];
  57. // }
  58. // }];
  59. // confimAction.cornerRadius = 24.0f;
  60. // confimAction.bgColor = [UIColor colorWithPatternImage:[LCTools ColorImage:CGSizeMake((KScreenWidth - 105.0f) / 2.0f, 48.0f) FromColors:@[ZYGradientOneColor,ZYGradientTwoColor] ByGradientType:GradientLeftToRight]];
  61. // LZAlertWindow *alert = [LZAlertWindow alertWithTitle:@"提示" content:tipStr action:@[cancelAction,confimAction]];
  62. // [[LCTools getCurrentVC] TFPresentVC:alert completion:^{}];
  63. // }
  64. // else{
  65. [self sendIM:message sessionid:sessionid msgType:msgType content:content completion:sendBlock];
  66. // }
  67. }else{
  68. [self sendIM:message sessionid:sessionid msgType:msgType content:content completion:sendBlock];
  69. }
  70. }
  71. + (void)sendIM:(NIMMessage*)message sessionid:(NSString*)sessionid msgType:(NSString *)msgType content:(NSString *)content completion:(sendMessageBlock)sendBlock{
  72. [LCHttpHelper requestWithURLString:SendIM parameters:@{@"to_uid":sessionid,@"type":msgType,@"content":content,@"msgId":message.messageId} needToken:YES type:(HttpRequestTypePost) success:^(id responseObject) {
  73. NSDictionary* dict = (NSDictionary*)responseObject;
  74. NSInteger code = [[dict objectForKey:@"code"] integerValue];
  75. if (code==0) {//成功
  76. NSDictionary* data = [dict objectForKey:@"data"];
  77. if([LCSaveModel getUserModel]){
  78. message.apnsPayload = @{@"userId":[LCSaveModel getUserModel].youpaipuserinfo.youpaipuser_id};
  79. }
  80. NIMMessageSetting* setting = [[NIMMessageSetting alloc]init];
  81. setting.apnsEnabled = YES;
  82. setting.apnsWithPrefix = NO;
  83. message.setting = setting;
  84. if (message.messageType == NIMMessageTypeText) {
  85. message.apnsContent = @"收到一条信息";
  86. }else if(message.messageType == NIMMessageTypeImage){
  87. message.apnsContent = @"收到一张图片";
  88. }else if(message.messageType == NIMMessageTypeAudio){
  89. message.apnsContent = @"收到一段语音";
  90. }else if(message.messageType == NIMMessageTypeVideo){
  91. message.apnsContent = @"收到一段小视频";
  92. }
  93. // NSInteger cut= [[data objectForKey:@"is_cut"]integerValue]; //0不扣费 1扣费
  94. // NSInteger cut_coin= [[data objectForKey:@"cut_coin"]integerValue]; //扣除的虾币数
  95. // NSInteger coin= [[data objectForKey:@"coin"]integerValue]; //剩余虾币数
  96. NSInteger filter = [[data objectForKey:@"filter"]integerValue]; //是否过滤掉
  97. if (sendBlock) {
  98. message.remoteExt = data;
  99. if (message.messageType == NIMMessageTypeText) {
  100. message.text = message.text;
  101. }
  102. //modify by leo 添加违规替代字段 只有文本消息有
  103. if (message.messageType == NIMMessageTypeText)
  104. sendBlock(message,filter,[data objectForKey:@"content"]);
  105. else
  106. sendBlock(message,filter,@"");
  107. }
  108. }
  109. } failure:^(NSError *error) {
  110. }];
  111. }
  112. - (void)sendLocalNotificationWithMessage:(NIMMessage *)message {
  113. }
  114. @end