其他语言:英文
PayDirectSMSCharging 提供将 sms 支付集成到您的应用程序中,通过 9029 号码的最简单方式。
PaySMSCharging iOS SDK 支持 iOS 6.0 及以上版本
PaySMS 版本 | 最低 iOS 目标版本 | 注意 |
---|---|---|
1.0.0 | 6.0 | 需要 Xcode 6.1。支持 armv7, armv7s 和 arm64 架构(+ i386 用于模拟器) |
PayDirectSMSCharging iOS SDK 支持所有 iOS 6.0 及以上版本。支持 armv7, armv7s 和 arm64 架构(+ i386 用于模拟器)。
我们使用 Xcode 7.3 编写项目示例和 SDK。如果使用旧版本 Xcode 打开可能会遇到一些错误。这就是我们建议您使用最新版(non-beta)的原因。
您需要将此仓库克隆或下载到您的计算机上。
git clone https://github.com/homedirectvn/PayDirectSMSCharging-iOS.git
运行项目。应用程序描述了 PaySMS 的功能和集成方式。
您需要做的第一件事是为 PaySMSCharging 注册客户账户。请通过 Email 或 Skype (kythuat_paydirect) 联系。在创建账户后,您可以访问 PayDirectSMSCharging 控制台,并将 PayDirectSMSCharging 集成到您的应用程序中。
将PayDirectSMSCharging加载到项目Xcode的方式有很多。您可以使用CocoaPod或手动下载并添加框架和相关库到项目中。
Cocoapod(即将推出)
CocoaPod是最快的方法来在iOS应用上加载和运行PayDirectSMSCharging。只需在Podfile中添加以下行,然后运行
pod install
或pod update
命令。pod 'PayDirectSMSCharging'
加载PayDirectSMSCharging
您可以直接从repo下载iOS SDK。解压缩PayDirectSMSCharging,然后将PayDirectSMSCharging及其框架拖入您的项目。
PayDirectSMSCharging SDK依赖于一些其他框架。您需要将它们添加到自己的项目中。具体需要添加以下框架
Framework |
---|
SystemConfiguration.framework |
CoreMobileServices.framework |
CoreTelephony.framework |
SDK通过PayDirectSMSCharging.h类进行导入。
#import <PayDirectSMSCharging/PayDirectSMSCharging.h>
当您需要使用PaySMS SDK时,您需要初始化一个PDSMSChargingClient。
NSString* moCode = @"YOUR_APP_MO_CODE";
NSString* accountName = @"USER_ACCOUNT_NAME_OR_ID";
paySMSChargingClient = [[PDSMSChargingClient alloc] initWithMOCode:moCode
accountName:accountName];
paySMSChargingClient.dataSource = self;
应如何设置accountName
的值?
accountName
的值应与您的系统中用户ID相同。accountName
的值应与设备ID对应。PDSMSChargingClientDataSource
中定义的- (NSString * _Nullable)partnerCodeForAmount: (PDSMSAmount * _Nonnull)amount
方法选择适用于您的游戏/应用的代码。- (NSString * _Nullable)partnerCodeForAmount:(PDSMSAmount * _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 QK , BX as default for Viettel and Vinaphone/Mobifone partner code
return nil;
}
使用这种方法,用户可以选择运营商和充值面值(如图所示)进行充值交易。
要进行支付,您需要
// the paySMSChargingClient you already inited above
PaySMSController* paySMSController = [[PaySMSController alloc] initWithSMSClient:paySMSChargingClient];
paySMSController.delegate = self;
// implement PaySMSControllerDelegate for custom the telecom and par value
[self presentViewController:paySMSController
animated:YES
completion:nil];
选择运营商:您需要实现一个名为 (NSArray*)supportedProviders: (PaySMSController * _Nonnull)viewController
的函数,它在 PaySMSControllerDelegate
中被描述,以便选择游戏/应用程序支持的运营商。以下示例允许用户只选择 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;
}
选择面额:您需要实现一个名为 availableFairValuesForProvider:inController:
的函数,它在 PDSMSChargingControllerDelegate
中被描述,以便选择游戏/应用程序支持的面额。以下示例允许用户只选择 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:(PDSMSProvider)provider
inController:(PDSMSChargingController * _Nonnull)viewController {
// This is the way you want user to pick some par values only
// An example with Viettel
if (provider == kPDSMSProviderViettel) {
return @[@(kPDSMSParValue1K),
@(kPDSMSParValue5K),
@(kPDSMSParValue10K)];
}
// return nil/NULL/Empty array, the SDK will allows user to choose all par values
return nil;
}
用户取消支付事件
/**
* 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:(PDSMSChargingController * _Nonnull)viewController {
[viewController dismissViewControllerAnimated:YES
completion:nil];
// [viewController dismissViewControllerAnimated:YES
// completion:^{
// [self.alert cancelAlertWithTitle:nil
// message:NSLocalizedString(@"User did cancel", @"User did cancel")
// cancelTitle:NSLocalizedString(@"OK", @"OK")
// cancelHandler:^{
// }];
// }];
}
成功发送 SMS 事件
/**
* Informs the delegate when the SMS did send
*
* @param viewController The PaySMSController view controller informing its delegate of failure or cancelation.
*/
- (void)smsDidSend:(PDSMSChargingController * _Nonnull)viewController {
[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:(PDSMSChargingController * _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 = [paySMSChargingClient 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];
}
}, ^ {
}]];
}
恭喜您,您已成功集成 PayDirectSMSCharging
请就一般性问题与我们联系:这里
如果您有技术问题,请与我们的技术团队联系:这里 联系时,请提供以下信息,这将帮助我们更快地支持您。