iOS SDK 对接文档

iOS SDK 对接文档


支付

<h1>支付</h1> <p>直接使用BSSDKUI对应的类方法调用登录接口。支付界面打开后,玩家可进行的操作包括:</p> <ul> <li>微信支付</li> <li>支付宝支付 <h2>接口说明</h2> <ol> <li>调用者需要传入对应的回调函数以处理API返回的结果。</li> <li>当用户点击支付后,如是微信或支付宝支付,会跳转到目标支付应用,完成支付后,支付宝会跳回原App,而微信则需用户自行返回到原App。</li> <li>当回到原App时,API会处理支付结果,如果支付成功,则返回成果结果,如支付失败或取消,用户还会停留在支付界面,直到用户再次支付成功或关闭支付界面。</li> <li>当用户关闭支付界面,API会返回支付失败,原因是用户取消支付。 <h2>接口更新</h2> <p>新增一个同名接口,参数列表中多了角色ID的参数( roleID: String ),请调用新的接口,旧接口可用但已过时,会在将来的SDK中去掉。</p> <h2>接口定义</h2> <p>Swift</p> <pre><code>@available(3.1.5) extension BSSDKUI { @objc public static func orderAndPaid(amount: UInt, productName: String, productIAPID: String? = nil, productDesc: String, gameServer: String, roleName: String, roleID: String, serverID: String, attachment: String, success: @escaping PaymentSuccessHandler, failure: @escaping FailureHandler) }</code></pre> <p>Objective-C</p> <pre><code> @available(3.1.5) @interface BSSDKUI</code></pre></li> </ol></li> <li>(void)orderAndPaidWithAmount:(NSUInteger)amount productName:(NSString <em> _Nonnull)productName productIAPID:(NSString </em> _Nullable)productIAPID productDesc:(NSString <em> _Nonnull)productDesc gameServer:(NSString </em> _Nonnull)gameServer roleName:(NSString <em> _Nonnull)roleName roleID:(NSString </em> _Nonnull)roleID serverID:(NSString <em> _Nonnull)serverID attachment:(NSString </em> _Nonnull)attachment success:(void (^ _Nonnull)(BSSDKUIPaymentResult <em> _Nonnull))success failure:(void (^ _Nonnull)(BSSDKUIError </em> _Nonnull))failure; @end <pre><code>## 接口参数说明 | 参数名 | 类型 | 参数说明 | | --- | --- | --- | | amount |NSUInteger | 消费金额,单位为元,如支持内购,则该金额需等于内购产品金额 | | productName | String | 产品名称 | | productIAPID | String? | 产品内购ID,如使用内购需要输入在itunes connect设置的产品ID,否则为空 | | productDesc | String | 产品描述 | | gameServer | String | 区服名称 | | roleName | String | 角色名称 | | roleID | String | 角色ID | | serverID | String | 区服ID | | attachment | String | 商户扩展参数(透传参数),如CP方订单号 | | success | PaymentSuccessHandler | 支付接口的成功回调 | | failure | FailureHandler | 支付接口的失败回调 | ## 接口回调说明 ● 支付成功回调方法中参数说明: **Swift**</code></pre> <p>public typealias PaymentSuccessHandler = (BSSDKUIPaymentResult) -&gt; Void @objc public class BSSDKUIPaymentResult: NSObject { @objc public let cent: Cent @objc public let message: String }</p> <pre><code>**Objective-C**</code></pre> <p>@interface BSSDKUIPaymentResult : NSObject @property (nonatomic, readonly) NSUInteger cent; @property (nonatomic, readonly, copy) NSString * _Nonnull message; @end</p> <pre><code>回调参数说明: | 参数名 | 类型 |参数说明 | | --- | --- |--- | | cent | NSUInteger | 充值金额,单位为分 | | message | string | 成功信息 | ● 支付失败回调方法中参数说明: **Swift**</code></pre> <p>@objc public final class BSSDKUIError: NSObject, Error { @objc public let code: Int @objc public let message: String }</p> <pre><code>**Objective-C**</code></pre> <p>@interface BSSDKUIError : NSObject @property (nonatomic, readonly) NSInteger code; @property (nonatomic, readonly, copy) NSString * _Nonnull message; @end</p> <pre><code>该方法在产生业务逻辑错误时调用。 | 参数名 | 类型 |参数说明 | | --- | --- |--- | | code | string |支付失败错误码 | | msg | string |支付失败的消息提示 | ## 调用完整代码 **Swift**</code></pre> <p>BSSDKUI.orderAndPaid(amount: 100, productName: &quot;产品名称&quot;, productIAPID: &quot;产品内购ID&quot;, productDesc: &quot;产品描述&quot;, gameServer: &quot;区服001&quot;, roleName: &quot;角色名称&quot;, roleID: &quot;角色ID&quot;, serverID: &quot;区服ID&quot;, attachment: &quot;CP方订单号001&quot;, success: {print(&quot;success: ($0)&quot;)}, failure: {print(&quot;failure: ($0)&quot;)})</p> <pre><code>**Objective-C**</code></pre> <p>[BSSDKUI orderAndPaidWithAmount: 100 productName:@&quot;产品名称&quot; productIAPID:@&quot;产品内购ID&quot; productDesc:@&quot;产品描述&quot; gameServer:@&quot;区服001&quot; roleName:@&quot;角色名称&quot; roleID:@&quot;角色ID&quot; serverID:@&quot;区服ID&quot; attachment:@&quot;CP方订单号001&quot; success:^(BSSDKUIPaymentResult <em> _Nonnull success) {NSLog(@&quot;支付成功: %@&quot;, success);} failure:^(BSSDKUIError </em> _Nonnull error) {NSLog(@&quot;支付失败: %@&quot;, error);}];</p> <pre><code></code></pre></li> </ul>

页面列表

ITEM_HTML