項(xiàng)目介紹
這是當(dāng)初給親加通訊云做紅包官方Demo時候,為他們提供的文檔。
親加紅包簡介
為 APP 提供了完整的收發(fā)紅包以及賬戶體系,發(fā)紅包支持支付寶和銀行卡支付, 零錢可以提現(xiàn)。
親加官方版Demo已默認(rèn)集成紅包功能,可以直接下載試用。
SDK介紹
RedpacketSDK包含:
RedpacketStaticLib靜態(tài)庫提供,實(shí)現(xiàn)了紅包收發(fā)流程和賬號安全體系。RedpacketOpen開源方式提供,實(shí)現(xiàn)了紅包消息的展示AliPay支付寶SDK
Step1. 導(dǎo)入SDK
將紅包庫RedpacketSDK添加到工程里。
Step2. 首先注冊紅包Token
@description:
- 在
GotyeLoginController.mm中
- (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:
- 在
GotyeAppDelegate.mm引入GotyeAppDelegate+Redpacket.h - 涉及到的方法
- (void)applicationDidBecomeActive:(UIApplication *)application
{
...
...
#ifdef REDPACKET_AVALABLE
[self redpacketApplicationDidBecomeActive:application];
#endif
}
添加支付寶回調(diào)Scheme
在info.plist文件中添加支付寶回調(diào)的URL Schemes alipayredpacket
- 選中要編譯的項(xiàng)目,在右側(cè)的窗口中選擇Targets中的某個target, 右側(cè)Bulid Setting旁邊有一個info選項(xiàng),打開后最下邊有一個URLTypes,點(diǎn)擊加號添加一個URLType, URL schemes 設(shè)為
alipayredpacket即可。
添加支付寶App Transport Security Settings
Step4. 處理聊天界面
@description:
- 替代ChatViewController為RedPacketChatViewController(帶有紅包功能的聊天窗口) ,建議全局搜索并替換,以免遺漏
Step5. 處理會話界面
@description:
- 替代GotyeMessageViewController為RedPacketMessageViewController(帶有紅包功能的聊天窗口) ,建議全局搜索并替換,以免遺漏
Step6. 零錢頁
@description:
'親加紅包版'的零錢頁放在了
GotyeSettingViewController頁面里。通過
[RedpacketViewControl changeMoneyController]獲取零錢頁。涉及到的方法
- (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進(jìn)入Active狀態(tài)和用戶退出時的對于紅包SDK的操作
@description:
- App進(jìn)入Active狀態(tài)涉及的方法:
- (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. 閱讀項(xiàng)目的忽略文件
@description:
- cd到工程目錄下面
cd ~/Desktop/gotye3.0/
cat .gitignore
*從鏈接:http://pan.baidu.com/s/1hrQqVnI 密碼:x4pr 下載 libgotyeapi.a放入GotyeIM_Redpacket/GotyeIM/GotyeAPI/目錄下編譯即可。
Step9. 可能發(fā)生的錯誤
RedPacketMessageViewController報(bào)編譯錯誤,注意此處需在RedPacketMessageViewController.m中引入GotyeMessageViewController.h此處主要為了引入GotyeMessageCell,因?yàn)橛H加通訊云將GotyeMessageCell寫入了GotyeMessageViewController.h內(nèi)某些方法找不到,請檢查BulidSetting中 OtherLinkFlag的標(biāo)記是否設(shè)置正確,如果缺省,還需添加
-Objc缺少類庫,支付寶需要添加的類庫 支付寶類庫
HTTP鏈接錯誤, App Transport Security Settings 是否配置了支付寶相關(guān)參數(shù), 參考支付寶文檔
缺少參數(shù),如果每個接口都報(bào)缺少參數(shù),則是Token沒有獲取到,請檢查
YZHRedpacketBridge中紅包注冊的方法是否實(shí)現(xiàn),或者是否傳入了正確的參數(shù)。 如果是發(fā)紅包頁面報(bào)缺少參數(shù),請檢查YZHRedpacketBridge中的dataSource是否實(shí)現(xiàn)
- 其它,此方案為親加官方Demo的集成方案,并不完全實(shí)用所有情況,如有不適,還望變通實(shí)現(xiàn)。