我已经成功地将rapidoreach ios应用货币化SDK添加到我的应用程序中。我对服务器到服务器callbacks..Any不是很了解,我想知道如何使用nodejs和express来实现?
发布于 2021-06-25 17:47:55
你可以使用node.js默认提供的请求方法,或者使用axios库进行服务器到服务器的回调,但是在rapidoreach site (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-10-17 09:53:32
Rapidoreach将使用应用程序设置中维护的回调URL的get请求将服务器发送到服务器回调。
假设应用设置中的回调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¤cyAmt=0.80&transactionId=trans0002&endUserId=SYKUser&txnHash=d5fecc45d5be250ff757f8694a6d65a1&useragent=Rapidoreach¤cyName=Local Coins&offerType=1&deviceType=Desktop&intergrationMethod=IFRAME下面是一个如何使用PHP处理回调的示例。
文件callback.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;
}https://stackoverflow.com/questions/68125604
复制相似问题