where do I get the signature from ?
看看官方文档,
它说在您的onActivityResult()
方法中,您可以获得以下数据,如示例所示,
@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");
String purchaseToken = jo.getString("purchaseToken");
//you need to send sku and purchaseToken to server for verification
}
catch (JSONException e) {
alert("Failed to parse purchase data.");
e.printStackTrace();
}
}
}
}
对于服务器端的验证,
请查看官方文档
如前所述,客户端应用程序将发送sku
和发送purchaseToken
到服务器 API。服务器必须接收这些值,并且必须使用 android publish api 执行检查以验证购买:
服务器可以通过添加必要的参数来调用以下GET 请求:
https://www.googleapis.com/androidpublisher/v2/applications/ packageName /purchases/products/ productId /tokens/ token
这里,
packageName = 客户端应用程序的 packageName
productId = 从客户端应用程序收到的 sku
令牌 = 从客户端应用程序收到的 purchaseToken
它将导致JSONObject
上述格式的响应:
{
"kind": "androidpublisher#productPurchase",
"purchaseTimeMillis": long,
"purchaseState": integer,
"consumptionState": integer,
"developerPayload": string,
"orderId": string,
"purchaseType": integer
}
这里,purchaseState = 0 表示有效购买
我希望它会有所帮助!