【问题标题】:How to implement server to server callback for rapidoreach SDKs?如何为 rapidoreach SDK 实现服务器到服务器的回调?
【发布时间】:2021-09-08 12:43:08
【问题描述】:

我已成功将 rapidoreach ios app monetization SDK 添加到我的应用中。我不太了解服务器到服务器的回调。知道如何使用 nodejs 和 express 来完成吗?

【问题讨论】:

标签: ios node.js reactjs express


【解决方案1】:

Rapidoreach 将使用 get 请求向应用设置中维护的回调 URL 发送服务器到服务器的回调。

假设应用设置中的回调 URL 设置为

https://local.callback.com/callback.php

以下是服务器到服务器回调的示例。回调中可用参数的详细信息可以在他们的官方文档中找到 https://www.rapidoreach.com/docs#/callbacks

https://local.callback.com/callback.php?cmd=P&userId=SYKUser-CvkBPlfibeV-aba04fe2fc72219fdbb9a9353a68713d&amt=0.01&offerInvitationId=trans0002&status=P&offerHash=4fdcc6461ec225ba8af3bc66ccf4017c&currencyAmt=0.80&transactionId=trans0002&endUserId=SYKUser&txnHash=d5fecc45d5be250ff757f8694a6d65a1&useragent=Rapidoreach&currencyName=Local Coins&offerType=1&deviceType=Desktop&intergrationMethod=IFRAME

这是一个如何使用 PHP 处理回调的示例。

文件回调.php

<?php

/**
 * ApplicationKey can be found in credentials tab of app created in Rapidoreach
 */
$ApplicationKey = "<Replace this>"; //<- replace this with real application key

/**
 * $endUserId is unique endUserId in publisher's system.
 */
$EndUserId = $_REQUEST['endUserId'];

/**
 * Unique offer Id 
 */
$OfferInvitationId = $_REQUEST['offerInvitationId'];

/**
 * TransactionId
 */
$TransactionId = $_REQUEST['transactionId'];

/**
 * Status
 *    C: Completed - User has successfully completed an offer and should be rewarded with currencyAmt
 *    P: Attempted - User has attempted an offer and attempt is valid will be rewarded with currencyAmt
 *                  currencyAmt will not be full in this case and will be equal to screenout reward maintained in App Setting of Rapidoreach Publisher portal
 *    F: Failed - User has failed to complete an offer and hence terminated. No rewards should be awarded
 */
$Status = $_REQUEST['status'];

/**
 * Validate offerHash
 * You should verify oidHash upon receipt of the callback by recomputing it with the callback offerInvitationId and your ApplicationKey. 
 * This will secure against users faking their own id and passing it in if by some chance they come across the script.
 */
$offerHash = $_REQUEST['offerHash'];
$CalculatedOfferHash = md5($OfferInvitationId . $ApplicationKey);
if ($offerHash != $CalculatedOfferHash) {
  /**
   * TODO: User is trying to manupulate offerId to get credits. Flag this user within this condition if required (optional).
   * Do not credit this user and send success response to Rapidoreach
   * Do not continue further
   */
  echo "1";
  die;
}

/**
 * Validate txnHash
 */

$txnHash = $_REQUEST['txnHash'];
$CalculatedTxnHash = md5($TransactionId . $ApplicationKey);
if ($txnHash != $CalculatedTxnHash) {
  /**
   * TODO: User is trying to manupulate transaction id to get credits. Flag this user within this condition if required (optional).
   * Do not credit this user and send success response to Rapidoreach
   * Do not continue further
   */
  echo "1";
  die;
}

/**
 * Credit the user based on offer status
 */

switch ($Status) {
  case 'C':
    # TODO: Credit the $EndUserId with $currencyAmt use $TransactionId to avoid duplicates
    echo "1";
    die;
    break;
  case 'P':
    # TODO: Credit the $EndUserId with $currencyAmt use $TransactionId to avoid duplicates
    echo "1";
    die;
    break;
  case 'F':
    # TODO: User has failed to complete an offer
    echo "1";
    die;
    break;

  default:
    # code...
    break;
}

【讨论】:

    【解决方案2】:

    您可以使用 node.js 默认提供的 request 方法,或者使用 axios 库进行服务器到服务器回调,但是在 rapidoreach 站点 (https://www.rapidoreach.com/docs#/callbacks) 快速检查会导致此文档用于回调设置,看起来像您想要接收回调,在这种情况下,您必须在最后设置一个 api 来接收他们的服务器调用,这是在 Nodejs 中完成的一个示例

    例子:

            function rapidoreachPostback(req: Request, res: Response) {
    
          var IP = req.headers['x-forwarded-for'] || req.connection.remoteAddress;
          var Input = req.query;
          
          if (Input.status == 'C' || Input.status == "P" || Input.status == "F") {
    
            if(Input.status === "C"){
              //record your completion here
            }
        
            //if rapidoreach allows disaqualification points
            if(Input.status === "P"){
              //record your disqualification transaction over here
            }
            if(Input.status === "F"){
              //record your survey offer failure transaction over here
            }
            
            }
              } catch (error) {
                // send "1" in response to server call from rapidoreach.
                res.send("1");
                return;
              }
              res.send("1");
        
              return;
            })
            return;
          }
          res.send("1");
          return;
        }
        
        
    

    【讨论】:

      猜你喜欢
      • 2021-06-01
      • 2016-02-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多