lib_google
lib_huawei
This commit is contained in:
parent
238181deca
commit
0b89ac21e8
@ -130,39 +130,36 @@ android {
|
||||
}
|
||||
variant.mergeAssetsProvider.configure {
|
||||
doLast {
|
||||
delete(fileTree(dir: outputDir, includes: [
|
||||
'model/ai_bgseg_green.bundle',
|
||||
'model/ai_face_processor.bundle',
|
||||
//'model/ai_face_processor_lite.bundle',
|
||||
'model/ai_hairseg.bundle',
|
||||
'model/ai_hand_processor.bundle',
|
||||
'model/ai_human_processor.bundle',
|
||||
'model/ai_human_processor_gpu.bundle',
|
||||
'model/ai_human_processor_mb_fast.bundle',
|
||||
'graphics/body_slim.bundle',
|
||||
'graphics/controller_cpp.bundle',
|
||||
//'graphics/face_beautification.bundle',
|
||||
'graphics/face_makeup.bundle',
|
||||
'graphics/fuzzytoonfilter.bundle',
|
||||
'graphics/fxaa.bundle',
|
||||
'graphics/tongue.bundle',
|
||||
//旧美颜
|
||||
'model-all.zip',
|
||||
'filterData.zip',
|
||||
'KSYResource/*',
|
||||
'Resources/*',
|
||||
'Asset/*',
|
||||
'image_effect_shaders/*',
|
||||
'internal/*'
|
||||
//美颜基础组件
|
||||
delete(fileTree(dir: outputDir, includes: ['model/ai_bgseg_green.bundle',
|
||||
'model/ai_face_processor.bundle',
|
||||
//'model/ai_face_processor_lite.bundle',
|
||||
'model/ai_hairseg.bundle',
|
||||
'model/ai_hand_processor.bundle',
|
||||
'model/ai_human_processor.bundle',
|
||||
'model/ai_human_processor_gpu.bundle',
|
||||
'model/ai_human_processor_mb_fast.bundle',
|
||||
'graphics/body_slim.bundle',
|
||||
'graphics/controller_cpp.bundle',
|
||||
//'graphics/face_beautification.bundle',
|
||||
'graphics/face_makeup.bundle',
|
||||
'graphics/fuzzytoonfilter.bundle',
|
||||
'graphics/fxaa.bundle',
|
||||
'graphics/tongue.bundle',
|
||||
//旧美颜
|
||||
'model-all.zip',
|
||||
'filterData.zip',
|
||||
'KSYResource/*',
|
||||
'Resources/*',
|
||||
'Asset/*',
|
||||
'image_effect_shaders/*',
|
||||
'internal/*'
|
||||
//美颜基础组件
|
||||
|
||||
]))
|
||||
println "isPluginModel = " + rootProject.ext.manifestPlaceholders.isPluginModel
|
||||
if (rootProject.ext.manifestPlaceholders.isPluginModel) {
|
||||
delete(fileTree(dir: outputDir, includes: [
|
||||
'model/ai_face_processor_lite.bundle',
|
||||
'graphics/face_beautification.bundle'
|
||||
]))
|
||||
delete(fileTree(dir: outputDir, includes: ['model/ai_face_processor_lite.bundle',
|
||||
'graphics/face_beautification.bundle']))
|
||||
} else {
|
||||
println "不删除bundle"
|
||||
}
|
||||
@ -172,7 +169,7 @@ android {
|
||||
def isGoogle = "link"
|
||||
if (rootProject.ext.manifestPlaceholders.isGooglePlay == 1) {
|
||||
isGoogle = "Google"
|
||||
} else if(rootProject.ext.manifestPlaceholders.isGooglePlay == 2){
|
||||
} else if (rootProject.ext.manifestPlaceholders.isGooglePlay == 2) {
|
||||
isGoogle = "Huawei"
|
||||
}
|
||||
def isPlugin = "all"
|
||||
@ -233,7 +230,6 @@ android {
|
||||
arguments = [AROUTER_MODULE_NAME: project.getName()]
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
buildTypes {
|
||||
release {
|
||||
|
12
app/proguard-rules.pro
vendored
12
app/proguard-rules.pro
vendored
@ -277,3 +277,15 @@ rx.internal.util.atomic.LinkedQueueNode* consumerNode;
|
||||
-keep class tech.sud.mgp.hello.common.event.model.** {*;}
|
||||
|
||||
-keep class com.yunbao.common.sud.** {*;}
|
||||
|
||||
|
||||
|
||||
-ignorewarnings
|
||||
-keepattributes *Annotation*
|
||||
-keepattributes Exceptions
|
||||
-keepattributes InnerClasses
|
||||
-keepattributes Signature
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
-keep class com.huawei.hianalytics.**{*;}
|
||||
-keep class com.huawei.updatesdk.**{*;}
|
||||
-keep class com.huawei.hms.**{*;}
|
||||
|
@ -6,7 +6,6 @@ import android.app.Activity;
|
||||
import android.app.ActivityManager;
|
||||
import android.content.Context;
|
||||
import android.net.http.HttpResponseCache;
|
||||
import android.os.Build;
|
||||
import android.os.Bundle;
|
||||
import android.os.Handler;
|
||||
import android.os.Looper;
|
||||
@ -59,7 +58,6 @@ import java.io.File;
|
||||
import java.io.IOException;
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import io.rong.imkit.config.RongConfigCenter;
|
||||
@ -156,7 +154,6 @@ public class AppContext extends CommonAppContext {
|
||||
}
|
||||
ARouter.init(this);
|
||||
|
||||
|
||||
//初始化 邀请码库
|
||||
if (isMainProcess()) {
|
||||
OpenInstall.init(this);
|
||||
|
@ -4,12 +4,8 @@ import android.app.Activity;
|
||||
import android.text.TextUtils;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.Constants;
|
||||
import com.yunbao.common.R;
|
||||
@ -19,16 +15,12 @@ import com.yunbao.common.event.CoinChangeEvent;
|
||||
import com.yunbao.common.http.CommonHttpUtil;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.pay.wx.WxPayBuilder;
|
||||
import com.yunbao.common.utils.GoogleBillingUtil;
|
||||
import com.yunbao.common.utils.OnGoogleBillingListener;
|
||||
import com.yunbao.common.utils.StringUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
|
||||
import org.greenrobot.eventbus.EventBus;
|
||||
|
||||
import java.lang.ref.WeakReference;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
/**
|
||||
* Created by cxf on 2019/4/22.
|
||||
@ -48,7 +40,7 @@ public class PayPresenter {
|
||||
private PayCallback mPayCallback;
|
||||
|
||||
|
||||
private GoogleBillingUtil googleBillingUtil;
|
||||
//private GoogleBillingUtil googleBillingUtil;
|
||||
private String TAG = "PayPresenter";
|
||||
private String[] arrPro = {"1"};
|
||||
private String mOrderid;
|
||||
@ -174,12 +166,12 @@ public class PayPresenter {
|
||||
}
|
||||
|
||||
private void initGooglePay() {
|
||||
GoogleBillingUtil.isDebug(true);
|
||||
/*GoogleBillingUtil.isDebug(true);
|
||||
GoogleBillingUtil.setSkus(arrPro, null);
|
||||
GoogleBillingUtil.setIsAutoAcknowledgePurchase(true);//设置自动确认购买
|
||||
googleBillingUtil = GoogleBillingUtil.getInstance()
|
||||
.addOnGoogleBillingListener(mActivity, mOnMyGoogleBillingListener)
|
||||
.build(mActivity);
|
||||
.build(mActivity);*/
|
||||
}
|
||||
|
||||
private void paypalPay(String orderParams) {
|
||||
@ -370,125 +362,10 @@ public class PayPresenter {
|
||||
}
|
||||
|
||||
|
||||
private OnGoogleBillingListener mOnMyGoogleBillingListener = new OnGoogleBillingListener() {
|
||||
@Override
|
||||
public void onSetupSuccess(boolean isSelf) {
|
||||
super.onSetupSuccess(isSelf);
|
||||
Log.d(TAG, "内购服务初始化完成");
|
||||
checkSubs();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuerySuccess(@NonNull String skuType, @NonNull List<SkuDetails> list, boolean isSelf) {
|
||||
// if(!isSelf) return;
|
||||
// StringBuffer tempBuffer =new StringBuffer();
|
||||
// tempBuffer.append("查询商品信息成功,数量=" + list.size() + "\n");
|
||||
// Log.d(TAG,tempBuffer.toString());
|
||||
// if (list.size()<=0){
|
||||
// ToastUtil.show("商品金额过大,无法支付");
|
||||
// return;
|
||||
// }
|
||||
// for(int i=0;i<list.size();i++){
|
||||
// String details = String.format(Locale.getDefault(),"%s , %s",
|
||||
// list.get(i).getSku(),list.get(i).getPrice()
|
||||
// );
|
||||
// tempBuffer.append(details);
|
||||
// if(i!=list.size()-1){
|
||||
// tempBuffer.append("\n");
|
||||
// }
|
||||
// }
|
||||
// googleBillingUtil.purchaseInApp(mActivity,"zs640");
|
||||
|
||||
googleBillingUtil.purchaseInApp(mActivity, googleBillingUtil.getInAppSkuByPosition(0));
|
||||
|
||||
// Log.d(TAG,tempBuffer.toString());
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPurchaseSuccess(@NonNull Purchase purchase, boolean isSelf) {
|
||||
StringBuffer tempBuffer = new StringBuffer();
|
||||
if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
|
||||
tempBuffer.append("购买成功:");
|
||||
//通知自己服务器
|
||||
if (mOrderid == null || purchase.getOrderId() == null) {
|
||||
return false;
|
||||
}
|
||||
String allData = "";
|
||||
allData = "OrderId=" + purchase.getOrderId() +
|
||||
",PackageName=" + purchase.getPackageName() +
|
||||
",Sku=" + "purchase.getSku()" +
|
||||
",PurchaseTime=" + purchase.getPurchaseTime() +
|
||||
",PurchaseToken=" + purchase.getPurchaseToken() +
|
||||
",DeveloperPayload=" + purchase.getDeveloperPayload() +
|
||||
",OriginalJson=" + purchase.getOriginalJson() +
|
||||
",PurchaseState=" + purchase.getPurchaseState() +
|
||||
",Signature=" + purchase.getSignature();
|
||||
// CommonHttpUtil.notifyGoogle("1",mOrderid,purchase.getOrderId(),allData, new HttpCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(int code, String msg, String[] info) {
|
||||
// if(code==0){
|
||||
// try {
|
||||
// ToastUtil.show("购买成功!");
|
||||
// }catch (Exception e){
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// }else {
|
||||
// ToastUtil.show("购买失败,请联系客服");
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
|
||||
|
||||
} else {
|
||||
tempBuffer.append("暂未支付:");
|
||||
}
|
||||
String details = String.format(Locale.getDefault(), "%s \n", " purchase.getSku()");
|
||||
tempBuffer.append(details);
|
||||
Log.d(TAG, tempBuffer.toString());
|
||||
return true;//自动消耗(只有当isSelf为true,并且支付状态为PURCHASED时,该值才会生效)
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public boolean onRecheck(@NonNull String skuType, @NonNull Purchase purchase, boolean isSelf) {
|
||||
StringBuffer tempBuffer = new StringBuffer();
|
||||
tempBuffer.append("检测到未处理的订单($skuType):${purchase.sku}()");
|
||||
Log.d(TAG, tempBuffer.toString());
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBillingServiceDisconnected() {
|
||||
super.onBillingServiceDisconnected();
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConsumeSuccess(@NonNull String purchaseToken, boolean isSelf) {
|
||||
Log.d(TAG, "消耗商品成功:$purchaseToken");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAcknowledgePurchaseSuccess(boolean isSelf) {
|
||||
Log.d(TAG, "确认购买商品成功");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onFail(@NonNull GoogleBillingUtil.GoogleBillingListenerTag tag, int responseCode, boolean isSelf) {
|
||||
Log.d(TAG, "操作失败:tag=${" + tag.name() + "responseCode=" + responseCode);
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull GoogleBillingUtil.GoogleBillingListenerTag tag, boolean isSelf) {
|
||||
Log.d(TAG, "发生错误:tag=" + tag.name());
|
||||
}
|
||||
|
||||
};
|
||||
//private OnGoogleBillingListener mOnMyGoogleBillingListener = null;
|
||||
|
||||
private void checkSubs() {
|
||||
int size = googleBillingUtil.getPurchasesSizeSubs(mActivity);
|
||||
/*int size = googleBillingUtil.getPurchasesSizeSubs(mActivity);
|
||||
switch (size) {
|
||||
case 0:
|
||||
//不具备有效订阅
|
||||
@ -502,18 +379,18 @@ public class PayPresenter {
|
||||
//具有有效订阅
|
||||
Log.d(TAG, "有效订阅数:$size(具备有效订阅)");
|
||||
break;
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
public void release() {
|
||||
mActivity = null;
|
||||
mPayCallback = null;
|
||||
|
||||
if (googleBillingUtil != null) {
|
||||
/*if (googleBillingUtil != null) {
|
||||
googleBillingUtil.onDestroy(mActivity);
|
||||
//退出程序的时候可以调用(实验性)
|
||||
GoogleBillingUtil.endConnection();
|
||||
}
|
||||
}*/
|
||||
}
|
||||
|
||||
|
||||
|
@ -30,18 +30,18 @@ public class HwBuilder {
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗所有商品
|
||||
*/
|
||||
public void consume() {
|
||||
try {
|
||||
Class<?> clz = mActivity.getClassLoader().loadClass("com.shayu.lib_huawei.utils.HuaWeiPayManage");
|
||||
Object invite = clz.getConstructor(Activity.class).newInstance(mActivity);
|
||||
invite.getClass().getMethod("consume").invoke(invite);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
/**
|
||||
* 消耗所有商品
|
||||
*/
|
||||
public void consume() {
|
||||
try {
|
||||
Class<?> clz = mActivity.getClassLoader().loadClass("com.shayu.lib_huawei.utils.HuaWeiPayManage");
|
||||
Object invite = clz.getConstructor(Activity.class).newInstance(mActivity);
|
||||
invite.getClass().getMethod("consume").invoke(invite);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取支付结果
|
||||
|
@ -1,926 +0,0 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.billingclient.api.AcknowledgePurchaseParams;
|
||||
import com.android.billingclient.api.AcknowledgePurchaseResponseListener;
|
||||
import com.android.billingclient.api.BillingClient;
|
||||
import com.android.billingclient.api.BillingClientStateListener;
|
||||
import com.android.billingclient.api.BillingFlowParams;
|
||||
import com.android.billingclient.api.BillingResult;
|
||||
import com.android.billingclient.api.ConsumeParams;
|
||||
import com.android.billingclient.api.ConsumeResponseListener;
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.android.billingclient.api.PurchaseHistoryResponseListener;
|
||||
import com.android.billingclient.api.PurchasesUpdatedListener;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.android.billingclient.api.SkuDetailsParams;
|
||||
import com.android.billingclient.api.SkuDetailsResponseListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 作者:天镜baobao
|
||||
* 时间:2019/1/5 15:16
|
||||
* 说明:允许使用,但请遵循Apache License 2.0
|
||||
* 使用:
|
||||
* Copyright 2019 天镜baobao
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
@SuppressWarnings({"WeakerAccess", "unused", "UnusedReturnValue"})
|
||||
public class GoogleBillingUtil {
|
||||
|
||||
private static final String TAG = "GoogleBillingUtil";
|
||||
private static boolean IS_DEBUG = false;
|
||||
private static String[] inAppSKUS = new String[]{};//内购ID,必填,注意!如果用不着的请去掉多余的""
|
||||
private static String[] subsSKUS = new String[]{};//订阅ID,必填,注意!如果用不着的请去掉多余的""
|
||||
|
||||
public static final String BILLING_TYPE_INAPP = BillingClient.SkuType.INAPP;//内购
|
||||
public static final String BILLING_TYPE_SUBS = BillingClient.SkuType.SUBS;//订阅
|
||||
|
||||
private static BillingClient mBillingClient;
|
||||
private static BillingClient.Builder builder ;
|
||||
private static List<OnGoogleBillingListener> onGoogleBillingListenerList = new ArrayList<>();
|
||||
private static Map<String,OnGoogleBillingListener> onGoogleBillingListenerMap = new HashMap<>();
|
||||
private MyPurchasesUpdatedListener purchasesUpdatedListener = new MyPurchasesUpdatedListener();
|
||||
|
||||
private static boolean isAutoAcknowledgePurchase = true;
|
||||
|
||||
private static final GoogleBillingUtil mGoogleBillingUtil = new GoogleBillingUtil() ;
|
||||
|
||||
private GoogleBillingUtil()
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
//region===================================初始化google应用内购买服务=================================
|
||||
|
||||
/**
|
||||
* 设置skus
|
||||
* @param inAppSKUS 内购id
|
||||
* @param subsSKUS 订阅id
|
||||
*/
|
||||
public static void setSkus(@Nullable String[] inAppSKUS, @Nullable String[] subsSKUS){
|
||||
if(inAppSKUS!=null){
|
||||
GoogleBillingUtil.inAppSKUS = Arrays.copyOf(inAppSKUS,inAppSKUS.length);
|
||||
}
|
||||
if(subsSKUS!=null){
|
||||
GoogleBillingUtil.subsSKUS = Arrays.copyOf(subsSKUS,subsSKUS.length);
|
||||
}
|
||||
}
|
||||
|
||||
private static <T> void copyToArray(T[] base,T[] target){
|
||||
System.arraycopy(base, 0, target, 0, base.length);
|
||||
}
|
||||
|
||||
public static GoogleBillingUtil getInstance()
|
||||
{
|
||||
return mGoogleBillingUtil;
|
||||
}
|
||||
|
||||
/**
|
||||
* 开始建立内购连接
|
||||
* @param activity activity
|
||||
*/
|
||||
public GoogleBillingUtil build(Activity activity)
|
||||
{
|
||||
purchasesUpdatedListener.tag = getTag(activity);
|
||||
if(mBillingClient==null)
|
||||
{
|
||||
synchronized (mGoogleBillingUtil)
|
||||
{
|
||||
if(mBillingClient==null)
|
||||
{
|
||||
builder = BillingClient.newBuilder(activity);
|
||||
mBillingClient = builder.setListener(purchasesUpdatedListener)
|
||||
.enablePendingPurchases()
|
||||
.build();
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.setListener(purchasesUpdatedListener);
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
builder.setListener(purchasesUpdatedListener);
|
||||
}
|
||||
synchronized (mGoogleBillingUtil)
|
||||
{
|
||||
if(mGoogleBillingUtil.startConnection(activity))
|
||||
{
|
||||
mGoogleBillingUtil.queryInventoryInApp(getTag(activity));
|
||||
mGoogleBillingUtil.queryInventorySubs(getTag(activity));
|
||||
mGoogleBillingUtil.queryPurchasesInApp(getTag(activity));
|
||||
}
|
||||
}
|
||||
return mGoogleBillingUtil;
|
||||
}
|
||||
|
||||
public boolean startConnection(Activity activity){
|
||||
return startConnection(getTag(activity));
|
||||
}
|
||||
|
||||
private boolean startConnection(String tag)
|
||||
{
|
||||
if(mBillingClient==null)
|
||||
{
|
||||
log("初始化失败:mBillingClient==null");
|
||||
return false;
|
||||
}
|
||||
if(!mBillingClient.isReady())
|
||||
{
|
||||
mBillingClient.startConnection(new BillingClientStateListener() {
|
||||
@Override
|
||||
public void onBillingSetupFinished(BillingResult billingResult) {
|
||||
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onSetupSuccess(listener.tag.equals(tag));
|
||||
}
|
||||
queryInventoryInApp(tag);
|
||||
queryInventorySubs(tag);
|
||||
queryPurchasesInApp(tag);
|
||||
}
|
||||
else
|
||||
{
|
||||
log("初始化失败:onSetupFail:code="+billingResult.getResponseCode());
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onFail(GoogleBillingListenerTag.SETUP,billingResult.getResponseCode(), listener.tag.equals(tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onBillingServiceDisconnected() {
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onBillingServiceDisconnected();
|
||||
}
|
||||
log("初始化失败:onBillingServiceDisconnected");
|
||||
}
|
||||
});
|
||||
return false;
|
||||
}
|
||||
else
|
||||
{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region===================================查询商品=================================
|
||||
|
||||
/**
|
||||
* 查询内购商品信息
|
||||
*/
|
||||
public void queryInventoryInApp(Activity activity)
|
||||
{
|
||||
queryInventoryInApp(getTag(activity));
|
||||
}
|
||||
|
||||
private void queryInventoryInApp(String tag)
|
||||
{
|
||||
queryInventory(tag, BillingClient.SkuType.INAPP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询订阅商品信息
|
||||
*/
|
||||
public void queryInventorySubs(Activity activity)
|
||||
{
|
||||
queryInventory(getTag(activity), BillingClient.SkuType.SUBS);
|
||||
}
|
||||
|
||||
public void queryInventorySubs(String tag)
|
||||
{
|
||||
queryInventory(tag, BillingClient.SkuType.SUBS);
|
||||
}
|
||||
|
||||
private void queryInventory(String tag,final String skuType) {
|
||||
Runnable runnable=new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
|
||||
if (mBillingClient == null)
|
||||
{
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onError(GoogleBillingListenerTag.QUERY, listener.tag.equals(tag));
|
||||
}
|
||||
return ;
|
||||
}
|
||||
ArrayList<String> skuList = new ArrayList<>();
|
||||
if(skuType.equals(BillingClient.SkuType.INAPP))
|
||||
{
|
||||
Collections.addAll(skuList, inAppSKUS);
|
||||
}
|
||||
else if(skuType.equals(BillingClient.SkuType.SUBS))
|
||||
{
|
||||
Collections.addAll(skuList, subsSKUS);
|
||||
}
|
||||
if(!skuList.isEmpty()){
|
||||
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder();
|
||||
params.setSkusList(skuList).setType(skuType);
|
||||
mBillingClient.querySkuDetailsAsync(params.build(),new MySkuDetailsResponseListener(skuType,tag));
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
executeServiceRequest(tag,runnable);
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region===================================购买商品=================================
|
||||
/**
|
||||
* 发起内购
|
||||
* @param skuId 内购商品id
|
||||
*/
|
||||
public void purchaseInApp(Activity activity, String skuId)
|
||||
{
|
||||
purchase(activity,skuId, BillingClient.SkuType.INAPP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 发起订阅
|
||||
* @param skuId 订阅商品id
|
||||
*/
|
||||
public void purchaseSubs(Activity activity,String skuId)
|
||||
{
|
||||
purchase(activity,skuId, BillingClient.SkuType.SUBS);
|
||||
}
|
||||
|
||||
private void purchase(Activity activity,final String skuId,final String skuType)
|
||||
{
|
||||
String tag = getTag(activity);
|
||||
if(mBillingClient==null)
|
||||
{
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onError(GoogleBillingListenerTag.PURCHASE, listener.tag.equals(tag));
|
||||
}
|
||||
return ;
|
||||
}
|
||||
if(startConnection(tag))
|
||||
{
|
||||
purchasesUpdatedListener.tag = tag;
|
||||
builder.setListener(purchasesUpdatedListener);
|
||||
List<String> skuList = new ArrayList<>();
|
||||
skuList.add(skuId);
|
||||
SkuDetailsParams skuDetailsParams = SkuDetailsParams.newBuilder()
|
||||
.setSkusList(skuList)
|
||||
.setType(skuType)
|
||||
.build();
|
||||
mBillingClient.querySkuDetailsAsync(skuDetailsParams, new SkuDetailsResponseListener() {
|
||||
@Override
|
||||
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
|
||||
|
||||
}
|
||||
});
|
||||
|
||||
mBillingClient.querySkuDetailsAsync(skuDetailsParams, new SkuDetailsResponseListener() {
|
||||
@Override
|
||||
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> skuDetailsList) {
|
||||
if(skuDetailsList!=null&&!skuDetailsList.isEmpty()){
|
||||
BillingFlowParams flowParams = BillingFlowParams.newBuilder()
|
||||
.setSkuDetails(skuDetailsList.get(0))
|
||||
.build();
|
||||
mBillingClient.launchBillingFlow(activity,flowParams);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}
|
||||
else
|
||||
{
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onError(GoogleBillingListenerTag.PURCHASE,listener.tag.equals(tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
//endregion
|
||||
|
||||
//region===================================消耗商品=================================
|
||||
|
||||
/**
|
||||
* 消耗商品
|
||||
* @param purchaseToken {@link Purchase#getPurchaseToken()}
|
||||
*/
|
||||
public void consumeAsync(Activity activity,String purchaseToken)
|
||||
{
|
||||
consumeAsync(getTag(activity),purchaseToken,null);
|
||||
}
|
||||
|
||||
|
||||
public void consumeAsync(Activity activity,String purchaseToken,@Nullable String developerPayload)
|
||||
{
|
||||
consumeAsync(getTag(activity),purchaseToken,developerPayload);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗商品
|
||||
* @param purchaseToken {@link Purchase#getPurchaseToken()}
|
||||
*/
|
||||
private void consumeAsync(String tag,String purchaseToken){
|
||||
consumeAsync(tag,purchaseToken,null);
|
||||
}
|
||||
|
||||
|
||||
private void consumeAsync(String tag,String purchaseToken,@Nullable String developerPayload)
|
||||
{
|
||||
if(mBillingClient==null)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
ConsumeParams consumeParams = ConsumeParams.newBuilder()
|
||||
.setPurchaseToken(purchaseToken)
|
||||
.build();
|
||||
mBillingClient.consumeAsync(consumeParams,new MyConsumeResponseListener(tag));
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗内购商品-通过sku数组
|
||||
* @param sku sku
|
||||
*/
|
||||
public void consumeAsyncInApp(Activity activity,@NonNull String... sku)
|
||||
{
|
||||
if(mBillingClient==null) {
|
||||
return ;
|
||||
}
|
||||
List<String> skuList = Arrays.asList(sku);
|
||||
consumeAsyncInApp(activity,skuList,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗内购商品-通过sku数组
|
||||
* @param skuList sku数组
|
||||
*/
|
||||
public void consumeAsyncInApp(Activity activity,@NonNull List<String> skuList,@Nullable List<String> developerPayloadList)
|
||||
{
|
||||
if(mBillingClient==null) {
|
||||
return ;
|
||||
}
|
||||
List<Purchase> purchaseList = queryPurchasesInApp(activity);
|
||||
if(purchaseList!=null){
|
||||
for(Purchase purchase : purchaseList){
|
||||
int index = skuList.indexOf("purchase.getSku()");
|
||||
if(index!=-1){
|
||||
if(developerPayloadList!=null&&index<developerPayloadList.size()){
|
||||
consumeAsync(activity,purchase.getPurchaseToken(),developerPayloadList.get(index));
|
||||
}else{
|
||||
consumeAsync(activity,purchase.getPurchaseToken(),null);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region===================================确认购买=================================
|
||||
|
||||
/**
|
||||
* 确认购买
|
||||
* @param activity activity
|
||||
* @param purchaseToken token
|
||||
*/
|
||||
public void acknowledgePurchase(Activity activity,String purchaseToken){
|
||||
acknowledgePurchase(activity,purchaseToken,null);
|
||||
}
|
||||
|
||||
public void acknowledgePurchase(Activity activity,String purchaseToken,@Nullable String developerPayload){
|
||||
acknowledgePurchase(getTag(activity),purchaseToken,developerPayload);
|
||||
}
|
||||
|
||||
private void acknowledgePurchase(String tag,String purchaseToken){
|
||||
acknowledgePurchase(tag,purchaseToken,null);
|
||||
}
|
||||
|
||||
private void acknowledgePurchase(String tag,String purchaseToken,@Nullable String developerPayload){
|
||||
if(mBillingClient==null)
|
||||
{
|
||||
return ;
|
||||
}
|
||||
AcknowledgePurchaseParams params = AcknowledgePurchaseParams.newBuilder()
|
||||
.setPurchaseToken(purchaseToken)
|
||||
.build();
|
||||
mBillingClient.acknowledgePurchase(params,new MyAcknowledgePurchaseResponseListener(tag));
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region===================================本地订单查询=================================
|
||||
/**
|
||||
* 获取已经内购的商品
|
||||
* @return 商品列表
|
||||
*/
|
||||
public List<Purchase> queryPurchasesInApp(Activity activity)
|
||||
{
|
||||
return queryPurchases(getTag(activity), BillingClient.SkuType.INAPP);
|
||||
}
|
||||
|
||||
private List<Purchase> queryPurchasesInApp(String tag)
|
||||
{
|
||||
return queryPurchases(tag, BillingClient.SkuType.INAPP);
|
||||
}
|
||||
|
||||
/**
|
||||
* 获取已经订阅的商品
|
||||
* @return 商品列表
|
||||
*/
|
||||
public List<Purchase> queryPurchasesSubs(Activity activity)
|
||||
{
|
||||
return queryPurchases(getTag(activity), BillingClient.SkuType.SUBS);
|
||||
}
|
||||
|
||||
private List<Purchase> queryPurchases(String tag, String skuType)
|
||||
{
|
||||
// if(mBillingClient==null)
|
||||
// {
|
||||
// return null;
|
||||
// }
|
||||
// if(!mBillingClient.isReady())
|
||||
// {
|
||||
// startConnection(tag);
|
||||
// }
|
||||
// else
|
||||
// {
|
||||
// Purchase.PurchasesResult purchasesResult = mBillingClient.queryPurchases(skuType);
|
||||
// if(purchasesResult!=null)
|
||||
// {
|
||||
// if(purchasesResult.getResponseCode()== BillingClient.BillingResponseCode.OK)
|
||||
// {
|
||||
// List<Purchase> purchaseList = purchasesResult.getPurchasesList();
|
||||
// if(purchaseList!=null&&!purchaseList.isEmpty())
|
||||
// {
|
||||
// for(Purchase purchase:purchaseList)
|
||||
// {
|
||||
// for(OnGoogleBillingListener listener : onGoogleBillingListenerList) {
|
||||
// boolean isSelf = listener.tag.equals(tag);//是否是当前页面
|
||||
// boolean isSuccess = listener.onRecheck(skuType, purchase, isSelf);//是否消耗或者确认
|
||||
// if(isSelf){
|
||||
// if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
|
||||
// if(skuType.equals(BillingClient.SkuType.INAPP)) {
|
||||
// if(isSuccess){
|
||||
// consumeAsync(tag,purchase.getPurchaseToken());
|
||||
// }else if(isAutoAcknowledgePurchase){
|
||||
// if(!purchase.isAcknowledged()){
|
||||
// acknowledgePurchase(tag,purchase.getPurchaseToken());
|
||||
// }
|
||||
// }
|
||||
// }else if(skuType.equals(BillingClient.SkuType.SUBS)){
|
||||
// if(isAutoAcknowledgePurchase){
|
||||
// if(!purchase.isAcknowledged()){
|
||||
// acknowledgePurchase(tag,purchase.getPurchaseToken());
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }else{
|
||||
// log("未支付的订单:"+"purchase.getSku()");
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
// return purchaseList;
|
||||
// }
|
||||
// }
|
||||
// }
|
||||
return null;
|
||||
}
|
||||
//endregion
|
||||
|
||||
//region===================================在线订单查询=================================
|
||||
|
||||
/**
|
||||
* 异步联网查询所有的内购历史-无论是过期的、取消、等等的订单
|
||||
* @param listener 监听器
|
||||
* @return 返回false的时候说明网络出错
|
||||
*/
|
||||
public boolean queryPurchaseHistoryAsyncInApp(PurchaseHistoryResponseListener listener){
|
||||
if(isReady()) {
|
||||
mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.INAPP,listener);
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
/**
|
||||
* 异步联网查询所有的订阅历史-无论是过期的、取消、等等的订单
|
||||
* @param listener 监听器
|
||||
* @return 返回false的时候说明网络出错
|
||||
*/
|
||||
public boolean queryPurchaseHistoryAsyncSubs(PurchaseHistoryResponseListener listener){
|
||||
if(isReady()) {
|
||||
mBillingClient.queryPurchaseHistoryAsync(BillingClient.SkuType.SUBS,listener);
|
||||
return true;
|
||||
}else{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region===================================工具集合=================================
|
||||
/**
|
||||
* 获取有效订阅的数量
|
||||
* @return -1查询失败,0没有有效订阅,>0具有有效的订阅
|
||||
*/
|
||||
public int getPurchasesSizeSubs(Activity activity)
|
||||
{
|
||||
List<Purchase> list = queryPurchasesSubs(activity);
|
||||
if(list!=null)
|
||||
{
|
||||
return list.size();
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过sku获取订阅商品序号
|
||||
* @param sku sku
|
||||
* @return 序号
|
||||
*/
|
||||
public int getSubsPositionBySku(String sku)
|
||||
{
|
||||
return getPositionBySku(sku, BillingClient.SkuType.SUBS);
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过sku获取内购商品序号
|
||||
* @param sku sku
|
||||
* @return 成功返回需要 失败返回-1
|
||||
*/
|
||||
public int getInAppPositionBySku(String sku)
|
||||
{
|
||||
return getPositionBySku(sku, BillingClient.SkuType.INAPP);
|
||||
}
|
||||
|
||||
private int getPositionBySku(String sku,String skuType)
|
||||
{
|
||||
|
||||
if(skuType.equals(BillingClient.SkuType.INAPP))
|
||||
{
|
||||
int i = 0;
|
||||
for(String s:inAppSKUS)
|
||||
{
|
||||
if(s.equals(sku))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
else if(skuType.equals(BillingClient.SkuType.SUBS))
|
||||
{
|
||||
int i = 0;
|
||||
for(String s:subsSKUS)
|
||||
{
|
||||
if(s.equals(sku))
|
||||
{
|
||||
return i;
|
||||
}
|
||||
i++;
|
||||
}
|
||||
}
|
||||
return -1;
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过序号获取订阅sku
|
||||
* @param position 序号
|
||||
* @return sku
|
||||
*/
|
||||
public String getSubsSkuByPosition(int position)
|
||||
{
|
||||
if(position>=0&&position<subsSKUS.length)
|
||||
{
|
||||
return subsSKUS[position];
|
||||
}
|
||||
else {
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过序号获取内购sku
|
||||
* @param position 序号
|
||||
* @return sku
|
||||
*/
|
||||
public String getInAppSkuByPosition(int position)
|
||||
{
|
||||
if(position>=0&&position<inAppSKUS.length)
|
||||
{
|
||||
return inAppSKUS[position];
|
||||
}
|
||||
else
|
||||
{
|
||||
return null;
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 通过sku获取商品类型(订阅获取内购)
|
||||
* @param sku sku
|
||||
* @return inapp内购,subs订阅
|
||||
*/
|
||||
public String getSkuType(String sku)
|
||||
{
|
||||
if(Arrays.asList(inAppSKUS).contains(sku))
|
||||
{
|
||||
return BillingClient.SkuType.INAPP;
|
||||
}
|
||||
else if(Arrays.asList(subsSKUS).contains(sku))
|
||||
{
|
||||
return BillingClient.SkuType.SUBS;
|
||||
}
|
||||
return null;
|
||||
}
|
||||
|
||||
private String getTag(Activity activity){
|
||||
if (activity==null){return "";}
|
||||
return activity.getLocalClassName();
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
//region===================================其他方法=================================
|
||||
|
||||
private void executeServiceRequest(String tag,final Runnable runnable) {
|
||||
if(startConnection(tag))
|
||||
{
|
||||
runnable.run();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* google内购服务是否已经准备好
|
||||
* @return boolean
|
||||
*/
|
||||
public static boolean isReady() {
|
||||
return mBillingClient!=null&&mBillingClient.isReady();
|
||||
}
|
||||
|
||||
/**
|
||||
* 设置是否自动确认购买
|
||||
* @param isAutoAcknowledgePurchase boolean
|
||||
*/
|
||||
public static void setIsAutoAcknowledgePurchase(boolean isAutoAcknowledgePurchase){
|
||||
GoogleBillingUtil.isAutoAcknowledgePurchase = isAutoAcknowledgePurchase;
|
||||
}
|
||||
|
||||
/**
|
||||
* 断开连接google服务
|
||||
* 注意!!!一般情况不建议调用该方法,让google保留连接是最好的选择。
|
||||
*/
|
||||
public static void endConnection()
|
||||
{
|
||||
//注意!!!一般情况不建议调用该方法,让google保留连接是最好的选择。
|
||||
if(mBillingClient!=null)
|
||||
{
|
||||
if(mBillingClient.isReady())
|
||||
{
|
||||
mBillingClient.endConnection();
|
||||
mBillingClient = null;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
//endregion
|
||||
|
||||
public GoogleBillingUtil addOnGoogleBillingListener(Activity activity,OnGoogleBillingListener onGoogleBillingListener){
|
||||
String tag = getTag(activity);
|
||||
onGoogleBillingListener.tag = tag;
|
||||
onGoogleBillingListenerMap.put(getTag(activity),onGoogleBillingListener);
|
||||
for(int i=onGoogleBillingListenerList.size()-1;i>=0;i--){
|
||||
OnGoogleBillingListener listener = onGoogleBillingListenerList.get(i);
|
||||
if(listener.tag.equals(tag)){
|
||||
onGoogleBillingListenerList.remove(listener);
|
||||
}
|
||||
}
|
||||
onGoogleBillingListenerList.add(onGoogleBillingListener);
|
||||
return this;
|
||||
}
|
||||
|
||||
public void removeOnGoogleBillingListener(OnGoogleBillingListener onGoogleBillingListener){
|
||||
onGoogleBillingListenerList.remove(onGoogleBillingListener);
|
||||
}
|
||||
|
||||
public void removeOnGoogleBillingListener(Activity activity){
|
||||
String tag = getTag(activity);
|
||||
for(int i=onGoogleBillingListenerList.size()-1;i>=0;i--){
|
||||
OnGoogleBillingListener listener = onGoogleBillingListenerList.get(i);
|
||||
if(listener.tag.equals(tag)){
|
||||
removeOnGoogleBillingListener(listener);
|
||||
onGoogleBillingListenerMap.remove(tag);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 清除内购监听器,防止内存泄漏-在Activity-onDestroy里面调用。
|
||||
* 需要确保onDestroy和build方法在同一个线程。
|
||||
*/
|
||||
public void onDestroy(Activity activity){
|
||||
if(builder!=null) {
|
||||
builder.setListener(null);
|
||||
}
|
||||
if (activity != null)
|
||||
removeOnGoogleBillingListener(activity);
|
||||
}
|
||||
|
||||
/**
|
||||
* Google购买商品回调接口(订阅和内购都走这个接口)
|
||||
*/
|
||||
private class MyPurchasesUpdatedListener implements PurchasesUpdatedListener
|
||||
{
|
||||
|
||||
public String tag ;
|
||||
|
||||
@Override
|
||||
public void onPurchasesUpdated(BillingResult billingResult, @Nullable List<Purchase> list) {
|
||||
if(billingResult.getResponseCode()== BillingClient.BillingResponseCode.OK&&list!=null)
|
||||
{
|
||||
for(Purchase purchase:list) {
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
boolean isSelf = listener.tag.equals(tag);//是否是当前页面
|
||||
boolean isSuccess = listener.onPurchaseSuccess(purchase,isSelf);//是否自动消耗
|
||||
if(isSelf&&purchase.getPurchaseState()== Purchase.PurchaseState.PURCHASED){
|
||||
//是当前页面,并且商品状态为支付成功,才会进行消耗与确认的操作
|
||||
String skuType = getSkuType("purchase.getSku()");
|
||||
if(BillingClient.SkuType.INAPP.equals(skuType)){
|
||||
if(isSuccess){
|
||||
//进行消耗
|
||||
consumeAsync(tag,purchase.getPurchaseToken());
|
||||
}else if(isAutoAcknowledgePurchase){
|
||||
//进行确认购买
|
||||
if(!purchase.isAcknowledged()){
|
||||
acknowledgePurchase(tag,purchase.getPurchaseToken());
|
||||
}
|
||||
}
|
||||
}else if(BillingClient.SkuType.SUBS.equals(skuType)){
|
||||
//进行确认购买
|
||||
if(isAutoAcknowledgePurchase){
|
||||
if(!purchase.isAcknowledged()){
|
||||
acknowledgePurchase(tag,purchase.getPurchaseToken());
|
||||
}
|
||||
}
|
||||
}
|
||||
}else if(purchase.getPurchaseState()== Purchase.PurchaseState.PENDING){
|
||||
log("待处理的订单:"+"purchase.getSku()");
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
if(IS_DEBUG){
|
||||
log("购买失败,responseCode:"+billingResult.getResponseCode()+",msg:"+billingResult.getDebugMessage());
|
||||
}
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onFail(GoogleBillingListenerTag.PURCHASE,billingResult.getResponseCode(),listener.tag.equals(tag));
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Google查询商品信息回调接口
|
||||
*/
|
||||
private class MySkuDetailsResponseListener implements SkuDetailsResponseListener
|
||||
{
|
||||
private String skuType ;
|
||||
private String tag;
|
||||
|
||||
public MySkuDetailsResponseListener(String skuType,String tag) {
|
||||
this.skuType = skuType;
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onSkuDetailsResponse(BillingResult billingResult, List<SkuDetails> list) {
|
||||
if(billingResult.getResponseCode()== BillingClient.BillingResponseCode.OK&&list!=null)
|
||||
{
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onQuerySuccess(skuType,list,listener.tag.equals(tag));
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onFail(GoogleBillingListenerTag.QUERY,billingResult.getResponseCode(),listener.tag.equals(tag));
|
||||
}
|
||||
if(IS_DEBUG){
|
||||
log("查询失败,responseCode:"+billingResult.getResponseCode()+",msg:"+billingResult.getDebugMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
/**
|
||||
* Googlg消耗商品回调
|
||||
*/
|
||||
private class MyConsumeResponseListener implements ConsumeResponseListener
|
||||
{
|
||||
private String tag ;
|
||||
|
||||
public MyConsumeResponseListener(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
|
||||
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onConsumeSuccess(purchaseToken,listener.tag.equals(tag));
|
||||
}
|
||||
}else{
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onFail(GoogleBillingListenerTag.COMSUME,billingResult.getResponseCode(),listener.tag.equals(tag));
|
||||
}
|
||||
if(IS_DEBUG){
|
||||
log("消耗失败,responseCode:"+billingResult.getResponseCode()+",msg:"+billingResult.getDebugMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Googlg消耗商品回调
|
||||
*/
|
||||
private class MyAcknowledgePurchaseResponseListener implements AcknowledgePurchaseResponseListener {
|
||||
|
||||
private String tag ;
|
||||
|
||||
public MyAcknowledgePurchaseResponseListener(String tag) {
|
||||
this.tag = tag;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onAcknowledgePurchaseResponse(BillingResult billingResult) {
|
||||
if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) {
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onAcknowledgePurchaseSuccess(listener.tag.equals(tag));
|
||||
}
|
||||
}else{
|
||||
for(OnGoogleBillingListener listener:onGoogleBillingListenerList){
|
||||
listener.onFail(GoogleBillingListenerTag.AcKnowledgePurchase,billingResult.getResponseCode(),listener.tag.equals(tag));
|
||||
}
|
||||
if(IS_DEBUG){
|
||||
log("确认购买失败,responseCode:"+billingResult.getResponseCode()+",msg:"+billingResult.getDebugMessage());
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
public enum GoogleBillingListenerTag{
|
||||
|
||||
QUERY("query"),
|
||||
PURCHASE("purchase"),
|
||||
SETUP("setup"),
|
||||
COMSUME("comsume"),
|
||||
AcKnowledgePurchase("AcKnowledgePurchase"),
|
||||
;
|
||||
public String tag ;
|
||||
GoogleBillingListenerTag(String tag){
|
||||
this.tag = tag;
|
||||
}
|
||||
}
|
||||
|
||||
private static void log(String msg)
|
||||
{
|
||||
if(IS_DEBUG)
|
||||
{
|
||||
Log.e(TAG,msg);
|
||||
}
|
||||
}
|
||||
|
||||
public static void isDebug(boolean isDebug){
|
||||
GoogleBillingUtil.IS_DEBUG = isDebug;
|
||||
}
|
||||
}
|
@ -1,184 +0,0 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
import android.app.Activity;
|
||||
import android.util.Log;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.annotation.Nullable;
|
||||
|
||||
import com.android.billingclient.api.BillingClient;
|
||||
import com.android.billingclient.api.BillingClientStateListener;
|
||||
import com.android.billingclient.api.BillingFlowParams;
|
||||
import com.android.billingclient.api.BillingResult;
|
||||
import com.android.billingclient.api.ConsumeParams;
|
||||
import com.android.billingclient.api.ConsumeResponseListener;
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.android.billingclient.api.PurchasesResponseListener;
|
||||
import com.android.billingclient.api.PurchasesUpdatedListener;
|
||||
import com.android.billingclient.api.QueryPurchasesParams;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.android.billingclient.api.SkuDetailsParams;
|
||||
import com.android.billingclient.api.SkuDetailsResponseListener;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 新写Google内付工具类做简单的封装
|
||||
* 支付流程:初始化Google支付服务-->查询商品-->购买-->支付成功回调-->消耗商品
|
||||
*/
|
||||
public class GoogleBillingUtilNew {
|
||||
private BillingClient billingClient;
|
||||
private Activity mContext;
|
||||
private String TAG = "GoogleBillingUtilNew";
|
||||
private static GoogleBillingUtilNew googleBillingUtilNew;
|
||||
|
||||
public static GoogleBillingUtilNew getInstance() {
|
||||
if (googleBillingUtilNew == null) {
|
||||
googleBillingUtilNew = new GoogleBillingUtilNew();
|
||||
}
|
||||
return googleBillingUtilNew;
|
||||
}
|
||||
|
||||
public void initGooglePay(Activity mContext) {
|
||||
this.mContext = mContext;
|
||||
billingClient = BillingClient.newBuilder(mContext)
|
||||
.setListener(purchasesUpdatedListener)
|
||||
.enablePendingPurchases()
|
||||
.build();
|
||||
//请求连接到GooglePay
|
||||
billingClient.startConnection(new BillingClientStateListener() {
|
||||
@Override
|
||||
public void onBillingSetupFinished(@NonNull BillingResult billingResult) {
|
||||
int code = billingResult.getResponseCode();
|
||||
if (code != BillingClient.BillingResponseCode.OK) {
|
||||
String msg = billingResult.getDebugMessage();
|
||||
Log.e(TAG, "连接到GooglePay失败 code = " + code + " msg = " + msg);
|
||||
return;
|
||||
}
|
||||
Log.e(TAG, "连接到GooglePay成功");
|
||||
|
||||
}
|
||||
|
||||
//连接失败
|
||||
@Override
|
||||
public void onBillingServiceDisconnected() {
|
||||
Log.e(TAG, "连接到GooglePay失败,请重试");
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//查询商品
|
||||
public void checkSku(String id) {
|
||||
List<String> skuList = new ArrayList<>();
|
||||
skuList.add(id);
|
||||
SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder()
|
||||
.setSkusList(skuList)
|
||||
.setType(BillingClient.SkuType.INAPP);
|
||||
billingClient.querySkuDetailsAsync(params.build(), new SkuDetailsResponseListener() {
|
||||
@Override
|
||||
public void onSkuDetailsResponse(@NonNull BillingResult billingResult, @Nullable List<SkuDetails> list) {
|
||||
int code = billingResult.getResponseCode();
|
||||
if (code != BillingClient.BillingResponseCode.OK || list == null || list.isEmpty()) {
|
||||
String msg = billingResult.getDebugMessage();
|
||||
Log.e(TAG, "查询商品失败 code = " + code + " msg = " + msg);
|
||||
return;
|
||||
}
|
||||
Log.e(TAG, "查询商品成功");
|
||||
buyIt(list.get(0));
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
//购买
|
||||
private void buyIt(SkuDetails skuDetails) {
|
||||
BillingFlowParams billingFlowParams = BillingFlowParams.newBuilder()
|
||||
.setSkuDetails(skuDetails)
|
||||
.build();
|
||||
BillingResult billingResult = billingClient.launchBillingFlow(mContext, billingFlowParams);
|
||||
int code = billingResult.getResponseCode();
|
||||
if (code != BillingClient.BillingResponseCode.OK) {
|
||||
String msg = billingResult.getDebugMessage();
|
||||
Log.e(TAG, "购买商品失败 code = " + code + " msg = " + msg);
|
||||
return;
|
||||
}
|
||||
Log.e(TAG, "购买商品" + skuDetails.toString());
|
||||
}
|
||||
|
||||
private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() {
|
||||
@Override
|
||||
public void onPurchasesUpdated(@NonNull BillingResult billingResult, @Nullable List<Purchase> list) {
|
||||
int code = billingResult.getResponseCode();
|
||||
String msg = billingResult.getDebugMessage();
|
||||
Log.e(TAG, "onPurchasesUpdated:code = " + code + " msg = " + msg);
|
||||
if (list != null) {
|
||||
for (Purchase purchase : list) {
|
||||
Log.e(TAG, "onPurchasesUpdated:" + purchase.toString());
|
||||
}
|
||||
}
|
||||
if (code == BillingClient.BillingResponseCode.OK && list != null) {
|
||||
consume(list);
|
||||
Log.e(TAG, "支付成功");
|
||||
if (billingListener != null) {
|
||||
billingListener.onPaySuccess(list);
|
||||
}
|
||||
} else if (code == BillingClient.BillingResponseCode.USER_CANCELED) {
|
||||
Log.e(TAG, "支付取消");
|
||||
if (billingListener != null) {
|
||||
billingListener.onPayFailed(code, msg);
|
||||
}
|
||||
} else {
|
||||
if (billingListener != null) {
|
||||
billingListener.onPayFailed(code, msg);
|
||||
}
|
||||
Log.e(TAG, "支付失败:code = " + code + " msg = " + msg);
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
|
||||
//消耗商品
|
||||
public void consume(List<Purchase> list) {
|
||||
if (list == null || list.isEmpty() || billingClient == null) {
|
||||
return;
|
||||
}
|
||||
for (Purchase purchase : list) {
|
||||
billingClient.consumeAsync(ConsumeParams.newBuilder().setPurchaseToken(purchase.getPurchaseToken()).build(), new ConsumeResponseListener() {
|
||||
@Override
|
||||
public void onConsumeResponse(BillingResult billingResult, String purchaseToken) {
|
||||
Log.e(TAG, "onConsumeResponse code = " + billingResult.getResponseCode() + " , msg = " + billingResult.getDebugMessage() + " , purchaseToken = " + purchaseToken);
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品订单
|
||||
*/
|
||||
public void queryPurchasesAsync(PurchasesResponseListener responseListener) {
|
||||
if (billingClient == null) return;
|
||||
//内购商品交易查询
|
||||
//内购商品交易查询
|
||||
QueryPurchasesParams inAppPurchasesQurey = QueryPurchasesParams.newBuilder()
|
||||
.setProductType(BillingClient.ProductType.INAPP)
|
||||
.build();
|
||||
billingClient.queryPurchasesAsync(inAppPurchasesQurey, responseListener);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定义接口返回支付结果
|
||||
*/
|
||||
public interface GoogleBillingListener {
|
||||
void onPaySuccess(List<Purchase> list);
|
||||
|
||||
void onPayFailed(int code, String msg);
|
||||
}
|
||||
|
||||
private GoogleBillingListener billingListener;
|
||||
|
||||
public GoogleBillingUtilNew setBillingListener(GoogleBillingListener billingListener) {
|
||||
this.billingListener = billingListener;
|
||||
return this;
|
||||
}
|
||||
}
|
@ -4,18 +4,11 @@ import android.app.Activity;
|
||||
import android.content.Context;
|
||||
import android.content.Intent;
|
||||
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
|
||||
import com.shayu.lib_google.utils.GoogleBillingManage;
|
||||
|
||||
import com.alibaba.fastjson.JSON;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.lang.reflect.InvocationHandler;
|
||||
import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.lang.reflect.Proxy;
|
||||
import java.util.Date;
|
||||
import java.util.List;
|
||||
import java.util.Timer;
|
||||
import java.util.TimerTask;
|
||||
|
||||
@ -191,10 +184,42 @@ public class GoogleUtils {
|
||||
googlePay = clz.getConstructor(Activity.class).newInstance(activity);
|
||||
googlePay.getClass().getMethod("initToken").invoke(googlePay);
|
||||
} catch (Exception e) {
|
||||
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
public void queryPurchasesAsync() {
|
||||
try {
|
||||
Class<?> clz = mActivity.getClassLoader().loadClass("com.shayu.lib_google.utils.GoogleBillingManage");
|
||||
googlePay = clz.getConstructor(Activity.class).newInstance(mActivity);
|
||||
googlePay.getClass().getMethod("consumeAll").invoke(googlePay);
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void setQueryPurchaseListener(Activity activity, QueryPurchasesListener queryPurchasesListener) {
|
||||
Timer timer = new Timer();
|
||||
TimerTask task = new TimerTask() {
|
||||
@Override
|
||||
public void run() {
|
||||
try {
|
||||
Class<?> clz = activity.getClassLoader().loadClass("com.shayu.lib_google.utils.GoogleBillingManage");
|
||||
googlePay = clz.getConstructor(Activity.class).newInstance(activity);
|
||||
JSONObject object = (JSONObject) googlePay.getClass().getMethod("getQuerySize").invoke(googlePay);
|
||||
if (object.getInt("querySize") != -1) {
|
||||
queryPurchasesListener.onResult(object);
|
||||
timer.cancel();
|
||||
}
|
||||
} catch (Exception e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
};
|
||||
timer.schedule(task, 10000, 1000);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定义接口返回支付结果
|
||||
@ -209,4 +234,8 @@ public class GoogleUtils {
|
||||
void onResultToken(String token);
|
||||
}
|
||||
|
||||
public interface QueryPurchasesListener {
|
||||
void onResult(JSONObject obj);
|
||||
}
|
||||
|
||||
}
|
||||
|
@ -1,106 +0,0 @@
|
||||
package com.yunbao.common.utils;
|
||||
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 作者:天镜baobao
|
||||
* 时间:2019/6/2 13:51
|
||||
* 说明:允许使用,但请遵循Apache License 2.0
|
||||
* 使用:
|
||||
* Copyright 2019 天镜baobao
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* http://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
public class OnGoogleBillingListener {
|
||||
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public String tag = null;
|
||||
|
||||
/**
|
||||
* 查询成功
|
||||
* @param skuType 内购或者订阅
|
||||
* @param list 商品列表
|
||||
* @param isSelf 是否是当前页面的结果
|
||||
*/
|
||||
public void onQuerySuccess(@NonNull String skuType, @NonNull List<SkuDetails> list, boolean isSelf){}
|
||||
|
||||
/**
|
||||
* 购买成功
|
||||
* @param purchase 商品
|
||||
* @param isSelf 是否是当前页面的结果
|
||||
*
|
||||
// * @return 是否消耗,只有当isSelf为true,并且支付状态为{@link com.android.billingclient.api.Purchase.PurchaseState.PURCHASED}时,该值才会生效。
|
||||
*/
|
||||
public boolean onPurchaseSuccess(@NonNull Purchase purchase, boolean isSelf){return true;}
|
||||
|
||||
/**
|
||||
* 初始化成功
|
||||
* @param isSelf 是否是当前页面的结果
|
||||
*/
|
||||
public void onSetupSuccess(boolean isSelf){}
|
||||
|
||||
/**
|
||||
* 每次启动重新检查订单,返回有效的订单
|
||||
*
|
||||
* @param skuType 内购或者订阅
|
||||
* @param purchase 商品
|
||||
* @param isSelf 是否是当前页面的结果
|
||||
*
|
||||
* @return 是否自动消耗,只有当isSelf为true,并且支付状态为{@link com.android.billingclient.api.Purchase.PurchaseState.PURCHASED}时,该值才会生效。
|
||||
*/
|
||||
public boolean onRecheck(@NonNull String skuType, @NonNull Purchase purchase, boolean isSelf) {
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 链接断开
|
||||
*/
|
||||
@SuppressWarnings("WeakerAccess")
|
||||
public void onBillingServiceDisconnected(){ }
|
||||
|
||||
/**
|
||||
* 消耗成功
|
||||
* @param purchaseToken token
|
||||
* @param isSelf 是否是当前页面的结果
|
||||
*/
|
||||
public void onConsumeSuccess(@NonNull String purchaseToken,boolean isSelf){}
|
||||
|
||||
|
||||
/**
|
||||
* 确认购买成功
|
||||
* @param isSelf 是否是当前页面的结果
|
||||
*/
|
||||
public void onAcknowledgePurchaseSuccess(boolean isSelf){}
|
||||
|
||||
/**
|
||||
* 失败回调
|
||||
* @param tag {@link GoogleBillingUtil.GoogleBillingListenerTag}
|
||||
* @param responseCode 返回码{https://developer.android.com/google/play/billing/billing_reference}
|
||||
* @param isSelf 是否是当前页面的结果
|
||||
*/
|
||||
public void onFail(@NonNull GoogleBillingUtil.GoogleBillingListenerTag tag, int responseCode, boolean isSelf){}
|
||||
|
||||
/**
|
||||
* google组件初始化失败等等。
|
||||
* @param tag {@link GoogleBillingUtil.GoogleBillingListenerTag}
|
||||
* @param isSelf 是否是当前页面的结果
|
||||
*/
|
||||
public void onError(@NonNull GoogleBillingUtil.GoogleBillingListenerTag tag, boolean isSelf){}
|
||||
|
||||
}
|
@ -14,6 +14,7 @@ import android.widget.TextView;
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.core.content.FileProvider;
|
||||
|
||||
import com.alibaba.android.arouter.utils.TextUtils;
|
||||
import com.lxj.xpopup.core.CenterPopupView;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.R;
|
||||
@ -84,25 +85,24 @@ public class APKUpdateCustomPopup extends CenterPopupView {
|
||||
updateLine.setVisibility(GONE);
|
||||
updateText.setText(APKManager.get().getAPKDes());
|
||||
ViewClicksAntiShake.clicksAntiShake(findViewById(R.id.dialog_close), new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
if (mInside) {
|
||||
dismiss();
|
||||
} else {
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY == 1 && APKManager.get().getAPKGoogleIsUp() != 1) {
|
||||
dismiss();
|
||||
}
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY == 2 && APKManager.get().getAPKGoogleIsUp() != 1) {
|
||||
dismiss();
|
||||
}
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY == 0 && APKManager.get().getApkIsUp() != 1) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
if (mInside) {
|
||||
dismiss();
|
||||
} else {
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY == 1 && APKManager.get().getAPKGoogleIsUp() != 1) {
|
||||
dismiss();
|
||||
}
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY == 2 && APKManager.get().getAPKGoogleIsUp() != 1) {
|
||||
dismiss();
|
||||
}
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY == 0 && APKManager.get().getApkIsUp() != 1) {
|
||||
dismiss();
|
||||
}
|
||||
}
|
||||
);
|
||||
|
||||
}
|
||||
});
|
||||
ViewClicksAntiShake.clicksAntiShake(versionImmediateUse, new ViewClicksAntiShake.ViewClicksCallBack() {
|
||||
@Override
|
||||
public void onViewClicks() {
|
||||
@ -114,7 +114,7 @@ public class APKUpdateCustomPopup extends CenterPopupView {
|
||||
} else if (CommonAppConfig.IS_GOOGLE_PLAY == 2) {
|
||||
//华为
|
||||
//todo
|
||||
|
||||
launchAppDetail(mContext, "com.pdlive.shayu", "com.pdlive.shayu");
|
||||
} else {
|
||||
versionImmediateUse.setVisibility(GONE);
|
||||
updateLine.setVisibility(VISIBLE);
|
||||
@ -129,13 +129,30 @@ public class APKUpdateCustomPopup extends CenterPopupView {
|
||||
});
|
||||
}
|
||||
|
||||
public static void launchAppDetail(Context mContext, String appPkg, String marketPkg) {
|
||||
try {
|
||||
if (TextUtils.isEmpty(appPkg)) {
|
||||
return;
|
||||
}
|
||||
|
||||
Uri uri = Uri.parse("market://details?id=" + appPkg);
|
||||
Intent intent = new Intent(Intent.ACTION_VIEW, uri);
|
||||
if (!TextUtils.isEmpty(marketPkg)) {
|
||||
intent.setPackage(marketPkg);
|
||||
}
|
||||
intent.addFlags(Intent.FLAG_ACTIVITY_NEW_TASK);
|
||||
mContext.startActivity(intent);
|
||||
} catch (Exception e) {
|
||||
e.printStackTrace();
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
public void downloadAPK(Activity context, String url, APKDownloadUtil.OnUpdateListener listener) {
|
||||
Request request = new Request.Builder().url(url)
|
||||
.addHeader("Accept-Encoding", "identity").build();
|
||||
Request request = new Request.Builder().url(url).addHeader("Accept-Encoding", "identity").build();
|
||||
File downloadFile = new File(context.getCacheDir(), "update_app.apk");
|
||||
try {
|
||||
if (!downloadFile.exists()
|
||||
&& !downloadFile.createNewFile()) {
|
||||
if (!downloadFile.exists() && !downloadFile.createNewFile()) {
|
||||
return;
|
||||
}
|
||||
} catch (IOException e) {
|
||||
@ -158,8 +175,7 @@ public class APKUpdateCustomPopup extends CenterPopupView {
|
||||
Looper.prepare();
|
||||
byte[] buf = new byte[2048];
|
||||
int len;
|
||||
try (InputStream inputStream = response.body().byteStream();
|
||||
FileOutputStream outputStream = new FileOutputStream(downloadFile)) {
|
||||
try (InputStream inputStream = response.body().byteStream(); FileOutputStream outputStream = new FileOutputStream(downloadFile)) {
|
||||
long total = response.body().contentLength();
|
||||
long sum = 0;
|
||||
while ((len = inputStream.read(buf)) != -1) {
|
||||
|
@ -23,6 +23,6 @@ android.enableJetifier=true
|
||||
|
||||
systemProp.http.proxyHost=127.0.0.1
|
||||
systemProp.https.proxyHost=127.0.0.1
|
||||
systemProp.https.proxyPort=49528
|
||||
systemProp.http.proxyPort=49528
|
||||
systemProp.https.proxyPort=65471
|
||||
systemProp.http.proxyPort=65471
|
||||
#android.enableR8.fullMode=true
|
2
lib_country_code/proguard-rules.pro
vendored
2
lib_country_code/proguard-rules.pro
vendored
@ -22,4 +22,4 @@
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
#-renamesourcefileattribute SourceFiles
|
||||
|
@ -34,4 +34,5 @@ dependencies {
|
||||
api 'com.google.android.gms:play-services-auth:15.0.0'
|
||||
api 'com.google.android.gms:play-services-ads-identifier:15.0.1'
|
||||
api 'com.google.firebase:firebase-messaging:23.0.6'
|
||||
api 'cn.rongcloud.sdk:sight:5.2.5.4'
|
||||
}
|
11
lib_google/proguard-rules.pro
vendored
11
lib_google/proguard-rules.pro
vendored
@ -18,4 +18,13 @@
|
||||
|
||||
# If you keep the line number information, uncomment this to
|
||||
# hide the original source file name.
|
||||
#-renamesourcefileattribute SourceFile
|
||||
#-renamesourcefileattribute SourceFile
|
||||
-ignorewarnings
|
||||
-keepattributes *Annotation*
|
||||
-keepattributes Exceptions
|
||||
-keepattributes InnerClasses
|
||||
-keepattributes Signature
|
||||
-keepattributes SourceFile,LineNumberTable
|
||||
-keep class com.huawei.hianalytics.**{*;}
|
||||
-keep class com.huawei.updatesdk.**{*;}
|
||||
-keep class com.huawei.hms.**{*;}
|
@ -11,6 +11,9 @@ import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.FirebaseApp;
|
||||
import com.google.firebase.messaging.FirebaseMessaging;
|
||||
|
||||
import io.rong.push.PushManager;
|
||||
import io.rong.push.PushType;
|
||||
|
||||
public class FirebaseManage {
|
||||
private Activity mActivity;
|
||||
private Context mContext;
|
||||
@ -41,6 +44,8 @@ public class FirebaseManage {
|
||||
token = task.getResult();
|
||||
// Log and toast
|
||||
Log.d("TAG", token);
|
||||
|
||||
PushManager.getInstance().onReceiveToken(mActivity, PushType.GOOGLE_FCM, token);
|
||||
}
|
||||
});
|
||||
}
|
||||
|
@ -24,6 +24,7 @@ import com.google.android.gms.ads.identifier.AdvertisingIdClient;
|
||||
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
|
||||
import com.google.android.gms.common.GooglePlayServicesRepairableException;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
@ -32,6 +33,7 @@ import java.lang.reflect.InvocationTargetException;
|
||||
import java.lang.reflect.Method;
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
|
||||
/**
|
||||
* 新写Google内付工具类做简单的封装
|
||||
@ -118,13 +120,50 @@ public class GoogleBillingManage implements PurchasesUpdatedListener {
|
||||
}
|
||||
}
|
||||
|
||||
int querySize = -1;
|
||||
JSONArray tokenList = new JSONArray();
|
||||
JSONArray orderList = new JSONArray();
|
||||
String tradeNo = "";
|
||||
|
||||
public JSONObject getQuerySize() {
|
||||
JSONObject object = new JSONObject();
|
||||
try {
|
||||
object.put("querySize", querySize);
|
||||
object.put("tokenList", tokenList);
|
||||
object.put("orderList", orderList);
|
||||
object.put("tradeNo", tradeNo);
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
return object;
|
||||
}
|
||||
|
||||
/**
|
||||
* 消耗所有商品
|
||||
*/
|
||||
public void consumeAll() {
|
||||
queryPurchasesAsync(new PurchasesResponseListener() {
|
||||
@Override
|
||||
public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List<Purchase> list) {
|
||||
querySize = list.size();
|
||||
if (querySize > 0) {
|
||||
tradeNo = list.get(0).getProducts().get(0);
|
||||
for (Purchase purchase : list) {
|
||||
tokenList.put(purchase.getPurchaseToken());
|
||||
orderList.put(purchase.getOrderId());
|
||||
}
|
||||
consume(list);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
/**
|
||||
* 查询商品订单
|
||||
*/
|
||||
public void queryPurchasesAsync(PurchasesResponseListener responseListener) {
|
||||
if (billingClient == null) return;
|
||||
//内购商品交易查询
|
||||
//内购商品交易查询
|
||||
QueryPurchasesParams inAppPurchasesQurey = QueryPurchasesParams.newBuilder().setProductType(BillingClient.ProductType.INAPP).build();
|
||||
billingClient.queryPurchasesAsync(inAppPurchasesQurey, responseListener);
|
||||
}
|
||||
@ -196,6 +235,7 @@ public class GoogleBillingManage implements PurchasesUpdatedListener {
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 定义接口返回支付结果
|
||||
*/
|
||||
@ -211,4 +251,6 @@ public class GoogleBillingManage implements PurchasesUpdatedListener {
|
||||
this.billingListener = billingListener;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
|
@ -110,7 +110,7 @@ public class EntryActivity extends AppCompatActivity {
|
||||
private ImageView btn_phone, btn_line, btn_twitter;
|
||||
private TextView btn_tip, btn_tip1, tv_customer;
|
||||
private TwitterLoginButton tt_login_button;
|
||||
private LinearLayout btn_google;
|
||||
private LinearLayout btn_google, googleLayout;
|
||||
public static Activity activity;
|
||||
private static String mLoginType = Constants.MOB_PHONE;//登录方式
|
||||
public String mPromoCode = "", UserID = "";//推广码
|
||||
@ -169,6 +169,7 @@ public class EntryActivity extends AppCompatActivity {
|
||||
}
|
||||
}
|
||||
|
||||
@SuppressLint("MissingInflatedId")
|
||||
@Override
|
||||
protected void onCreate(Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
@ -184,6 +185,12 @@ public class EntryActivity extends AppCompatActivity {
|
||||
activity = this;
|
||||
Contexts = this;
|
||||
setStatusBar();
|
||||
googleLayout = findViewById(R.id.googleLayout);
|
||||
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY == 2) {
|
||||
googleLayout.setVisibility(View.GONE);
|
||||
}
|
||||
|
||||
lt_btn_facebook = findViewById(R.id.lt_btn_facebook);
|
||||
lt_btn_twitter = findViewById(R.id.lt_btn_twitter);
|
||||
btn_tip = findViewById(R.id.btn_tip);
|
||||
|
@ -38,9 +38,6 @@ import androidx.viewpager.widget.ViewPager;
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.alibaba.fastjson.JSON;
|
||||
import com.alibaba.fastjson.JSONObject;
|
||||
import com.google.android.gms.tasks.OnCompleteListener;
|
||||
import com.google.android.gms.tasks.Task;
|
||||
import com.google.firebase.messaging.FirebaseMessaging;
|
||||
import com.google.gson.Gson;
|
||||
import com.google.gson.reflect.TypeToken;
|
||||
import com.jakewharton.rxbinding3.view.RxView;
|
||||
@ -751,10 +748,8 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
|
||||
} else {
|
||||
ToastUtil.show("正在初始化,請稍等....");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* 检查版本更新
|
||||
*/
|
||||
|
@ -18,10 +18,6 @@ import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.alibaba.android.arouter.facade.annotation.Route;
|
||||
import com.android.billingclient.api.BillingResult;
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.android.billingclient.api.PurchasesResponseListener;
|
||||
import com.google.gson.Gson;
|
||||
import com.umeng.analytics.MobclickAgent;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.activity.AbsActivity;
|
||||
@ -30,7 +26,7 @@ import com.yunbao.common.http.CommonHttpUtil;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.manager.IMLoginManager;
|
||||
import com.yunbao.common.pay.hw.HwBuilder;
|
||||
import com.yunbao.common.utils.GoogleBillingUtilNew;
|
||||
import com.yunbao.common.utils.GoogleUtils;
|
||||
import com.yunbao.common.utils.RouteUtil;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.main.R;
|
||||
@ -47,9 +43,11 @@ import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTit
|
||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
|
||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;
|
||||
|
||||
import org.json.JSONArray;
|
||||
import org.json.JSONException;
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
@ -62,7 +60,7 @@ public class MyWalletActivity extends AbsActivity {
|
||||
public static String orderId;
|
||||
|
||||
HwBuilder hwBuilder;
|
||||
|
||||
GoogleUtils googleUtils;
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
@ -76,7 +74,10 @@ public class MyWalletActivity extends AbsActivity {
|
||||
mw = MyWalletActivity.this;
|
||||
setTitle(mContext.getString(R.string.wallet));
|
||||
|
||||
GoogleBillingUtilNew.getInstance().initGooglePay(mContext);
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY == 1) {
|
||||
googleUtils = new GoogleUtils(mContext);
|
||||
googleUtils.initGooglePay();
|
||||
}
|
||||
|
||||
hwBuilder = new HwBuilder(MyWalletActivity.this);
|
||||
|
||||
@ -92,37 +93,49 @@ public class MyWalletActivity extends AbsActivity {
|
||||
loadingDialog.setShowText(getString(R.string.order_query));
|
||||
|
||||
if (CommonAppConfig.IS_GOOGLE_PLAY == 1) {
|
||||
GoogleBillingUtilNew.getInstance().queryPurchasesAsync(new PurchasesResponseListener() {
|
||||
@Override
|
||||
public void onQueryPurchasesResponse(@NonNull BillingResult billingResult, @NonNull List<Purchase> list) {
|
||||
if (list.size() == 0) {
|
||||
loadingDialog.setShowText(getString(R.string.order_query_success));
|
||||
payHandler.postDelayed(() -> loadingDialog.dismiss(), 2000);
|
||||
} else {
|
||||
loadingDialog.setShowText(getString(R.string.order_query));
|
||||
//消费订单
|
||||
GoogleBillingUtilNew.getInstance().consume(list);
|
||||
for (int i = 0; i < list.size(); i++) {
|
||||
int finalI = i;
|
||||
payHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//谷歌掉单处理
|
||||
CommonHttpUtil.Google_sec_pay(list.get(finalI).getPurchaseToken(), list.get(finalI).getOrderId(), list.get(finalI).getProducts().get(0), new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if (finalI == list.size() - 1) {
|
||||
loadingDialog.setShowText(getString(R.string.order_query_success));
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
ToastUtil.show("充值已到账");
|
||||
finish();
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
googleUtils.queryPurchasesAsync();
|
||||
googleUtils.setQueryPurchaseListener(mContext, new GoogleUtils.QueryPurchasesListener() {
|
||||
@Override
|
||||
public void onResult(JSONObject obj) {
|
||||
try {
|
||||
int code = obj.getInt("querySize");
|
||||
if (code == 0) {
|
||||
loadingDialog.setShowText(getString(R.string.order_query_success));
|
||||
payHandler.postDelayed(() -> loadingDialog.dismiss(), 2000);
|
||||
} else {
|
||||
|
||||
JSONArray tokenList = obj.getJSONArray("tokenList");
|
||||
JSONArray orderList = obj.getJSONArray("orderList");
|
||||
String tradeNo = obj.getString("tradeNo");
|
||||
|
||||
for (int i = 0; i < tokenList.length(); i++) {
|
||||
int finalI = i;
|
||||
payHandler.post(new Runnable() {
|
||||
@Override
|
||||
public void run() {
|
||||
//谷歌掉单处理
|
||||
try {
|
||||
CommonHttpUtil.Google_sec_pay(tokenList.getString(finalI), orderList.getString(finalI), tradeNo, new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if (finalI == tokenList.length() - 1) {
|
||||
loadingDialog.setShowText(getString(R.string.order_query_success));
|
||||
loadingDialog.dismiss();
|
||||
}
|
||||
ToastUtil.show("充值已到账");
|
||||
finish();
|
||||
}
|
||||
});
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
}
|
||||
} catch (JSONException e) {
|
||||
throw new RuntimeException(e);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
@ -59,6 +59,7 @@
|
||||
</LinearLayout>
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/googleLayout"
|
||||
android:layout_width="match_parent"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_gravity="center"
|
||||
@ -132,7 +133,6 @@
|
||||
<!-- </RelativeLayout>-->
|
||||
|
||||
|
||||
|
||||
<LinearLayout
|
||||
android:id="@+id/lt_login_other"
|
||||
android:layout_width="match_parent"
|
||||
|
Loading…
Reference in New Issue
Block a user