diff --git a/config.gradle b/config.gradle index 144f5ea90..9d17f066f 100644 --- a/config.gradle +++ b/config.gradle @@ -4,7 +4,7 @@ ext { buildToolsVersion: "29.0.2", minSdkVersion : 23, targetSdkVersion : 34, - versionCode : 698, + versionCode : 700, versionName : "6.8.1" ] manifestPlaceholders = [ diff --git a/lib_xiaomi_pay/.gitignore b/lib_xiaomi_pay/.gitignore new file mode 100644 index 000000000..42afabfd2 --- /dev/null +++ b/lib_xiaomi_pay/.gitignore @@ -0,0 +1 @@ +/build \ No newline at end of file diff --git a/lib_xiaomi_pay/build.gradle b/lib_xiaomi_pay/build.gradle new file mode 100644 index 000000000..4c03e1854 --- /dev/null +++ b/lib_xiaomi_pay/build.gradle @@ -0,0 +1,39 @@ +apply plugin: 'com.android.library' +apply from: "../package_config.gradle" + +android { + namespace "com.shayu.lib_xiaomi_pay" + compileSdk rootProject.ext.android.compileSdkVersion + defaultConfig { + + testInstrumentationRunner "androidx.test.runner.AndroidJUnitRunner" + consumerProguardFiles "consumer-rules.pro" + minSdkVersion rootProject.ext.android.minSdkVersion + targetSdkVersion rootProject.ext.android.targetSdkVersion + versionCode rootProject.ext.android.versionCode + versionName rootProject.ext.android.versionName + } + + buildTypes { + release { + minifyEnabled false + proguardFiles getDefaultProguardFile('proguard-android-optimize.txt'), 'proguard-rules.pro' + } + } + compileOptions { + sourceCompatibility JavaVersion.VERSION_18 + targetCompatibility JavaVersion.VERSION_18 + } +} + +dependencies { + implementation rootProject.ext.dependencies["appcompat-androidx"] + + //谷歌内购 + api ' implementation "com.xiaomi.billingclient:billing:1.1.3"' + implementation 'com.android.billingclient:billing:7.1.0' + + //implementation platform('com.google.firebase:firebase-bom:30.5.0') + //implementation 'com.google.firebase:firebase-crashlytics' + +} \ No newline at end of file diff --git a/lib_xiaomi_pay/consumer-rules.pro b/lib_xiaomi_pay/consumer-rules.pro new file mode 100644 index 000000000..e69de29bb diff --git a/lib_xiaomi_pay/proguard-rules.pro b/lib_xiaomi_pay/proguard-rules.pro new file mode 100644 index 000000000..b9e257838 --- /dev/null +++ b/lib_xiaomi_pay/proguard-rules.pro @@ -0,0 +1,30 @@ +# Add project specific ProGuard rules here. +# You can control the set of applied configuration files using the +# proguardFiles setting in build.gradle. +# +# For more details, see +# http://developer.android.com/guide/developing/tools/proguard.html + +# If your project uses WebView with JS, uncomment the following +# and specify the fully qualified class name to the JavaScript interface +# class: +#-keepclassmembers class fqcn.of.javascript.interface.for.webview { +# public *; +#} + +# Uncomment this to preserve the line number information for +# debugging stack traces. +#-keepattributes SourceFile,LineNumberTable + +# If you keep the line number information, uncomment this to +# hide the original source file name. +#-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.**{*;} \ No newline at end of file diff --git a/lib_xiaomi_pay/src/main/AndroidManifest.xml b/lib_xiaomi_pay/src/main/AndroidManifest.xml new file mode 100644 index 000000000..a5918e68a --- /dev/null +++ b/lib_xiaomi_pay/src/main/AndroidManifest.xml @@ -0,0 +1,4 @@ + + + + \ No newline at end of file diff --git a/lib_xiaomi_pay/src/main/java/com/shayu/lib_xiaomi/utils/XiaomiBillingManage.java b/lib_xiaomi_pay/src/main/java/com/shayu/lib_xiaomi/utils/XiaomiBillingManage.java new file mode 100644 index 000000000..d651333d5 --- /dev/null +++ b/lib_xiaomi_pay/src/main/java/com/shayu/lib_xiaomi/utils/XiaomiBillingManage.java @@ -0,0 +1,129 @@ +package com.shayu.lib_xiaomi.utils; + +import android.app.Activity; +import android.content.Context; +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.Purchase; +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.List; + +/** + * 小米支付 + */ +public class XiaomiBillingManage { + private Activity mContext; + private String TAG = "XiaomiBillingManage"; + BillingClient billingClient; + public XiaomiBillingManage(Activity activity) { + this.mContext = activity; + } + /** + * 此监听器可接收应用中所有购买交易的更新 + */ + private PurchasesUpdatedListener purchasesUpdatedListener = new PurchasesUpdatedListener() { + @Override + public void onPurchasesUpdated(BillingResult billingResult, List purchases) { + // To be implemented in a later section. + if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) { + if (purchases != null && purchases.size() > 0) { + //处理购买 + + } + } else if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.USER_CANCELED) { + //支付取消 + } else { + //处理其他响应码 + } + } + }; + + /** + * 连接到Google Play Billing服务 + */ + private final BillingClientStateListener billingClientStateListener = new BillingClientStateListener() { + @Override + public void onBillingServiceDisconnected() { + Log.d("TAG", "onBillingServiceDisconnected"); + } + @Override + public void onBillingSetupFinished(BillingResult billingResult) { + Log.d("TAG", "Service.code : " + billingResult.getResponseCode() + " msg : " + billingResult.getDebugMessage()); + if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) { + } + } + }; + + /** + * 初始化小米支付 + * @param mContext + */ + public void initXiaomiPay(Context mContext) { + billingClient = BillingClient.newBuilder(mContext).setListener(purchasesUpdatedListener).build(); + } + + /** + *建立连接 + */ + public void connectXiaomiPay(){ + billingClient.startConnection(billingClientStateListener); + //billingClient.launchBillingFlow(mContext,) + } + + /** + * 判断服务是否可用 + */ + public boolean isReady(){ + if (billingClient == null) { + return false; + } + return billingClient.isReady(); + } + + public void querySkuList(){ + List skuList = new ArrayList<>(); + skuList.add("Game-10");//以实际业务为准 + SkuDetailsParams.Builder params = SkuDetailsParams.newBuilder(); + params.setSkusList(skuList).setType(BillingClient.SkuType.INAPP); + billingClient.querySkuDetailsAsync(params.build(), + new SkuDetailsResponseListener() { + @Override + public void onSkuDetailsResponse(@NonNull BillingResult billingResult, + @Nullable List list) { + Log.d("TAG", "onSkuDetailsResponse"); + if (billingResult.getResponseCode() == BillingClient.BillingResponseCode.OK) { + if (list != null && list.size() > 0) { + // get list + Log.e("xiaomi_pay",list.get(0).getSubscriptionPeriod()); + + //创建BillingFlowParams对象 + BillingFlowParams params = BillingFlowParams.newBuilder() + .setSkuDetails(list.get(0)) + .setIsOfferPersonalized(true) + .setObfuscatedAccountId("xxx") + .setObfuscatedProfileId("yyy") + .build(); + BillingResult result = billingClient.launchBillingFlow(mContext, params); + + + } + } + } + }); + + + + } +} diff --git a/settings.gradle b/settings.gradle index c759e0b49..b1d023a52 100644 --- a/settings.gradle +++ b/settings.gradle @@ -10,3 +10,4 @@ include ':IAP6Helper' include ':lib_faceunity' //include ':SVGAlibrary' include ':TabLayout' +//include ':lib_xiaomi_pay'