Skip to content

Commit

Permalink
将查询历史订单的回调纳入统一接口。
Browse files Browse the repository at this point in the history
  • Loading branch information
TJHello committed May 26, 2020
1 parent 6baabee commit fbdac91
Show file tree
Hide file tree
Showing 3 changed files with 44 additions and 15 deletions.
2 changes: 2 additions & 0 deletions .idea/gradle.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

Original file line number Diff line number Diff line change
Expand Up @@ -421,31 +421,27 @@ private List<Purchase> queryPurchases(String tag,String skuType)
//endregion

//region===================================在线订单查询=================================

/**
* 异步联网查询所有的内购历史-无论是过期的、取消、等等的订单
* @param listener 监听器
* @param activity activity
*/
public void queryPurchaseHistoryAsyncInApp(PurchaseHistoryResponseListener listener){
if(isReady()) {
mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP,listener);
} else{
listener.onPurchaseHistoryResponse(BillingClient.BillingResponse.SERVICE_DISCONNECTED,null);
}
public void queryPurchaseHistoryAsyncInApp(Activity activity){
queryPurchaseHistoryAsync(getTag(activity),BILLING_TYPE_INAPP);
}

/**
* 异步联网查询所有的订阅历史-无论是过期的、取消、等等的订单
* @param listener 监听器
* @param activity activity
*/
public void queryPurchaseHistoryAsyncSubs(PurchaseHistoryResponseListener listener){
public void queryPurchaseHistoryAsyncSubs(Activity activity){
queryPurchaseHistoryAsync(getTag(activity),BILLING_TYPE_SUBS);
}

private void queryPurchaseHistoryAsync(String tag,String type){
if(isReady()) {
mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.SUBS,listener);
}else{
listener.onPurchaseHistoryResponse(BillingClient.BillingResponse.SERVICE_DISCONNECTED,null);
mBillingClient.queryPurchaseHistoryAsync(type,new MyPurchaseHistoryResponseListener(tag));
}
}

//endregion

//region===================================工具集合=================================
Expand Down Expand Up @@ -747,12 +743,36 @@ public void onConsumeResponse(int responseCode, String purchaseToken) {
}
}

private class MyPurchaseHistoryResponseListener implements PurchaseHistoryResponseListener{

private String tag ;
public MyPurchaseHistoryResponseListener(String tag) {
this.tag = tag;
}

@Override
public void onPurchaseHistoryResponse(int responseCode, List<Purchase> list) {
if(responseCode== BillingClient.BillingResponse.OK&&list!=null){
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
for (Purchase purchase : list) {
listener.onQueryHistory(purchase);
}
}
}else{
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
listener.onFail(GoogleBillingListenerTag.HISTORY,responseCode,listener.tag.equals(tag));
}
}
}
}

public enum GoogleBillingListenerTag{

QUERY("query"),
PURCHASE("purchase"),
SETUP("setup"),
COMSUME("comsume")
COMSUME("comsume"),
HISTORY("history")
;
public String tag ;
GoogleBillingListenerTag(String tag){
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -115,4 +115,11 @@ public void onFail(@NonNull GoogleBillingUtil.GoogleBillingListenerTag tag, int
public void onError(@NonNull GoogleBillingUtil.GoogleBillingListenerTag tag, boolean isSelf) {
}

/**
* 获取历史订单-无论是否还有效
* @param purchase 商品实体
*/
public void onQueryHistory(@NonNull Purchase purchase){

}
}

0 comments on commit fbdac91

Please sign in to comment.