天天看點

iOS支付配置 ping++

發個廣告:ios開發兩年了,一步步走來  關注公衆号一起進步

iOS支付配置 ping++

ping++文章總結

應用在接入 Ping++ SDK 時,需要使用以下三個參數,這三個參數你可以在管理平台中擷取:

API Key:API Key 是 Ping++ 配置設定給你的唯一身份辨別。在 Server SDK 的使用過程中需要配置該參數。注冊 Ping++ 賬号并通過稽核後,Ping++ 會配置設定給你兩個 API Key,分别為:test key和live key。這倆 分别表明使用測試模式和真實模式,你可以根據實際應用使用場景分别使用。

應用 ID:應用 ID 是 Ping++ 配置設定給你的應用的唯一辨別。在 Server SDK 的使用過程中需要配置該參數。

Notify URL:Notify URL 是 Ping++ 系統用來向你的應用背景推送異步通知時使用的位址,該位址必須是一個網際網路可以通路的位址。你可以在 Ping++ 管理平台中對應的應用内進行設定。

一、接入步驟:

擷取 SDK

從 Github 下載下傳 SDK, 裡面包含了 lib 檔案夾和 example 檔案夾。lib 檔案夾裡面是 SDK 的檔案,example 檔案夾裡是接入示例代碼 

cocoapods 在profile中加入  pod 'Pingpp'

依賴 Frameworks:

           必需:

    1.            百度錢包所需:

    1. Client 發送支付要素給 Server

    使用者選擇管道點選交易按鈕, Client 收集交易所需的相關參數傳遞給 Server (伺服器的位址為代碼中的 URL)。
    NSDictionary* dict = @{    @"channel" : channel, // 管道 alipay, wx, upacp, bfb
        @"amount"  : amount   // 金額};NSData* data = [NSJSONSerialization dataWithJSONObject:dict options:NSJSONWritingPrettyPrinted error:nil];NSString *bodyData = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];
    [postRequest setHTTPBody:[NSData dataWithBytes:[bodyData UTF8String] length:strlen([bodyData UTF8String])]];
    [postRequest setHTTPMethod:@"POST"];
    [postRequest setValue:@"application/json; charset=utf-8" forHTTPHeaderField:@"Content-Type"];
    NSOperationQueue *queue = [[NSOperationQueue alloc] init];
    [NSURLConnection sendAsynchronousRequest:postRequest queue:queue completionHandler:^(NSURLResponse *response, NSData *data, NSError *connectionError) {
        NSHTTPURLResponse* httpResponse = (NSHTTPURLResponse*)response;    NSString* charge = [[NSString alloc] initWithData:data encoding:NSUTF8StringEncoding];    // ...}];
               

    2. Server 發送支付請求并将傳回的支付憑據傳給 Client

    Server 接收并處理 Client 傳過來的資料,使用 Ping++ 提供的方法向 Ping++ 發起交易,并将從 Ping++ 獲得的帶支付憑據的 Charge 對象傳回給 Client。
    <?php//引用 SDK 庫檔案require_once('/path/to/Pingpp.php');//擷取用戶端的參數,這裡不能使用 $_POST 接收,是以我們提供了如下的參考方法接收$input_data = json_decode(file_get_contents("php://input"), true);//TODO 客戶在這裡自行處理接收過來的交易所需的資料//設定API KEY,如果是測試模式,這裡填入 Test Key;如果是真實模式, 這裡填入 Live Key。Pingpp::setApiKey("YOUR-KEY");//建立支付對象,發起交易$ch = Pingpp_Charge::create(    //array 裡需要哪些參數請閱讀 API Reference 文檔
        array(        "order_no"  => $orderNo,  //商戶系統自己生成的訂單号
            "app"       => array("id" => "YOUR-APP-ID"),  //Ping++ 配置設定給商戶的應用 ID
            "amount"    => $amount,  //交易金額
            "channel"   => $channel,  //交易管道
            "currency"  => "cny",        "client_ip" => $_SERVER["REMOTE_ADDR"],  //發起交易的用戶端的 IP
            "subject"   => "Your Subject",        "body"      => "Your Body",        "extra"     => null //僅用戶端為 HTML5 時此參數不為空,具體請參考 API Reference 文檔
        )
    );echo $ch;                

    3. Client 調起支付控件完成支付

    Client 接收 Server 傳回的帶支付憑據的 Charge 對象并用之調起支付插件完成交易
    [Pingpp createPayment:charge viewController:viewController appURLScheme:kUrlScheme withCompletion:^(NSString *result, PingppError *error) {    if ([result isEqualToString:@"success"]) {        // ...
        } else {        NSLog(@"PingppError: code=%lu msg=%@", error.code, [error getMsg]);
        }
    }];
               

    4. 管道同步傳回支付結果給 Client

    在上一步中使用者完成了支付,管道會傳回一個支付結果給用戶端,這裡 Client 需要做的是處理此結果。

    管道為銀聯、百度錢包或者管道為支付寶但未安裝支付寶錢包時,交易結果會在調起插件時的 Completion 中傳回。 管道為微信、支付寶且安裝了支付寶錢包時,請實作 

    UIApplicationDelegate

     的 

    - application:openURL:sourceApplication:annotation:

     方法:
     - (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
        [Pingpp handleOpenURL:url withCompletion:^(NSString *result, PingppError *error) {        if ([result isEqualToString:@"success"]) {            // ...
            } else {            NSLog(@"PingppError: code=%lu msg=%@", error.code, [error getMsg]);
            }
        }];    return  YES;
    }
               

    5. Server 收到 Ping++ 發送的交易結果的異步通知

    Ping++ 會把從管道收到的異步通知告訴商戶 Server,客戶 Server 接收到異步通知是一個帶支付狀态的完整的 Charge 對象,客戶在接收到異步通知後需要回複 success 給 Ping++ 表明成功收到異步通知。所有的交易結果,商戶均須以異步通知結果為準。關于異步通知具體請參見 API Reference 文檔。
    <?php$input_data = json_decode(file_get_contents("php://input"), true);if($input_data['object'] == 'charge') {    //TODO update database
        echo 'success';
    } else {    echo 'fail';
    }                
  1. 用到微信 的話 需要用到這樣的配置
  2. iOS支付配置 ping++
  3. iOS支付配置 ping++

    添加網絡通路權限及白名單

    添加URL Type