问题描述
我无法找到一个直接的答案,以我怎么做可下载的内容给用户之前验证服务器上的应用程序内购买的计费
我在app计费3.版本中使用我购买使用基于从TrivialDrive样品code中的IabHelper类code管理产品。一切都很好,很正常,并购买成功完成后,我得到一个完整的购买对象返回和下面的原始JSON数据:
{
的orderId:12999763169054705758.1364365967744519,
软件包名:我的包名,
productId参数:77,
purchaseTime:1366217534000,
purchaseState:0,
"purchaseToken":"utfwimslnrrwvglktizikdcd.AO-J1OwZ4l5oXz_3d2SAWAAUgFE3QErKoyIX8WuSEnBW26ntsyDmlLgoUd5lshqIY2p2LnlV4tpH4NITB4mJMX98sCtZizH7wGf6Izw3tfW_GflJDKFyb-g"
}
据我了解,我需要通过purchaseToken和一些我看到被称为与服务器的签名。然后,服务器用私钥来验证购买。它是否正确?如果是这样,我在哪里得到签名的,是真的有关于购买服务器端验证没有像样的文档?
我在哪里得到的签名?
看一看官方文档,
它说,你的 onActivityResult()
方法中,你可以得到以下数据所示的例子中,
@覆盖
保护无效onActivityResult(INT申请code,INT结果code,意图数据){
如果(要求code == 1001){
INT响应code = data.getIntExtra(RESPONSE_ code,0);
串购买数据= data.getStringExtra(INAPP_PURCHASE_DATA);
字符串dataSignature = data.getStringExtra(INAPP_DATA_SIGNATURE); //这是您要签名
如果(结果code == RESULT_OK){
尝试 {
JSONObject的乔=新的JSONObject(购买数据); //这是你已经包括在你的问题,现在的的JSONObject
字符串SKU = jo.getString(productId参数);
警报(你所购买的+ SKU +最佳选择,
冒险家!);
}
赶上(JSONException E){
警报(无法解析的购买数据。);
e.printStackTrace();
}
}
}
}
我希望这会有所帮助!
I'm unable to find a straight answer as to how I verify an in-app billing purchase on the server before making downloadable content available to the user.
I use in app-billing version 3. I purchase managed products using code based on the IabHelper class from the TrivialDrive sample code. Everything is fine and dandy and the purchase is successfully completed, I get a full Purchase object back and the following original JSON data:
{
"orderId":"12999763169054705758.1364365967744519",
"packageName":"my package name",
"productId":"77",
"purchaseTime":1366217534000,
"purchaseState":0,
"purchaseToken":"utfwimslnrrwvglktizikdcd.AO-J1OwZ4l5oXz_3d2SAWAAUgFE3QErKoyIX8WuSEnBW26ntsyDmlLgoUd5lshqIY2p2LnlV4tpH4NITB4mJMX98sCtZizH7wGf6Izw3tfW_GflJDKFyb-g"
}
As I understand it I need to pass the purchaseToken and something I see referred to as a signature to the server. The server then use a private key to verify the purchase. Is this correct? If so, where do I get the signature from and is there really no decent documentation concerning server-side verification of a purchase?
where do I get the signature from ?
Have a look at official docs,
It says that inside your onActivityResult()
method you can get following data as shown in example,
@Override
protected void onActivityResult(int requestCode, int resultCode, Intent data) {
if (requestCode == 1001) {
int responseCode = data.getIntExtra("RESPONSE_CODE", 0);
String purchaseData = data.getStringExtra("INAPP_PURCHASE_DATA");
String dataSignature = data.getStringExtra("INAPP_DATA_SIGNATURE");//this is the signature which you want
if (resultCode == RESULT_OK) {
try {
JSONObject jo = new JSONObject(purchaseData);//this is the JSONObject which you have included in Your Question right now
String sku = jo.getString("productId");
alert("You have bought the " + sku + ". Excellent choice,
adventurer!");
}
catch (JSONException e) {
alert("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
I hope it will be helpful !!
这篇关于谷歌的服务器端验证播放应用内计费第3版报价的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!