问题描述
我即将在应用付款中将google实现到我的android应用中,事情就是这样:
我有3个订阅级别,比如说noob,normal和pro。除了Google登录名外,我的应用程序还具有登录名/注册名。我已经在我的应用程序中实现了所有购买,但是现在我想知道哪种方法是将用Google帐单支付的高级订阅附加到我的用户的最佳做法,因此我可以检查应用程序中的每个用户,即使他们重新共享具有相同Google帐户但订阅级别不同的设备。
*例如:我处于“普通”订阅中,其关系5中的用户名为mine21,使用帐户[email protected]付费
然后我姐姐购买了一个用帐户[email protected]支付的“专业版”订阅 用户名SHE123在她的galaxy S6中,但随后她抓住了我的Nexus 5和 使用SHE123登录,但在Playstore中,我登录为[email protected]。
那一刻,我想向她展示所有专业功能,但我需要 确认SHE123是否为优质帐户,即使该Playstore帐户是 与mine21。链接的[email protected] *
如果我不清楚自己的解释,请告诉我。
我可以从购买订阅的用户那里获得用户ID,并将其与Google帐户ID,令牌购买和高级级别一起保存在我的数据库中吗?
我想知道我该如何与数据库中的每个用户核对google付款,即使他们在Play商店中使用另一个google帐户也是如此。
关于, Inrovero
我要把我的流程付款放在这里:
private void processpayment(final String SKU){
PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
@Override
public void onPurchasesUpdated(@NonNull BillingResult billingResult,@Nullable List<Purchase> list) {
// To be implemented
if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK && list != null){
// do Something you want
Log.i(TAG,"Compra exitosa");
// Preparar categoría de premium
premium = "";
if(list.get(0).getSku().equals(SKU_BS)) premium = "BS";
else if(list.get(0).getSku().equals(SKU_BN)) premium = "BN";
else if(list.get(0).getSku().equals(SKU_BP)) premium = "BP";
Toast.makeText(mContext,premium + " adquirido",Toast.LENGTH_LONG).show();
// Sincronizar premium con la DB y suscripción con el usuario
User currentUser = SharedPrefManager.getInstance(mContext).getUser();
int uid = currentUser.getId();
// Datos a sincronizar
AccountIdentifiers accountIdentifiers = list.get(0).getAccountIdentifiers();
String accID = accountIdentifiers.getobfuscatedAccountId();
String token = list.get(0).getPurchasetoken();
// Pasar a la DB el token,accID y uid vinculados con el premium.
// UID // ACCID // TOKEN // PREMIUM //
}else if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED){
// do Something you want
Log.i(TAG,"Compra cancelada");
// Nada? Cancelar all?
}else if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.ITEM_UNAVAILABLE){
Log.i(TAG,"Item inexistente");
}
}
};
final BillingClient billingClient = BillingClient.newBuilder(mContext)
.setListener(purchasesUpdatedListener)
.enablePendingPurchases()
.build();
billingClient.startConnection(new BillingClientStateListener() {
@Override
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
if(billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK){
// The BillingClient is ready. You can query purchases here.
List<String> skuList = new ArrayList<>();
skuList.add(SKU);
SkuDetailsParams params = SkuDetailsParams.newBuilder()
.setSkusList(skuList).setType(BillingClient.SkuType.SUBS)
.build();
billingClient.querySkuDetailsAsync(params,new SkuDetailsResponseListener() {
@Override
public void onSkuDetailsResponse(@NonNull BillingResult billingResult,@Nullable List<SkuDetails> list) {
if(list == null){
Log.i(TAG,"lista vacía");
return;
}
for(int i = 0; i < list.size(); i++){
Log.i(TAG,String.valueOf(list.get(i)));
}
BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
.setSkuDetails(list.get(0))
.build();
int responseCode = billingClient.launchBillingFlow(requireActivity(),billingFlowParams).getResponseCode();
if(responseCode == BillingClient.BillingResponseCode.OK){
// do Something you want
Log.i(TAG,"responseCode OK");
}else if(responseCode == BillingClient.BillingResponseCode.ERROR){
Log.i(TAG,"responseCode ERROR");
}else if(responseCode == BillingClient.BillingResponseCode.ITEM_UNAVAILABLE){
Log.i(TAG,"responseCode ITEM_UNAVAILABLE");
}
}
});
}
}
@Override
public void onBillingServicedisconnected() {
// Try to restart the connection on the next request to
// Google Play by calling the startConnection() method.
}
});
}
解决方法
购买成功后,将http请求发送到您的php服务器,并将订阅az int 例如int如果noob = 1且pro = 2
并将其保存在服务器上的数据库中 比起您可以从php创建http请求来获取该号码,这样您就知道订阅用户拥有什么
您甚至可以将字符串设置为更易于理解的形式
因此,如果用户x的int = 1,则您知道这是noob订阅 比你想做的
我希望它能帮助您找出答案