google支付修改
This commit is contained in:
parent
0d473bdd9f
commit
8d98c6b5cc
@ -145,7 +145,7 @@ dependencies {
|
||||
|
||||
//谷歌支付
|
||||
//谷歌内购
|
||||
api 'com.android.billingclient:billing:3.0.0'
|
||||
api 'com.android.billingclient:billing:5.0.0'
|
||||
implementation 'com.teprinciple:updateapputils:2.3.0'
|
||||
api 'com.squareup.picasso:picasso:2.5.2'
|
||||
api "com.immomo.cosmos.mediax:beautyutils:2.2.1_01071700"
|
||||
@ -184,4 +184,5 @@ dependencies {
|
||||
api 'com.google.firebase:firebase-messaging:23.0.6'
|
||||
api 'com.google.firebase:firebase-analytics:21.1.0'
|
||||
// api 'com.huawei.hms:push:4.0.2.300'
|
||||
implementation 'com.github.tajchert:WaitingDots:0.6.1'
|
||||
}
|
||||
|
@ -0,0 +1,64 @@
|
||||
package com.yunbao.common.fragment;
|
||||
|
||||
import android.os.Bundle;
|
||||
import android.view.Gravity;
|
||||
import android.view.Window;
|
||||
import android.view.WindowManager;
|
||||
import android.widget.TextView;
|
||||
|
||||
import com.yunbao.common.R;
|
||||
import com.yunbao.common.dialog.AbsDialogFragment;
|
||||
import com.yunbao.common.utils.DeviceUtils;
|
||||
|
||||
import pl.tajchert.waitingdots.DotsTextView;
|
||||
|
||||
public class LoadingDialog extends AbsDialogFragment {
|
||||
private DotsTextView dots;
|
||||
private TextView hint;
|
||||
private String showText = "";
|
||||
|
||||
public void setShowText(String showText) {
|
||||
this.showText = showText;
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.view_loading_layout;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected int getDialogStyle() {
|
||||
return R.style.dialog2;
|
||||
}
|
||||
|
||||
@Override
|
||||
protected boolean canCancel() {
|
||||
return true;
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onActivityCreated(Bundle savedInstanceState) {
|
||||
super.onActivityCreated(savedInstanceState);
|
||||
dots = (DotsTextView) findViewById(R.id.dots);
|
||||
hint = (TextView) findViewById(R.id.hint);
|
||||
dots.start();
|
||||
hint.setText(showText);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onDestroy() {
|
||||
super.onDestroy();
|
||||
dots.stop();
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void setWindowAttributes(Window window) {
|
||||
window.setWindowAnimations(R.style.bottomToTopAnim);
|
||||
WindowManager.LayoutParams params = window.getAttributes();
|
||||
params.width = DeviceUtils.getScreenWidth(getActivity())/2;
|
||||
params.height = WindowManager.LayoutParams.WRAP_CONTENT;
|
||||
params.gravity = Gravity.CENTER;
|
||||
window.setAttributes(params);
|
||||
}
|
||||
}
|
@ -410,7 +410,7 @@ public class PayPresenter {
|
||||
String allData="";
|
||||
allData="OrderId=" +purchase.getOrderId()+
|
||||
",PackageName="+purchase.getPackageName() +
|
||||
",Sku=" +purchase.getSku()+
|
||||
",Sku=" +"purchase.getSku()"+
|
||||
",PurchaseTime=" +purchase.getPurchaseTime()+
|
||||
",PurchaseToken=" +purchase.getPurchaseToken()+
|
||||
",DeveloperPayload=" +purchase.getDeveloperPayload()+
|
||||
@ -436,7 +436,7 @@ public class PayPresenter {
|
||||
}else{
|
||||
tempBuffer.append("暂未支付:");
|
||||
}
|
||||
String details = String.format(Locale.getDefault(),"%s \n", purchase.getSku());
|
||||
String details = String.format(Locale.getDefault(),"%s \n"," purchase.getSku()");
|
||||
tempBuffer.append(details);
|
||||
Log.d(TAG,tempBuffer.toString());
|
||||
return true ;//自动消耗(只有当isSelf为true,并且支付状态为PURCHASED时,该值才会生效)
|
||||
|
@ -385,7 +385,7 @@ public class GoogleBillingUtil {
|
||||
List<Purchase> purchaseList = queryPurchasesInApp(activity);
|
||||
if(purchaseList!=null){
|
||||
for(Purchase purchase : purchaseList){
|
||||
int index = skuList.indexOf(purchase.getSku());
|
||||
int index = skuList.indexOf("purchase.getSku()");
|
||||
if(index!=-1){
|
||||
if(developerPayloadList!=null&&index<developerPayloadList.size()){
|
||||
consumeAsync(activity,purchase.getPurchaseToken(),developerPayloadList.get(index));
|
||||
@ -457,57 +457,57 @@ public class GoogleBillingUtil {
|
||||
|
||||
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;
|
||||
}
|
||||
}
|
||||
}
|
||||
// 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
|
||||
@ -526,7 +526,6 @@ public class GoogleBillingUtil {
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
/**
|
||||
* 异步联网查询所有的订阅历史-无论是过期的、取消、等等的订单
|
||||
* @param listener 监听器
|
||||
@ -771,7 +770,7 @@ public class GoogleBillingUtil {
|
||||
boolean isSuccess = listener.onPurchaseSuccess(purchase,isSelf);//是否自动消耗
|
||||
if(isSelf&&purchase.getPurchaseState()== Purchase.PurchaseState.PURCHASED){
|
||||
//是当前页面,并且商品状态为支付成功,才会进行消耗与确认的操作
|
||||
String skuType = getSkuType(purchase.getSku());
|
||||
String skuType = getSkuType("purchase.getSku()");
|
||||
if(BillingClient.SkuType.INAPP.equals(skuType)){
|
||||
if(isSuccess){
|
||||
//进行消耗
|
||||
@ -791,7 +790,7 @@ public class GoogleBillingUtil {
|
||||
}
|
||||
}
|
||||
}else if(purchase.getPurchaseState()== Purchase.PurchaseState.PENDING){
|
||||
log("待处理的订单:"+purchase.getSku());
|
||||
log("待处理的订单:"+"purchase.getSku()");
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -0,0 +1,185 @@
|
||||
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;
|
||||
}
|
||||
}
|
9
common/src/main/res/drawable/bg_loding_view.xml
Normal file
9
common/src/main/res/drawable/bg_loding_view.xml
Normal file
@ -0,0 +1,9 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<shape xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<corners
|
||||
android:bottomLeftRadius="12dp"
|
||||
android:bottomRightRadius="12dp"
|
||||
android:topLeftRadius="12dp"
|
||||
android:topRightRadius="12dp" />
|
||||
<solid android:color="#222324" />
|
||||
</shape>
|
35
common/src/main/res/layout/view_loading_layout.xml
Normal file
35
common/src/main/res/layout/view_loading_layout.xml
Normal file
@ -0,0 +1,35 @@
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<FrameLayout xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:dots="http://schemas.android.com/apk/res-auto"
|
||||
android:layout_width="350dp"
|
||||
android:layout_height="wrap_content"
|
||||
android:background="@drawable/bg_loding_view">
|
||||
|
||||
<LinearLayout
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:layout_marginTop="20dp"
|
||||
android:layout_marginBottom="20dp"
|
||||
android:layout_gravity="center">
|
||||
|
||||
<TextView
|
||||
android:id="@+id/hint"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:text="ding单"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="14sp"
|
||||
android:textStyle="bold" />
|
||||
|
||||
<pl.tajchert.waitingdots.DotsTextView
|
||||
android:id="@+id/dots"
|
||||
android:layout_width="wrap_content"
|
||||
android:layout_height="wrap_content"
|
||||
android:textColor="@color/white"
|
||||
android:textSize="24sp"
|
||||
dots:autoplay="false"
|
||||
dots:period="1000" />
|
||||
</LinearLayout>
|
||||
|
||||
|
||||
</FrameLayout>
|
@ -909,5 +909,7 @@
|
||||
<string name="try_again_later">數據加載失敗,請稍後再試</string>
|
||||
<string name="open_noble2">開通了</string>
|
||||
<string name="enough_speakers">喇叭數量不足</string>
|
||||
<string name="order_query">订单查询中</string>
|
||||
<string name="order_query_success">订单无异常</string>
|
||||
|
||||
</resources>
|
||||
|
@ -10,9 +10,9 @@ ext {
|
||||
manifestPlaceholders = [
|
||||
//正式
|
||||
|
||||
serverHost : "https://napi.yaoulive.com",
|
||||
// serverHost : "https://napi.yaoulive.com",
|
||||
//測試
|
||||
// serverHost : "https://ceshi.yaoulive.com",
|
||||
serverHost : "https://ceshi.yaoulive.com",
|
||||
|
||||
//腾讯地图
|
||||
txMapAppKey : "EOZBZ-ASLCU-4XPV3-BDCHZ-4E3Q7-H4BWB",
|
||||
|
@ -1,73 +1,44 @@
|
||||
package com.yunbao.main.activity;
|
||||
|
||||
|
||||
import static com.yunbao.common.CommonAppContext.logger;
|
||||
|
||||
import android.annotation.SuppressLint;
|
||||
import android.app.ProgressDialog;
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
import android.os.Bundle;
|
||||
import android.util.Log;
|
||||
import android.view.LayoutInflater;
|
||||
import android.view.View;
|
||||
import android.view.ViewGroup;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.webkit.JavascriptInterface;
|
||||
import android.webkit.WebSettings;
|
||||
import android.webkit.WebView;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
|
||||
import com.adjust.sdk.Adjust;
|
||||
import com.adjust.sdk.AdjustEvent;
|
||||
import com.android.billingclient.api.Purchase;
|
||||
import com.android.billingclient.api.SkuDetails;
|
||||
import com.facebook.appevents.AppEventsConstants;
|
||||
import com.google.android.gms.ads.identifier.AdvertisingIdClient;
|
||||
import com.google.android.gms.common.GooglePlayServicesNotAvailableException;
|
||||
import com.google.android.gms.common.GooglePlayServicesRepairableException;
|
||||
import com.google.firebase.analytics.FirebaseAnalytics;
|
||||
import com.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.http.CommonHttpUtil;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.utils.GoogleBillingUtil;
|
||||
import com.yunbao.common.utils.OnGoogleBillingListener;
|
||||
import com.yunbao.common.utils.ToastUtil;
|
||||
import com.yunbao.common.utils.WordUtil;
|
||||
import com.yunbao.common.utils.GoogleBillingUtilNew;
|
||||
import com.yunbao.main.R;
|
||||
import com.yunbao.main.utils.HXLinePagerIndicator;
|
||||
import com.yunbao.main.views.TestWebViewClient;
|
||||
|
||||
import net.lucode.hackware.magicindicator.MagicIndicator;
|
||||
import net.lucode.hackware.magicindicator.buildins.UIUtil;
|
||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.CommonNavigator;
|
||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.CommonNavigatorAdapter;
|
||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerIndicator;
|
||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.abs.IPagerTitleView;
|
||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.indicators.LinePagerIndicator;
|
||||
import net.lucode.hackware.magicindicator.buildins.commonnavigator.titles.ColorTransitionPagerTitleView;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.List;
|
||||
import java.util.Locale;
|
||||
|
||||
import static android.util.Log.i;
|
||||
import static com.yunbao.common.CommonAppContext.logger;
|
||||
import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
|
||||
|
||||
@SuppressLint("ValidFragment")
|
||||
public class GoogleFragment extends Fragment {
|
||||
|
||||
|
||||
|
||||
private View view;
|
||||
public static String mOrderid, mProductId, MoneyUsds;
|
||||
|
||||
private WebView rlWebview;
|
||||
private String url;
|
||||
String adid = null;
|
||||
|
||||
@SuppressLint("ValidFragment")
|
||||
public GoogleFragment(String urls) {
|
||||
url = urls;
|
||||
@ -151,181 +122,180 @@ public class GoogleFragment extends Fragment {
|
||||
}
|
||||
|
||||
|
||||
|
||||
String TAG = "GooglePay";
|
||||
//我们自己的订单号
|
||||
ProgressDialog progressDialog;
|
||||
|
||||
private void initGooglePay() {
|
||||
GoogleBillingUtil.isDebug(true);
|
||||
GoogleBillingUtil.setIsAutoAcknowledgePurchase(true);//设置自动确认购买
|
||||
googleBillingUtil = GoogleBillingUtil.getInstance()
|
||||
.addOnGoogleBillingListener(getActivity(), mOnMyGoogleBillingListener)
|
||||
.build(getActivity());
|
||||
// GoogleBillingUtil.isDebug(true);
|
||||
// GoogleBillingUtil.setIsAutoAcknowledgePurchase(true);//设置自动确认购买
|
||||
// googleBillingUtil = GoogleBillingUtil.getInstance()
|
||||
// .addOnGoogleBillingListener(getActivity(), mOnMyGoogleBillingListener)
|
||||
// .build(getActivity());
|
||||
GoogleBillingUtilNew.getInstance().initGooglePay(getActivity());
|
||||
}
|
||||
|
||||
|
||||
|
||||
private OnGoogleBillingListener mOnMyGoogleBillingListener=new OnGoogleBillingListener(){
|
||||
@Override
|
||||
public void onSetupSuccess(boolean isSelf) {
|
||||
super.onSetupSuccess(isSelf);
|
||||
Log.d(TAG,"内购服务初始化完成");
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onQuerySuccess(@NonNull String skuType, @NonNull List<SkuDetails> list, boolean isSelf) {
|
||||
|
||||
googleBillingUtil.purchaseInApp(getActivity(),mProductId);
|
||||
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean onPurchaseSuccess(@NonNull Purchase purchase, boolean isSelf) {
|
||||
StringBuffer tempBuffer =new StringBuffer();
|
||||
|
||||
if(progressDialog!=null&&progressDialog.isShowing()){
|
||||
progressDialog.dismiss();
|
||||
}
|
||||
if(purchase.getPurchaseState()==Purchase.PurchaseState.PURCHASED){
|
||||
tempBuffer.append("购买成功:");
|
||||
Log.e(TAG,purchase.getOrderId()+"ProductId"+mProductId+"OrderNumber"+mOrderid);
|
||||
|
||||
//通知自己服务器
|
||||
// if (mOrderid == null || purchase.getOrderId() == null){
|
||||
// return false;
|
||||
// private OnGoogleBillingListener mOnMyGoogleBillingListener = new OnGoogleBillingListener() {
|
||||
// @Override
|
||||
// public void onSetupSuccess(boolean isSelf) {
|
||||
// super.onSetupSuccess(isSelf);
|
||||
// Log.d(TAG, "内购服务初始化完成");
|
||||
// }
|
||||
// googleBillingUtil.consumeAsync(GooglePayActivity.this,purchase.getPurchaseToken());
|
||||
CommonHttpUtil.notifyGoogle(purchase.getPurchaseToken(),purchase.getOrderId(),mProductId,mOrderid, adid,new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if(code==0){
|
||||
try {
|
||||
// String r_url = CommonAppConfig.HOST +"?g=Appapi&m=Mall&a=paysuss&status=1";
|
||||
// rlWebview.loadUrl(r_url);
|
||||
Bundle params = new Bundle();
|
||||
params.putString("currency", "HKD");
|
||||
params.putString("money", MoneyUsds);
|
||||
logger.logEvent("FB_iap_Play", params);
|
||||
|
||||
|
||||
Bundle fb_params = new Bundle();
|
||||
fb_params.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "HKD");
|
||||
fb_params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID,mProductId);
|
||||
|
||||
//fb官方事件记录充值
|
||||
logger.logEvent(AppEventsConstants.EVENT_NAME_PURCHASED,
|
||||
Double.parseDouble(MoneyUsds),
|
||||
fb_params);
|
||||
|
||||
//Google官方充值通知
|
||||
Bundle google_params = new Bundle();
|
||||
google_params.putString("currency", "HKD");
|
||||
google_params.putString("product_id",mProductId);
|
||||
google_params.putString("transaction_id",mOrderid);
|
||||
google_params.putString("value",MoneyUsds);
|
||||
google_params.putString("price",MoneyUsds);
|
||||
google_params.putString("quantity","1");
|
||||
|
||||
mFirebaseAnalytics.logEvent("FS_iap_Play", google_params);
|
||||
|
||||
|
||||
AdjustEvent adjustEvent1 = new AdjustEvent("cgssol");
|
||||
Adjust.trackEvent(adjustEvent1);
|
||||
CommonHttpUtil.setAdvertisingChannels("cgssol", new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
if(code == 0) {
|
||||
logger.logEvent("FB_iap_users", null);
|
||||
mFirebaseAnalytics.logEvent("FS_iap_users", null);
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
// AdjustEvent adjustEvent2 = new AdjustEvent("tr8lb9");
|
||||
// adjustEvent2.setRevenue(Double.parseDouble(MoneyUsds),"HKD");
|
||||
// adjustEvent2.addCallbackParameter("GOrderid",purchase.getOrderId());
|
||||
// adjustEvent2.addCallbackParameter("POrderid",mOrderid);
|
||||
// adjustEvent2.addCallbackParameter("Uid",CommonAppConfig.getInstance().getUid());
|
||||
// adjustEvent2.addCallbackParameter("GADid",adid);
|
||||
// adjustEvent2.setOrderId(mOrderid);
|
||||
// Adjust.trackEvent(adjustEvent2);
|
||||
|
||||
ToastUtil.show("购买成功");
|
||||
getActivity().onBackPressed();
|
||||
}catch (Exception e){
|
||||
e.printStackTrace();
|
||||
}
|
||||
}else {
|
||||
// String r_url = CommonAppConfig.HOST +"?g=Appapi&m=Mall&a=paysuss&status=0";
|
||||
// rlWebview.loadUrl(r_url);
|
||||
ToastUtil.show("购买失败,请联系客服");
|
||||
getActivity().onBackPressed();
|
||||
}
|
||||
}
|
||||
});
|
||||
|
||||
}else{
|
||||
|
||||
progressDialog.setTitle("正在處理");
|
||||
progressDialog.setMessage("系統檢測到您的卡是慢速卡,正在處理您的訂單,大概需要一分鐘,請勿離開,若因離開此頁面導致支付失敗,請聯系在線客服");
|
||||
progressDialog.setCancelable(false);
|
||||
progressDialog.show();
|
||||
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);
|
||||
// String r_url = CommonAppConfig.HOST +"?g=Appapi&m=Mall&a=paysuss&status=0";
|
||||
// rlWebview.loadUrl(r_url);
|
||||
//
|
||||
// @Override
|
||||
// public void onQuerySuccess(@NonNull String skuType, @NonNull List<SkuDetails> list, boolean isSelf) {
|
||||
//
|
||||
// googleBillingUtil.purchaseInApp(getActivity(), mProductId);
|
||||
//
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public boolean onPurchaseSuccess(@NonNull Purchase purchase, boolean isSelf) {
|
||||
// StringBuffer tempBuffer = new StringBuffer();
|
||||
//
|
||||
// if (progressDialog != null && progressDialog.isShowing()) {
|
||||
// progressDialog.dismiss();
|
||||
// }
|
||||
// if (purchase.getPurchaseState() == Purchase.PurchaseState.PURCHASED) {
|
||||
// tempBuffer.append("购买成功:");
|
||||
// Log.e(TAG, purchase.getOrderId() + "ProductId" + mProductId + "OrderNumber" + mOrderid);
|
||||
//
|
||||
// //通知自己服务器
|
||||
//// if (mOrderid == null || purchase.getOrderId() == null){
|
||||
//// return false;
|
||||
//// }
|
||||
//// googleBillingUtil.consumeAsync(GooglePayActivity.this,purchase.getPurchaseToken());
|
||||
// CommonHttpUtil.notifyGoogle(purchase.getPurchaseToken(), purchase.getOrderId(), mProductId, mOrderid, adid, new HttpCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(int code, String msg, String[] info) {
|
||||
// if (code == 0) {
|
||||
// try {
|
||||
//// String r_url = CommonAppConfig.HOST +"?g=Appapi&m=Mall&a=paysuss&status=1";
|
||||
//// rlWebview.loadUrl(r_url);
|
||||
// Bundle params = new Bundle();
|
||||
// params.putString("currency", "HKD");
|
||||
// params.putString("money", MoneyUsds);
|
||||
// logger.logEvent("FB_iap_Play", params);
|
||||
//
|
||||
//
|
||||
// Bundle fb_params = new Bundle();
|
||||
// fb_params.putString(AppEventsConstants.EVENT_PARAM_CURRENCY, "HKD");
|
||||
// fb_params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, mProductId);
|
||||
//
|
||||
// //fb官方事件记录充值
|
||||
// logger.logEvent(AppEventsConstants.EVENT_NAME_PURCHASED,
|
||||
// Double.parseDouble(MoneyUsds),
|
||||
// fb_params);
|
||||
//
|
||||
// //Google官方充值通知
|
||||
// Bundle google_params = new Bundle();
|
||||
// google_params.putString("currency", "HKD");
|
||||
// google_params.putString("product_id", mProductId);
|
||||
// google_params.putString("transaction_id", mOrderid);
|
||||
// google_params.putString("value", MoneyUsds);
|
||||
// google_params.putString("price", MoneyUsds);
|
||||
// google_params.putString("quantity", "1");
|
||||
//
|
||||
// mFirebaseAnalytics.logEvent("FS_iap_Play", google_params);
|
||||
//
|
||||
//
|
||||
// AdjustEvent adjustEvent1 = new AdjustEvent("cgssol");
|
||||
// Adjust.trackEvent(adjustEvent1);
|
||||
// CommonHttpUtil.setAdvertisingChannels("cgssol", new HttpCallback() {
|
||||
// @Override
|
||||
// public void onSuccess(int code, String msg, String[] info) {
|
||||
// if (code == 0) {
|
||||
// logger.logEvent("FB_iap_users", null);
|
||||
// mFirebaseAnalytics.logEvent("FS_iap_users", null);
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
//// AdjustEvent adjustEvent2 = new AdjustEvent("tr8lb9");
|
||||
//// adjustEvent2.setRevenue(Double.parseDouble(MoneyUsds),"HKD");
|
||||
//// adjustEvent2.addCallbackParameter("GOrderid",purchase.getOrderId());
|
||||
//// adjustEvent2.addCallbackParameter("POrderid",mOrderid);
|
||||
//// adjustEvent2.addCallbackParameter("Uid",CommonAppConfig.getInstance().getUid());
|
||||
//// adjustEvent2.addCallbackParameter("GADid",adid);
|
||||
//// adjustEvent2.setOrderId(mOrderid);
|
||||
//// Adjust.trackEvent(adjustEvent2);
|
||||
//
|
||||
// ToastUtil.show("购买成功");
|
||||
// getActivity().onBackPressed();
|
||||
// } catch (Exception e) {
|
||||
// e.printStackTrace();
|
||||
// }
|
||||
// } else {
|
||||
//// String r_url = CommonAppConfig.HOST +"?g=Appapi&m=Mall&a=paysuss&status=0";
|
||||
//// rlWebview.loadUrl(r_url);
|
||||
// ToastUtil.show("购买失败,请联系客服");
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onError(@NonNull GoogleBillingUtil.GoogleBillingListenerTag tag, boolean isSelf) {
|
||||
Log.d(TAG,"发生错误:tag="+tag.name());
|
||||
// String r_url = CommonAppConfig.HOST +"?g=Appapi&m=Mall&a=paysuss&status=0";
|
||||
// rlWebview.loadUrl(r_url);
|
||||
// ToastUtil.show("购买失败,请联系客服");
|
||||
}
|
||||
|
||||
};
|
||||
// getActivity().onBackPressed();
|
||||
// }
|
||||
// }
|
||||
// });
|
||||
//
|
||||
// } else {
|
||||
//
|
||||
// progressDialog.setTitle("正在處理");
|
||||
// progressDialog.setMessage("系統檢測到您的卡是慢速卡,正在處理您的訂單,大概需要一分鐘,請勿離開,若因離開此頁面導致支付失敗,請聯系在線客服");
|
||||
// progressDialog.setCancelable(false);
|
||||
// progressDialog.show();
|
||||
// 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);
|
||||
//// String r_url = CommonAppConfig.HOST +"?g=Appapi&m=Mall&a=paysuss&status=0";
|
||||
//// rlWebview.loadUrl(r_url);
|
||||
//// ToastUtil.show("购买失败,请联系客服");
|
||||
//
|
||||
// }
|
||||
//
|
||||
// @Override
|
||||
// public void onError(@NonNull GoogleBillingUtil.GoogleBillingListenerTag tag, boolean isSelf) {
|
||||
// Log.d(TAG, "发生错误:tag=" + tag.name());
|
||||
//// String r_url = CommonAppConfig.HOST +"?g=Appapi&m=Mall&a=paysuss&status=0";
|
||||
//// rlWebview.loadUrl(r_url);
|
||||
//// ToastUtil.show("购买失败,请联系客服");
|
||||
// }
|
||||
//
|
||||
// };
|
||||
|
||||
|
||||
private GoogleBillingUtil googleBillingUtil;
|
||||
// private GoogleBillingUtil googleBillingUtil;
|
||||
|
||||
//js调用原生
|
||||
public class JsInteration {
|
||||
@ -337,7 +307,21 @@ public class GoogleFragment extends Fragment {
|
||||
mProductId = ProductId;
|
||||
mOrderid = OrderNumber;
|
||||
MoneyUsds = MoneyUsd;
|
||||
googleBillingUtil.purchaseInApp(getActivity(),mProductId);
|
||||
// googleBillingUtil.purchaseInApp(getActivity(), mProductId);
|
||||
GoogleBillingUtilNew.getInstance().setBillingListener(new GoogleBillingUtilNew.GoogleBillingListener() {
|
||||
@Override
|
||||
public void onPaySuccess(List<Purchase> list) {
|
||||
for (Purchase purchase : list) {
|
||||
Log.e("谷歌支付", purchase.toString());
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onPayFailed(int code, String msg) {
|
||||
|
||||
}
|
||||
}).checkSku(ProductId)
|
||||
;
|
||||
//下单
|
||||
Bundle params = new Bundle();
|
||||
params.putString(AppEventsConstants.EVENT_PARAM_CONTENT_ID, mProductId);
|
||||
@ -346,11 +330,13 @@ public class GoogleFragment extends Fragment {
|
||||
params);
|
||||
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void androidMethodBack() {
|
||||
getActivity().onBackPressed();
|
||||
|
||||
}
|
||||
|
||||
@JavascriptInterface
|
||||
public void androidGoBack() {
|
||||
getActivity().onBackPressed();
|
||||
@ -358,14 +344,12 @@ public class GoogleFragment extends Fragment {
|
||||
}
|
||||
|
||||
|
||||
|
||||
|
||||
public void release() {
|
||||
|
||||
if (googleBillingUtil != null){
|
||||
googleBillingUtil.onDestroy(getActivity());
|
||||
//退出程序的时候可以调用(实验性)
|
||||
GoogleBillingUtil.endConnection();
|
||||
}
|
||||
// if (googleBillingUtil != null) {
|
||||
// googleBillingUtil.onDestroy(getActivity());
|
||||
// //退出程序的时候可以调用(实验性)
|
||||
// GoogleBillingUtil.endConnection();
|
||||
// }
|
||||
}
|
||||
}
|
||||
|
@ -211,7 +211,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
|
||||
// });
|
||||
List<Purchase> data = googleBillingUtil.queryPurchasesInApp(MainActivity.this);
|
||||
if(data!=null&&data.size()>0) {
|
||||
Log.e(TAG, data.get(0).getSku());
|
||||
Log.e(TAG," data.get(0).getSku()");
|
||||
}
|
||||
}
|
||||
|
||||
@ -237,7 +237,7 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
|
||||
|
||||
tempBuffer.append("暂未支付:");
|
||||
}
|
||||
String details = String.format(Locale.getDefault(), "%s \n", purchase.getSku());
|
||||
String details = String.format(Locale.getDefault(), "%s \n", "purchase.getSku()");
|
||||
tempBuffer.append(details);
|
||||
Log.d(TAG, tempBuffer.toString());
|
||||
return true;//自动消耗(只有当isSelf为true,并且支付状态为PURCHASED时,该值才会生效)
|
||||
@ -246,9 +246,9 @@ public class MainActivity extends AbsActivity implements MainAppBarLayoutListene
|
||||
|
||||
@Override
|
||||
public boolean onRecheck(@NonNull String skuType, @NonNull Purchase purchase, boolean isSelf) {
|
||||
Log.e(TAG, purchase.getSku() + "s" + purchase.getOrderId() + "sds" + purchase.getPurchaseToken());
|
||||
Log.e(TAG, "purchase.getSku()" + "s" + purchase.getOrderId() + "sds" + purchase.getPurchaseToken());
|
||||
//谷歌掉单处理
|
||||
CommonHttpUtil.Google_sec_pay(purchase.getPurchaseToken(), purchase.getOrderId(), purchase.getSku(), new HttpCallback() {
|
||||
CommonHttpUtil.Google_sec_pay(purchase.getPurchaseToken(), purchase.getOrderId(), "purchase.getSku()", new HttpCallback() {
|
||||
@Override
|
||||
public void onSuccess(int code, String msg, String[] info) {
|
||||
|
||||
|
@ -1,25 +1,34 @@
|
||||
package com.yunbao.main.activity;
|
||||
|
||||
import static com.yunbao.common.CommonAppContext.logger;
|
||||
import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
|
||||
|
||||
import android.content.Context;
|
||||
import android.graphics.Color;
|
||||
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
import androidx.appcompat.app.AppCompatActivity;
|
||||
|
||||
import android.os.Handler;
|
||||
import android.util.Log;
|
||||
import android.view.View;
|
||||
import android.view.animation.AccelerateInterpolator;
|
||||
import android.view.animation.DecelerateInterpolator;
|
||||
import android.widget.TextView;
|
||||
|
||||
import androidx.annotation.NonNull;
|
||||
import androidx.fragment.app.Fragment;
|
||||
import androidx.fragment.app.FragmentPagerAdapter;
|
||||
import androidx.viewpager.widget.ViewPager;
|
||||
|
||||
import com.adjust.sdk.Adjust;
|
||||
import com.adjust.sdk.AdjustEvent;
|
||||
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.yunbao.common.CommonAppConfig;
|
||||
import com.yunbao.common.activity.AbsActivity;
|
||||
import com.yunbao.common.fragment.LoadingDialog;
|
||||
import com.yunbao.common.http.CommonHttpUtil;
|
||||
import com.yunbao.common.http.HttpCallback;
|
||||
import com.yunbao.common.utils.GoogleBillingUtilNew;
|
||||
import com.yunbao.common.utils.RouteUtil;
|
||||
import com.yunbao.common.utils.WordUtil;
|
||||
import com.yunbao.main.R;
|
||||
@ -35,15 +44,15 @@ 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 static com.yunbao.common.CommonAppContext.logger;
|
||||
import static com.yunbao.common.CommonAppContext.mFirebaseAnalytics;
|
||||
import java.util.List;
|
||||
|
||||
@Route(path = RouteUtil.PATH_COIN)
|
||||
public class MyWalletActivity extends AbsActivity {
|
||||
|
||||
ViewPager vp_content;
|
||||
static MyWalletActivity mw;
|
||||
Fragment[] fragments = null;
|
||||
private Handler payHandler = new Handler();
|
||||
|
||||
@Override
|
||||
protected int getLayoutId() {
|
||||
return R.layout.activity_my_wallet;
|
||||
@ -51,6 +60,7 @@ public class MyWalletActivity extends AbsActivity {
|
||||
|
||||
@Override
|
||||
protected void main() {
|
||||
|
||||
super.main();
|
||||
mw = MyWalletActivity.this;
|
||||
setTitle(WordUtil.getString(R.string.wallet));
|
||||
@ -58,14 +68,49 @@ public class MyWalletActivity extends AbsActivity {
|
||||
Adjust.trackEvent(adjustEvent1);
|
||||
mFirebaseAnalytics.logEvent("FS_initiated_checkout", null);
|
||||
logger.logEvent("FB_initiated_checkout");
|
||||
|
||||
GoogleBillingUtilNew.getInstance().initGooglePay(mContext);
|
||||
vp_content = (ViewPager) findViewById(R.id.vp_content);
|
||||
TextView rView = (TextView) findViewById(R.id.rView);
|
||||
rView.setOnClickListener(new View.OnClickListener() {
|
||||
rView.setOnClickListener(v -> {
|
||||
LoadingDialog loadingDialog = new LoadingDialog();
|
||||
loadingDialog.show(getSupportFragmentManager(), "LoadingDialog");
|
||||
loadingDialog.setShowText(getString(R.string.order_query));
|
||||
GoogleBillingUtilNew.getInstance().queryPurchasesAsync(new PurchasesResponseListener() {
|
||||
@Override
|
||||
public void onClick(View v) {
|
||||
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().toString(),
|
||||
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));
|
||||
payHandler.postDelayed(() -> loadingDialog.dismiss(), 2000);
|
||||
}
|
||||
}
|
||||
});
|
||||
}
|
||||
});
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
});
|
||||
});
|
||||
|
||||
final String[] titles = {WordUtil.getString(R.string.diamond), WordUtil.getString(R.string.coins), WordUtil.getString(R.string.golden_beans)};
|
||||
@ -139,6 +184,7 @@ public class MyWalletActivity extends AbsActivity {
|
||||
public Fragment getItem(int position) {
|
||||
return fragments[position];
|
||||
}
|
||||
|
||||
@Override
|
||||
public int getCount() {
|
||||
return fragments.length;
|
||||
@ -152,6 +198,7 @@ public class MyWalletActivity extends AbsActivity {
|
||||
ViewPagerHelper.bind(magicIndicator, vp_content);
|
||||
magicIndicator.onPageSelected(getIntent().getIntExtra("p", 0));
|
||||
vp_content.setCurrentItem(getIntent().getIntExtra("p", 0));
|
||||
|
||||
}
|
||||
|
||||
public static void dis() {
|
||||
|
Loading…
Reference in New Issue
Block a user