其他语言: 英文
PaySMS 提供了最简单的将短信支付积分聚合到应用中的方法,支付给 9029 头号。
PaySMS iOS SDK 支持 iOS 6.0 及以上版本
PaySMS 版本 | 最低 iOS 目标 | 注意 |
---|---|---|
1.0.0 | 6.0 | 需要 Xcode 6.1。支持 armv7、armv7s 和 arm64 架构 (+ i386 用于模拟器) |
PaySMS iOS SDK 支持 iOS 6.0 及以上所有版本。支持 armv7、armv7s 和 arm64 架构 (+ i386 用于模拟器)。
我们使用 Xcode 7.3 编写项目演示和 SDK。如果您使用比这更老的版本可能遇到一些错误。这就是为什么我们建议您使用最新版本(非beta)的原因。
您需要克隆或下载此仓库到您的计算机上。
git clone https://github.com/homedirectvn/PaySMSSDK-iOS.git
运行项目。应用程序描述了 PaySMS 的功能以及如何集成。
您需要做的第一件事是为 PaySMS 登记客户帐户。可以通过 Email(kythuat_paydirect)或 Skype 联系我们。拥有账户后,您可以访问 PaySMS 控制面板并将 PaySMS 集成到您的应用程序中。
有几种方法可以将 App360SDK 添加到 Xcode 项目。您可以使用 CocoaPods 或手动下载并将框架及相关库添加到项目中
Cocoapod (即将推出)
CocoaPods 是在 iOS 应用中快速安装和运行 PaySMS 的最佳方法。只需将以下行添加到 Podfile 中,然后运行
pod install
或pod update
命令。pod 'PaySMS'
下载 PaySMS
您可以从本存储库直接下载 iOS SDK。解压 PaySMS,然后将 PaySMS 和相关框架拖入您的项目中。
PaySMS SDK 依赖于一些其他框架。您需要将这些框架添加到您的项目中。具体需要添加以下框架:
框架 |
---|
SystemConfiguration.framework |
CoreMobileServices.framework |
CoreTelephony.framework |
SDK 通过 class PaySMSSDK.h 进行导入。
#import <PaySMSSDK/PaySMSSDK.h>
当您需要使用 PaySMS SDK 时,您需要初始化一个 PaySMSClient。
NSString* moCode = @"YOUR_APP_MO_CODE";
NSString* accountName = @"USER_ACCOUNT_NAME_OR_ID";
paySMSClient = [[PaySMSClient alloc] initWithMOCode:moCode
accountName:accountName];
paySMSClient.dataSource = self;
应该将 accountName
设置为多少?
accountName
设置为您的系统中 user id 的值。accountName
设置为 device id。PaySMSClientDataSource
中定义的 - (NSString * _Nullable)partnerCodeForAmount: (PaySMSAmount * _Nonnull)amount
方法选择适用于您游戏应用的代码服务。- (NSString * _Nullable)partnerCodeForAmount:(PaySMSAmount * _Nonnull)amount {
// You can custom telecom service code here
// Ex: For Mobifone, there are VTC and BX codes. The default value is VTC,
// but you can choose the BX code by "return" BX value here.
if (amount.provider == kPaySMSProviderMobifone) {
return @"BX";
}
// It is also you can choose BX as partner Code for Vinaphone
else if (amount.provider == kPaySMSProviderVinaphone) {
// For BX, there is no amount with value == 100K, so,
// if the amount == 100K, and you choose "BX", it will raise the Assertion
return @"BX";
} else if (amount.provider == kPaySMSProviderViettel) {
// For BX, there is no amount with value == 100K, so,
// if the amount == 100K, and you choose "BX", it will raise the Assertion
return @"QK";
}
// When this function return null or the listener is nil/NULL,
// it will using VTC as default partner code
return nil;
}
使用此方法,用户可以选择网络运营商(telecom)和充值(par value)金额以进行充值交易(如图所示)。
要进行支付,您需要:
// the paySMSClient you already inited above
PaySMSController* paySMSController = [[PaySMSController alloc] initWithSMSClient:paySMSClient];
paySMSController.delegate = self;
// implement PaySMSControllerDelegate for custom the telecom and par value
[self presentViewController:paySMSController
animated:YES
completion:nil];
选择网络运营商:您需要在PaySMSControllerDelegate
中实现(NSArray*)supportedProviders: (PaySMSController * _Nonnull)viewController
函数来选择游戏/应用程序所支持的网络运营商。以下示例允许用户仅选择Mobilfone和Vinaphone。如果不实现此函数或在函数中返回nil/null值,则游戏/应用程序将允许用户选择所有网络运营商。
/**
* This function for developer can set the list of telecom, that the game/app supported
* This function is optional, and if the function return null or an empty array list,
* the SDK will show all Providers
*
* @param viewController The PaySMSController
*/
- (NSArray*)supportedProviders:(PaySMSController * _Nonnull)viewController {
//this is an example when you want user choose Mobilfone or Vinaphone only
NSArray* supportedProviders = @[@(kPaySMSProviderMobifone),
@(kPaySMSProviderVinaphone)];
return supportedProviders;
}
选择面额:您需要在PaySMSControllerDelegate
中实现availableFairValuesForProvider:inController:
函数来选择游戏/应用程序所支持的面额。以下示例允许用户仅选择1K、5K和100K。如果不实现此函数或在函数中返回nil/null值,则游戏/应用程序将允许用户选择所有支持的面额。
/**
* This function for developer can set the list of fair values for providers
* This function is optional, and if the function return null or an empty array list,
* the SDK still show all available fair values
*
* @param viewController The PDVoucherUseCardViewController its delegate of fail
* @param result The selected (and possibly newly created) tokenized payment information.
*/
- (NSArray*)availableFairValuesForProvider:(PaySMSProvider)provider
inController:(PaySMSController * _Nonnull)viewController {
// This is the way you want user to pick some par values only
// An example with Viettel
if (provider == kPaySMSProviderViettel) {
return @[@(kPaySMSParValue1K),
@(kPaySMSParValue5K),
@(kPaySMSParValue10K)];
}
}
用户取消支付事件
/**
* Informs the delegate when the user has decided to cancel out of the Pay by SMS form.
*
* @param viewController The PaySMSController view controller informing its delegate of failure or cancelation.
*/
- (void)userDidCancel:(PaySMSController * _Nonnull)viewController {
// By simple way, you just need to dissmis the PaySMSController
[viewController dismissViewControllerAnimated:YES
completion:nil];
}
SMS发送成功事件
/**
* Informs the delegate when the sms did send
*
* @param viewController The PaySMSController view controller informing its delegate of failure or cancelation.
*/
- (void)smsDidSend:(PaySMSController * _Nonnull)viewController {
// Thanks for user and check your server side to be sure your got money from user
[self.alert cancelAlertWithTitle:nil
message:NSLocalizedString(@"The SMS did sent", @"The SMS did sent")
cancelTitle:NSLocalizedString(@"OK", @"OK")
cancelHandler:^{}];
}
SMS发送失败事件
/**
* Informs the delegate when the sms failed
*
* @param viewController The PaySMSController view controller informing its delegate of failure.
*/
- (void)smsFailed:(PaySMSController * _Nonnull)viewController {
[self.alert cancelAlertWithTitle:nil
message:NSLocalizedString(@"Can not send SMS", @"Can not send SMS")
cancelTitle:NSLocalizedString(@"OK", @"OK")
cancelHandler:^{}];
}
// Init an amount to charge by PaySMS
PaySMSAmount* amount = [[PaySMSAmount alloc] init];
// Set your telecom: Mobilfone/Vinaphone or Viettel. It should be the user's telecom.
amount.provider = kPaySMSProviderMobifone;
// The par value to charge by PaySMS: 1K, 2K, 3K, 4K, 5K, 10K, 15K, 20K, 30K, 40K, 50K, 100K
amount.parValue = kPaySMSParValue1K;
// Generate the SMS Syntax
NSString* smsSyntax = [paySMSClient smsSyntax:amount];
// In case the par value is not supported by telecom, the smsSyntax returned will be nil
if (smsSyntax) {
// It is an example for you can use 'smsSyntax', Alert to user
NSString * message = [NSString stringWithFormat:NSLocalizedString(@"The syntax is: %@. Do you want to send to the provider?", @"The syntax is: \"%@\". Do you want to send to the provider?"),smsSyntax];
[self.alert alertWithTitle:nil
message:message
titles:@[NSLocalizedString(@"Yes", @"Yes"),
NSLocalizedString(@"Cancel", @"Cancel")]
handlers:@[^{
// And send SMS by using MFMessageComposeViewController
if ([MFMessageComposeViewController canSendText]) {
MFMessageComposeViewController *messageController = [[MFMessageComposeViewController alloc] init];
messageController.messageComposeDelegate = self;
[messageController setRecipients:@[@"9029"]];
[messageController setBody:smsSyntax];
[self presentViewController:messageController
animated:YES
completion:nil];
}
}, ^ {
}]];
}
恭喜。您已成功集成PaySMS。
关于通用问题,请通过我们联系。
如果您遇到技术问题,请通过技术团队联系。联系时,请提供以下信息,这将帮助我们更快地为您提供支持。