差别

这里会显示出您选择的修订版和当前版本之间的差别。

到此差别页面的链接

两侧同时换到之前的修订记录 前一修订版
后一修订版
前一修订版
后一修订版 两侧同时换到之后的修订记录
start:300iosclientintegration:300iosredpacket [2016/05/18 11:21]
zilong.li
start:300iosclientintegration:300iosredpacket [2016/08/30 07:20]
liulij
行 1: 行 1:
 +====== 环信红包接入文档(iOS) =======
  
-====== 环信红包接入文档 ======+------
  
----- +新开商户可免费发送累计5000元总额的红包,超过5000元后,红包功能自动关闭,直到商付费购买增值服务“红包功能”后,该功能重新开启,购买增值服务请咨询环信商务经理
-===== 环信红包简介(此文档只针对非Demo版本的集成说明仅做参考)===== +
-1. 为 APP 提供了完整的收发红包以及账体系+
  
-2. 环信官方''​SDK2.2.5 ChatDemoUI3.0''​版Demo已默认集成红包功能,可以直接下载试用。+===== 环信红包简介 =====
  
-3通过.pch文件中宏定义''​REDPACKET_AVALABLE''​开启或者关闭红包功能。+1为 APP 提供了完整收发红包以及账户体系,发红包支持支付宝和银行卡支付, 零钱可以提现。 
 + 
 +2. 环信官方''​SDK2.2.5 ChatDemoUI3.0''​版Demo已默认集成红包功能,可以直接下载试用
  
 ===== SDK介绍 ===== ===== SDK介绍 =====
-''​RedpacketSDK''​包含 ​''​RedpacketStaticLib''​ 和 ''​RedpacketOpen''​ +''​RedpacketSDK''​包含:  
-''​RedpacketStaticLib''​静态库提供,实现了红包收发流程和账号安全体系。  + 
-''​RedpacketOpen''​开源方式提供,实现了红包消息的展示+''​RedpacketStaticLib''​静态库提供,实现了红包收发流程和账号安全体系。  
 + 
 +''​RedpacketOpen''​开源方式提供,实现了红包消息的展示 
 + 
 +* ''​AliPay''​ 支付宝SDK
  
  
-==== Step1. 导入SDK ====+===== Step1. 导入SDK ​=====
  ​将红包库''​RedpacketSDK''​添加到工程里。  ​将红包库''​RedpacketSDK''​添加到工程里。
  
-==== Step2. 配置商户ID ==== +===== Step2. 配置商户ID =====
-**@Class:** //​AppDelegate//​+
  
-**@Function:** //- (BOOL)application:​(UIApplication *)application didFinishLaunchingWithOptions:​(NSDictionary *)launchOptions;//​+**@description:** 
  
-**@description:​** appKey为环信分配的appKey+* appKey为环信分配的appKey,​格式为''​****#​****''​
  
 <code objc> <code objc>
行 38: 行 42:
 </​code>​ </​code>​
  
-==== Step3.公开协议 ​====+===== Step3. ​替换聊天窗口 ===== 
 +**@description:​** ​
  
-**@class:** //ChatViewController//+替代''​ChatViewController''​为''​RedPacketChatViewController(带有红包功能的聊天窗口)''​
  
-**@description:​** 开放协议,将''​ChatViewController.m''​中的协议''<​EaseMessageViewControllerDelegate,​ EaseMessageViewControllerDataSource>''​,公开到''​ChatViewController.h''​中+===== Step4零钱页 =====
  
-<code objc> +**@description:**
-//​ 修改后.h文件 +
-@interface ChatViewController ​EaseMessageViewController <​EaseMessageViewControllerDelegate,​ EaseMessageViewControllerDataSource>​+
  
-</​code>​+* ''​ChatDemoUI3.0''​的零钱页放在了''​SettingsViewController''​页面里。
  
-==== Step4.替换聊天窗口ChatViewController ==== +通过''​[RedpacketViewControl changeMoneyController]''​获取零钱页。
-**@OriginClass:​** //​ChatViewController//​+
  
-**@ReplaceClass:​** //​RedPacketChatViewController//​ +===== Step5. ​支持支付宝 =====
- +
-**@description:​** 替代//​ChatViewController//​为//​RedPacketChatViewController(带有红包功能的聊天窗口)//​ +
- +
- +
-==== Step5.检查红包按钮索引 ​==== +
-**@Class:** //​RedPacketChatViewController//​ +
- +
-**@description:​** 不同的App,聊天界面中更多功能列表页里的功能按钮数量可能不同,对应的位置也可能不同,所以要保证索引值正确。 +
- +
-**@Function:​**  +
- +
-//- (void)messageViewController:​(EaseMessageViewController *)viewController didSelectMoreView:​(EaseChatBarMoreView *)moreView AtIndex:​(NSInteger)index//​+
  
 +=== 支付宝回调处理 ===
 <code objc> <code objc>
-/** + #ifdef REDPACKET_AVALABLE 
- ​* ​ 红包单击事件索引 + #pragma mark - Alipay
- */ +
-static NSInteger const _redpacket_send_index ​  = 5;+
  
-</​code>​ +- (void)applicationDidBecomeActive:(UIApplication ​*)application
- +
-==== Step6.群红包消息透传 ==== +
-**@Class:** //​MainViewController//​ +
-**@description:​** 群红包被抢,抢红包的人和发红包的人,都要收到你抢了***的红包或者***的抢了你的红包, 抢红包消息是通过cmd消息实现,在这里需要将cmd消息处理成txt消息。 +
- +
-**@Function:​** \\ +
-//​-(void)didReceiveCmdMessage:​(EMMessage *)message//​\\ +
-//​-(void)didReceiveOfflineCmdMessages:​(NSArray *)offlineCmdMessages//​\\ +
-//​-(void)didReceiveMessage:​(EMMessage *)message//​ +
- +
-<code objc> +
-//​ 复制以下代码到MainViewController中,替换原有的方法。 +
- +
-/** +
- ​* ​ TODO: [Step6] RedpacketSDK +
- */ +
-  +
-- (void)didReceiveOfflineCmdMessages:(NSArray ​*)offlineCmdMessages+
 { {
-    ​/** +    [[NSNotificationCenter defaultCenterpostNotificationName:RedpacketAlipayNotifaction object:nil];
-     ​* ​ 收到红包被抢的 +
-     */ +
-    for (EMMessage *message in offlineCmdMessages) { +
-        EMCommandMessageBody * body = (EMCommandMessageBody *)message.messageBodies[0]+
-        if ([body.action isEqualToString:RedpacketKeyRedapcketCmd]) { +
-            [self handleCmdMessage:message]; +
-        } +
-    }+
 } }
  
--(void)didReceiveCmdMessage:(EMMessage ​*)message +// NOTE: iOS9.0之前使用的API接口 
-+- (BOOL)application:(UIApplication ​*)application 
-    // 群红包透传处理 +            ​openURL:​(NSURL ​*)url 
-    EMCommandMessageBody ​body = (EMCommandMessageBody ​*)message.messageBodies[0];​+  sourceApplication:​(NSString ​*)sourceApplication 
 +         ​annotation:​(id)annotation {
     ​     ​
-    if ([body.action ​isEqualToString:​RedpacketKeyRedapcketCmd]) +    if ([url.host isEqualToString:​@"​safepay"​]) { 
-        [self handleCmdMessage:​message];​ +        //跳转支付宝钱包进行支付,处理支付结果 
-         +        [[AlipaySDK defaultService] processOrderWithPaymentResult:​url standbyCallback:^(NSDictionary *resultDic
-    }else+            [[NSNotificationCenter defaultCenter] postNotificationName:​RedpacketAlipayNotifaction object:​resultDic];​ 
-        //环信原调用 +        }];
-        [self showHint:NSLocalizedString(@"​receiveCmd",​ @"​receive cmd message"​)];+
     }     }
 +    return YES;
 } }
  
-- (void)handleCmdMessage:(EMMessage ​*)message+// NOTE: iOS9.0以后使用新API接口 
 +- (BOOL)application:(UIApplication *)app 
 +            openURL:​(NSURL *)url 
 +            options:​(NSDictionary<​NSString*,​ id> ​*)options
 { {
-    ​NSDictionary *dict = message.ext;​ +    if ([url.host ​isEqualToString:​@"​safepay"​]) { 
-    NSString *senderID = [dict valueForKey:​RedpacketKeyRedpacketSenderId];​ +        //跳转支付宝钱进行支付,处理支付结果 
-    NSString *receiverID = [dict valueForKey:​RedpacketKeyRedpacketReceiverId];​ +        [[AlipaySDK defaultServiceprocessOrderWithPaymentResult:​url standbyCallback:^(NSDictionary ​*resultDic) { 
-    NSString *currentUserID = [[[[EaseMob sharedInstance] chatManager] loginInfo] objectForKey:​kSDKUsername];​ +            [[NSNotificationCenter defaultCenterpostNotificationName:RedpacketAlipayNotifaction object:resultDic]; 
-     +        ​}];
-    ​if ([senderID ​isEqualToString:​currentUserID]){ +
-        /** +
-         ​* ​ 当前用户是红包发送者。 +
-         */ +
-        NSString *text = [NSString stringWithFormat:​@"​%@领取了你的红",​receiverID];​ +
-        ​NSString *willSendText = [EaseConvertToCommonEmoticonsHelper convertToCommonEmoticons:​text];​ +
-        EMChatText *textChat = [[EMChatText allocinitWithText:willSendText];​ +
-        EMTextMessageBody ​*body1 = [[EMTextMessageBody alloc] initWithChatObject:​textChat];​ +
-        ​EMMessage *SelfMessage = [[EMMessage allocinitWithReceiver:message.conversationChatter bodies:[NSArray arrayWithObject:​body1]]; +
-        ​SelfMessage.requireEncryption = NO; +
-        SelfMessage.messageType = eMessageTypeGroupChat;​ +
-        SelfMessage.ext = message.ext;​ +
-        SelfMessage.deliveryState = eMessageDeliveryState_Delivered;​ +
-        SelfMessage.isRead = YES; +
-         +
-        /** +
-         ​* ​ 插入数据库,并更新当前聊天界面 +
-         */ +
-        [[EaseMob sharedInstance].chatManager insertMessageToDB:​SelfMessage append2Chat:​YES];+
     }     }
 +    return YES;
 } }
 +
 + #​endif
 + 
 </​code>​ </​code>​
  
-<code objc>+=== 添加支付宝回调Scheme ===  
 +在info.plist文件中添加支付宝回调的URL Schemes ''​alipayredpacket''​
  
-/*+选中要编译项目在右侧的窗口中选择Targets中的某个target,​ 右侧Bulid Setting旁边有一个info选项,打开后最下边有一个URLTypes,点击加号添加一个URLType, URL schemes 设为 ''​alipayredpacket''​ 即可。
- ​* ​ TODO: [Step6]: 屏蔽震动消息 +
- */ +
-  +
--(void)didReceiveMessage:​(EMMessage *)message +
-+
-    NSDictionary *dict = message.ext;​ +
-    /** +
-     ​* ​ 红包被抢消息不提示不震动 +
-     */ +
-    if (dict && [dict valueForKey:​RedpacketKeyRedpacketTakenMessageSign]) { +
-        return; +
-    } +
-     +
- ... +
- ... +
-  +
-}+
  
-</code>+=== 添加支付宝App Transport Security Settings === 
 + 
 +* [支付宝官方集成文档](https:​//​doc.open.alipay.com/​doc2/​detail?​treeId=59&​articleId=103676&​docType=1)
  
-==== Step7.会话列表页 ==== 
  
-**@Class:** //​MainViewController//​ 
  
-**@description:​** 修改会话列表页,当某人抢了红包后显示正确提示信息,​ 直接复制到以下代码到具体位置+===== Step6. 可能发生错误 =====
  
-**@Function:​** //- (NSString *)commonLatestMessageTitle:​(EMMessage *)latestMessage//​+RedpacketChatViewController报错,请查看RedpacketChatViewController是否引用了基类的私有方法,或者私有继承的协议,请将这些协议更开到.h文件中。
  
 <code objc> <code objc>
-\#pragma mark - 阅后即焚或普通消息内容显示 +//​ 涉及到的协议 
-- (NSString *)commonLatestMessageTitle:​(EMMessage *)latestMessage + 
-{ +EaseMessageViewControllerDelegate 
-    ​NSString *latestMessageTitle = @"";​ + 
-    if (latestMessage.ext && +EaseMessageViewControllerDataSource 
-        ​[EaseMessageHelper isRemoveAfterReadMessage:​latestMessage] && + 
-        ​[latestMessage.to isEqualToString:​[[EaseMob sharedInstance].chatManager loginInfo][kSDKUsername]]) +EaseMessageCellDelegate 
-    { + 
-        ​latestMessageTitle = NSLocalizedString(@"​message.burn",​ @"​[Burn after reading]"​);​ +// 涉及到的方法 
-        return latestMessageTitle;​ + 
-    } +(void)sendTextMessage:​(NSString *)text withExt:(NSDictionary*)ext; 
-    id<​IEMMessageBody>​ messageBody = latestMessage.messageBodies.lastObject;​ + 
-     +(void)showMenuViewController:(UIView ​*)showInView 
-    ​//  ​TODO:​Step7. 开始位置 +                   andIndexPath:(NSIndexPath ​*)indexPath 
-    ​if ​(messageBody.messageBodyType == eMessageBodyType_Text+                    ​messageType:(EMMessageBodyType)messageType
-        ​NSDictionary *dict = latestMessage.ext; + 
-         +(BOOL)shouldSendHasReadAckForMessage:​(EMMessage ​*)message 
-      ​if ​([dict valueForKey:​RedpacketKeyRedpacketTakenMessageSign]+                                  read:(BOOL)read;
-            /** +
-             ​* ​ 红包被抢的消息 +
-             */ +
-            NSString *senderID = [dict valueForKey:RedpacketKeyRedpacketSenderId];​ +
-            NSString ​*currentUserID = [[[[EaseMob sharedInstance] chatManager] loginInfo] objectForKey:​kSDKUsername];​ +
-            if ([senderID isEqualToString:​currentUserID]{ +
-                /** +
-                 ​* ​ 发送红包的用户就是当前用户 +
-                 */ +
-                NSString *receiver = [dict valueForKey:RedpacketKeyRedpacketReceiverNickname];​ +
-                NSString ​*receiverID = [dict valueForKey:​RedpacketKeyRedpacketReceiverId];​ +
-                NSString *prompt; +
-                 +
-                if ([senderID isEqualToString:​receiverID]{ +
-                    ​/** +
-                     ​* ​ 自己抢了自己的红包 +
-                     */ +
-                    prompt = @"​你领取了自己的红包";​ +
-                }else { +
-                    /** +
-                     ​* ​ 别人领取了当前用户的红包 +
-                     */ +
-                    prompt = [NSString stringWithFormat:@"​%@领取了你的红包",​ receiver];+
-                } +
-                 +
-                ​((EMTextMessageBody ​*)messageBody).text = prompt; +
-            } +
-        } +
-    } +
-     +
-    //  END: Redpacket Modify +
-    ... +
-    ... +
-}+
  
 </​code>​ </​code>​
  
-==== Step8.零钱页 ====+* 某些方法找不到,请检查BulidSetting中 OtherLinkFlag的标记是否设置正确,如果缺省,还需添加''​-Objc''​
  
-**@Class:** //​SettingsViewController//​+发红包按钮点击没反应,请查看''​RedpacketChatViewController''​中''​static NSInteger const _redpacket_send_index ​  = 5;''​ 值是否正确
  
-**@description:​** +缺少类库,支付宝需要添加类库 ​[支付宝类库](https://​doc.open.alipay.com/​doc2/​detail?​treeId=59&​articleId=103676&​docType=1)
-''​ChatDemoUI3.0''​零钱页放在了''​SettingsViewController''​页面里。 通过''​[RedpacketViewControl changeMoneyController]''​获取零钱页。+
  
 +* 缺少参数,如果每个接口都报缺少参数,则是Token没有获取到,请检查''​YZHRedpacketBridge''​中红包注册的方法是否实现,或者是否传入了正确的参数。 如果是发红包页面报缺少参数,请检查''​YZHRedpacketBridge''​中的dataSource是否实现
  
 +* HTTP链接错误, App Transport Security Settings 是否配置了支付宝相关参数, 参考支付宝文档
  
-==== Step9.快喊老板来发红包了 ====+* 其它,此方案为环信官方Demo的集成方案,并不完全实用所有情况,如有不适,还望变通实现。
  
  
-==== 更多 ==== +---- 
-  * 环信红包是基于''​环信 SDK2.2.5 ChatDemoUI3.0''​开发的,以上介绍也是基于''​环信 SDK2.2.5 ChatDemoUI3.0''​,如果您的APP不依赖于环信''​ChatDemoUI3.0''​的''​ChatViewController''​,或者不依赖于''​EaseUI''​,可以参考以步骤自行现红包功能。 +<WRAP group> 
-  * 红包的零钱页放在了''​ChatDemoUI3.0''​中的设置页面。 +<WRAP half column> 
-  * 宏定义开启关闭红包功能。 关闭红包功能只需在pch文件中注释掉此宏定义。 +一页:[[start:​300iosclientintegration:​100rtaudio|时通话]] 
-<code objc+</​WRAP>​ 
- #define REDPACKET_AVALABLE + 
-</code>+<WRAP half column
 +下一页:[[start:​300iosclientintegration:​80apns|APNS离线推送]] 
 +</WRAP> 
 +</​WRAP>​