3分种给你的APP集成红包功能

2016-09-25  本文已影响2496人  非夜

项目介绍

这是当初给亲加通讯云做红包官方Demo时候,为他们提供的文档。

亲加红包简介

  1. 为 APP 提供了完整的收发红包以及账户体系,发红包支持支付宝和银行卡支付, 零钱可以提现。

  2. 亲加官方版Demo已默认集成红包功能,可以直接下载试用。

SDK介绍

RedpacketSDK包含:

Step1. 导入SDK

将红包库RedpacketSDK添加到工程里。

Step2. 首先注册红包Token

@description:

- (void)onLogin:(GotyeStatusCode)code user:(GotyeOCUser *)user
{
    if(code == GotyeStatusCodeOK || code == GotyeStatusCodeOfflineLoginOK || code == GotyeStatusCodeReloginOK)
    {
#ifdef REDPACKET_AVALABLE
        //TODO: 注册获取Token,传入用户ID。注意:此处获取失败,则无法使用红包功能
        [[RedPacketUserConfig sharedConfig] configWithUserId:textUsername.text];
#endif
     ...
     ...
}
    

Step3. 支持支付宝

@description:

- (void)applicationDidBecomeActive:(UIApplication *)application
{
      ...
      ...
#ifdef REDPACKET_AVALABLE
    [self redpacketApplicationDidBecomeActive:application];
#endif
}

添加支付宝回调Scheme

在info.plist文件中添加支付宝回调的URL Schemes alipayredpacket

添加支付宝App Transport Security Settings

Step4. 处理聊天界面

@description:

Step5. 处理会话界面

@description:

Step6. 零钱页

@description:

- (void)tableView:(UITableView *)tableView didSelectRowAtIndexPath:(NSIndexPath *)indexPath
{
    ...
    ...
#ifdef REDPACKET_AVALABLE
    if(indexPath.section == 0 && indexPath.row == SettingUserTypeMax)
    {
        UIViewController *controller = [RedpacketViewControl changeMoneyController];
        UINavigationController *nav = [[UINavigationController alloc] initWithRootViewController:controller];
        [self presentViewController:nav animated:YES completion:nil];
    }
#endif
    ...
    ...
}
- (NSInteger)tableView:(UITableView *)tableView
 numberOfRowsInSection:(NSInteger)section {
    ...
    ...
#ifdef REDPACKET_AVALABLE
    return SettingUserTypeMax + 1;
#endif
    return SettingUserTypeMax;
  }
    ...
    ...
}

Step7. App进入Active状态和用户退出时的对于红包SDK的操作

@description:

- (void)applicationDidBecomeActive:(UIApplication *)application {
...
#ifdef REDPACKET_AVALABLE
  [self redpacketApplicationDidBecomeActive:application];
#endif
}

- (void)onLogout:(GotyeStatusCode)code {
...
#ifdef REDPACKET_AVALABLE
    [[YZHRedpacketBridge sharedBridge] redpacketUserLoginOut];
#endif
...
#ifdef REDPACKET_AVALABLE
    [[YZHRedpacketBridge sharedBridge] redpacketUserLoginOut];
#endif
...
}

Step8. 阅读项目的忽略文件

@description:

cd ~/Desktop/gotye3.0/
cat .gitignore

*从链接:http://pan.baidu.com/s/1hrQqVnI 密码:x4pr 下载 libgotyeapi.a放入GotyeIM_Redpacket/GotyeIM/GotyeAPI/目录下编译即可。

Step9. 可能发生的错误


上一篇下一篇

猜你喜欢

热点阅读