PaySMSSDK 1.0.3

PaySMSSDK 1.0.3

许可证 MIT
发布最后发布2016年4月

DuyKienNgo 维护。



PaySMSSDK 1.0.3

  • Homedirect

其他语言: 英文

介绍

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

我们使用 Xcode 7.3 编写项目演示和 SDK。如果您使用比这更老的版本可能遇到一些错误。这就是为什么我们建议您使用最新版本(非beta)的原因。

使用项目演示开始

您需要克隆或下载此仓库到您的计算机上。

运行项目。应用程序描述了 PaySMS 的功能以及如何集成。

与 PaySMS 集成的 6 个步骤

1. 创建 MO Code

您需要做的第一件事是为 PaySMS 登记客户帐户。可以通过 Email(kythuat_paydirect)或 Skype 联系我们。拥有账户后,您可以访问 PaySMS 控制面板并将 PaySMS 集成到您的应用程序中。

2. 下载 SDK

有几种方法可以将 App360SDK 添加到 Xcode 项目。您可以使用 CocoaPods 或手动下载并将框架及相关库添加到项目中

Cocoapod (即将推出)

CocoaPods 是在 iOS 应用中快速安装和运行 PaySMS 的最佳方法。只需将以下行添加到 Podfile 中,然后运行 pod installpod update 命令。

pod 'PaySMS'

下载 PaySMS

您可以从本存储库直接下载 iOS SDK。解压 PaySMS,然后将 PaySMS 和相关框架拖入您的项目中。

3. 集成 SDK

框架 & 依赖项

PaySMS SDK 依赖于一些其他框架。您需要将这些框架添加到您的项目中。具体需要添加以下框架:

框架
SystemConfiguration.framework
CoreMobileServices.framework
CoreTelephony.framework

4. 开始编码

4.1. 导入 SDK

SDK 通过 class PaySMSSDK.h 进行导入。

#import <PaySMSSDK/PaySMSSDK.h>

4.2. 初始化 PaySMSClient

当您需要使用 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。
  • accountName 只能包含 a-z,A-Z,和 0-9 的字符。

4.3. 配置/选择电信服务代码

  • PaySMS 允许使用多种不同代码的消息,如 VTC(适用于所有 Mobilfone、Vinaphone、Viettel 网络),BX(适用于 Mobilfone 和 Vinaphone 网络),QK(适用于 Viettel 网络)。默认情况下,我们选择 VTC 作为消息服务代码。但是,您可以通过在 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;
}

4.4. 创建 SMS 语法和发送 SMS 到 9029 号码(通过 9029 号码支付)

4.1. 使用 PaySMS SDK 中提供的 UI

使用此方法,用户可以选择网络运营商(telecom)和充值(par value)金额以进行充值交易(如图所示)。

SMS Charging by UI

要进行支付,您需要:

  • 创建一个 PaySMSController。
    // 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 中描述的函数进行实现。

选择网络运营商:您需要在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:^{}];
}

4.2. 使用PaySMSClient根据网络运营商(PaySMSProvider)和面额(PaySMSParValue)自创建短信格式

    // 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。

支持

关于通用问题,请通过我们联系。

关于技术问题

如果您遇到技术问题,请通过技术团队联系。联系时,请提供以下信息,这将帮助我们更快地为您提供支持。