三星内购调用

This commit is contained in:
hch
2023-12-14 18:28:39 +08:00
23 changed files with 343 additions and 67 deletions

View File

@@ -17,8 +17,6 @@ import android.webkit.WebView;
import androidx.fragment.app.Fragment;
import com.facebook.appevents.AppEventsConstants;
import com.google.android.gms.common.ConnectionResult;
import com.google.android.gms.common.GoogleApiAvailability;
import com.yunbao.common.http.CommonHttpUtil;
import com.yunbao.common.http.HttpCallback;
import com.yunbao.common.utils.GoogleUtils;
@@ -42,8 +40,6 @@ public class GoogleFragment extends Fragment {
GoogleUtils googleUtils;
boolean isGoogleService = true;
public GoogleFragment() {
}
@@ -63,13 +59,8 @@ public class GoogleFragment extends Fragment {
rlWebview = (WebView) view.findViewById(R.id.rlWebview);
Log.e("ttt", url);
rlWebview.loadUrl(url);
// 验证是否已在此设备上安装并启用Google Play服务以及此设备上安装的旧版本是否为此客户端所需的版本
int code = GoogleApiAvailability.getInstance().isGooglePlayServicesAvailable(getActivity());
if (code == ConnectionResult.SUCCESS) {
isGoogleService = true;
// 支持Google服务
initGooglePay();
initGooglePay();
if (googleUtils.getGoogleService()) {
new Thread() {
@Override
public void run() {

View File

@@ -26,6 +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.pay.samsung.SamsungUtil;
import com.yunbao.common.utils.GoogleUtils;
import com.yunbao.common.utils.L;
import com.yunbao.common.utils.RouteUtil;
@@ -64,13 +65,13 @@ public class MyWalletActivity extends AbsActivity {
GoogleUtils googleUtils;
LoadingDialog loadingDialog;
SamsungUtil samsungUtil;
@Override
protected int getLayoutId() {
return R.layout.activity_my_wallet;
}
@Override
protected void main() {
super.main();
@@ -80,9 +81,13 @@ public class MyWalletActivity extends AbsActivity {
if (CommonAppConfig.IS_GOOGLE_PLAY == 1) {
googleUtils = new GoogleUtils(mContext);
googleUtils.initGooglePay();
} else if (CommonAppConfig.IS_GOOGLE_PLAY == 2) {
hwBuilder = new HwBuilder(MyWalletActivity.this);
} else if (CommonAppConfig.IS_GOOGLE_PLAY == 3) {
samsungUtil = SamsungUtil.newInstance(mContext);
samsungUtil.init();
}
hwBuilder = new HwBuilder(MyWalletActivity.this);
vp_content = (ViewPager) findViewById(R.id.vp_content);
TextView rView = (TextView) findViewById(R.id.rView);
@@ -158,6 +163,9 @@ public class MyWalletActivity extends AbsActivity {
HuaWeiFragment huaWeiFragment1 = null;
HuaWeiFragment huaWeiFragment2 = null;
SamsungFragment samsungFragment1 = null;
SamsungFragment samsungFragment2 = null;
final String[] titles = {mContext.getString(R.string.diamond), mContext.getString(R.string.coins), mContext.getString(R.string.golden_beans)};
if (getIntent().getStringExtra("tag") != null) {
Log.i("tss", "首充");
@@ -195,6 +203,23 @@ public class MyWalletActivity extends AbsActivity {
Bundle bundle2 = new Bundle();
bundle2.putString("url", CommonAppConfig.HOST + "/themes/simplebootx/appapi/mall/huaweipaygole.html?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd");
huaWeiFragment2.setArguments(bundle2);
} else if (CommonAppConfig.IS_GOOGLE_PLAY == 3) {
rView.setVisibility(View.VISIBLE);
walletFragment = new WalletFragment();
Bundle bundle = new Bundle();
bundle.putString("url", CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&first_page=1&a=walletbean&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"));
walletFragment.setArguments(bundle);
samsungFragment1 = new SamsungFragment();
Bundle bundle1 = new Bundle();
bundle1.putString("url", CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaycoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd" + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"));
samsungFragment1.setArguments(bundle1);
samsungFragment2 = new SamsungFragment();
Bundle bundle2 = new Bundle();
bundle2.putString("url", CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaygole&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd" + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"));
samsungFragment2.setArguments(bundle2);
} else {
walletFragment = new WalletFragment();
Bundle bundle = new Bundle();
@@ -246,6 +271,21 @@ public class MyWalletActivity extends AbsActivity {
Bundle bundle2 = new Bundle();
bundle2.putString("url", CommonAppConfig.HOST + "/themes/simplebootx/appapi/mall/huaweipaygole.html?uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd");
huaWeiFragment2.setArguments(bundle2);
} else if (CommonAppConfig.IS_GOOGLE_PLAY == 3) {
walletFragment = new WalletFragment();
Bundle bundle = new Bundle();
bundle.putString("url", CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&first_page=1&a=walletbean&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"));
walletFragment.setArguments(bundle);
samsungFragment1 = new SamsungFragment();
Bundle bundle1 = new Bundle();
bundle1.putString("url", CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaycoin&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd" + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"));
samsungFragment1.setArguments(bundle1);
samsungFragment2 = new SamsungFragment();
Bundle bundle2 = new Bundle();
bundle2.putString("url", CommonAppConfig.HOST + "/index.php?g=Appapi&m=Mall&a=googlepaygole&uid=" + CommonAppConfig.getInstance().getUid() + "&token=" + CommonAppConfig.getInstance().getToken() + "&package_name=pd" + "&isZh=" + ((IMLoginManager.get(mContext).getLocaleLanguage() == Locale.SIMPLIFIED_CHINESE) ? "1" : "0"));
samsungFragment2.setArguments(bundle2);
} else {
Log.i("tss", "不是首充");
//链接版本
@@ -271,10 +311,11 @@ public class MyWalletActivity extends AbsActivity {
fragments = new Fragment[]{googleFragment1, googleFragment2, walletFragment};
} else if (CommonAppConfig.IS_GOOGLE_PLAY == 2) {
fragments = new Fragment[]{huaWeiFragment1, huaWeiFragment2, walletFragment};
} else if (CommonAppConfig.IS_GOOGLE_PLAY == 3) {
fragments = new Fragment[]{samsungFragment1, samsungFragment2, walletFragment};
} else {
fragments = new Fragment[]{googleFragment1, googleFragment2, walletFragment};
}
MagicIndicator magicIndicator = (MagicIndicator) findViewById(R.id.magic_indicator);
CommonNavigator commonNavigator = new CommonNavigator(this);
commonNavigator.setAdjustMode(true);

View File

@@ -0,0 +1,121 @@
package com.yunbao.main.activity;
import android.annotation.SuppressLint;
import android.os.Bundle;
import android.os.Handler;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.webkit.JavascriptInterface;
import android.webkit.WebSettings;
import android.webkit.WebView;
import androidx.fragment.app.Fragment;
import com.yunbao.common.pay.samsung.SamsungUtil;
import com.yunbao.common.utils.StringUtil;
import com.yunbao.main.R;
import com.yunbao.main.views.TestWebViewClient;
@SuppressLint("ValidFragment")
public class SamsungFragment extends Fragment {
private long lastClickTime = 0;
private static final long INTERVAL_TIME = 1500;
private View view;
public static String mOrderid, mProductId, MoneyUsds;
private WebView rlWebview;
private String url;
SamsungUtil samsungUtil;
public SamsungFragment() {
}
@Override
public View onCreateView(LayoutInflater inflater, ViewGroup container, Bundle savedInstanceState) {
//通过参数中的布局填充获取对应布局
view = inflater.inflate(R.layout.activity_recharge, container, false);
assert getArguments() != null;
url = getArguments().getString("url");
if (StringUtil.isEmpty(url)) {
Log.e(TAG, "URL为空");
return view;
}
rlWebview = (WebView) view.findViewById(R.id.rlWebview);
Log.e("ttt", url);
rlWebview.loadUrl(url);
initSamsung();
WebSettings webSettings = rlWebview.getSettings();
webSettings.setDomStorageEnabled(true);
webSettings.setTextZoom(100);
webSettings.setUseWideViewPort(true);
webSettings.setJavaScriptEnabled(true); // 是否开启JS支持
webSettings.setJavaScriptCanOpenWindowsAutomatically(true); // 是否允许JS打开新窗口
webSettings.setLoadWithOverviewMode(true); // 缩放至屏幕大小
webSettings.setSupportZoom(true); // 是否支持缩放
webSettings.setBuiltInZoomControls(true); // 是否支持缩放变焦,前提是支持缩放
rlWebview.addJavascriptInterface(new JsInteration(), "androidObject");
TestWebViewClient testWebViewClient = new TestWebViewClient(getActivity(), rlWebview);
rlWebview.setWebViewClient(testWebViewClient);
return view;
}
String TAG = "SamsungPay";
private void initSamsung() {
samsungUtil = new SamsungUtil(getActivity());
samsungUtil.init();
}
private Handler payHandler = new Handler();
//js调用原生
public class JsInteration {
@JavascriptInterface
public void androidNewGoToGooglePay(String ProductId, String OrderNumber, String MoneyUsd) {
long currentTime = System.currentTimeMillis();
if (currentTime - lastClickTime > INTERVAL_TIME) {
mProductId = ProductId;
mOrderid = OrderNumber;
MoneyUsds = MoneyUsd;
SamsungUtil.newInstance(getActivity()).buy(mProductId);
}
lastClickTime = currentTime;
Log.e(TAG, "ProductId" + ProductId + "OrderNumber" + OrderNumber + "MoneyUsd" + MoneyUsd);
}
@JavascriptInterface
public void androidMethodBack() {
getActivity().onBackPressed();
}
@JavascriptInterface
public void androidGoBack() {
getActivity().onBackPressed();
}
}
public void release() {
}
}

View File

@@ -1,6 +1,5 @@
<?xml version="1.0" encoding="utf-8"?>
<LinearLayout xmlns:android="http://schemas.android.com/apk/res/android"
xmlns:app="http://schemas.android.com/apk/res-auto"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:orientation="vertical">
@@ -9,14 +8,15 @@
android:id="@+id/classRecyclerView_top"
android:layout_width="match_parent"
android:layout_height="wrap_content"
android:overScrollMode="never"/>
android:overScrollMode="never" />
<com.yunbao.common.custom.CommonRefreshView
android:id="@+id/refreshView"
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="4dp"
android:layout_marginRight="10dp" />
android:layout_marginRight="10dp"
android:layout_marginBottom="55dp" />
<FrameLayout
android:id="@+id/btn_dismiss"

View File

@@ -11,6 +11,7 @@
android:layout_width="match_parent"
android:layout_height="match_parent"
android:layout_marginLeft="4dp"
android:layout_marginBottom="55dp"
android:layout_marginRight="10dp"/>
</LinearLayout>

View File

@@ -76,9 +76,9 @@
<ImageButton
android:id="@+id/change_batch"
android:layout_width="wrap_content"
android:layout_width="80dp"
android:clickable="true"
android:layout_height="wrap_content"
android:layout_height="30dp"
android:layout_gravity="center_vertical|right"
android:background="@mipmap/icon_cange"
android:focusable="true" />