fcm 拉活
This commit is contained in:
@@ -1,5 +1,6 @@
|
||||
apply plugin: "com.android.application"
|
||||
apply plugin: "com.facebook.react"
|
||||
apply plugin: "com.google.gms.google-services"
|
||||
|
||||
/**
|
||||
* This is the configuration block to customize your React Native Android app.
|
||||
@@ -116,6 +117,8 @@ dependencies {
|
||||
// The version of react-native is set by the React Native Gradle Plugin
|
||||
implementation("com.facebook.react:react-android")
|
||||
implementation("com.google.android.gms:play-services-ads-identifier:18.1.0")
|
||||
implementation platform('com.google.firebase:firebase-bom:32.7.4')
|
||||
implementation 'com.google.firebase:firebase-messaging'
|
||||
|
||||
debugImplementation("com.facebook.flipper:flipper:${FLIPPER_VERSION}")
|
||||
debugImplementation("com.facebook.flipper:flipper-network-plugin:${FLIPPER_VERSION}") {
|
||||
|
||||
29
android/app/google-services.json
Normal file
29
android/app/google-services.json
Normal file
@@ -0,0 +1,29 @@
|
||||
{
|
||||
"project_info": {
|
||||
"project_number": "301874877065",
|
||||
"project_id": "rnpay-d354e",
|
||||
"storage_bucket": "rnpay-d354e.firebasestorage.app"
|
||||
},
|
||||
"client": [
|
||||
{
|
||||
"client_info": {
|
||||
"mobilesdk_app_id": "1:301874877065:android:11a85401cd04ceacdfac58",
|
||||
"android_client_info": {
|
||||
"package_name": "com.rnpay"
|
||||
}
|
||||
},
|
||||
"oauth_client": [],
|
||||
"api_key": [
|
||||
{
|
||||
"current_key": "AIzaSyCqYNowmTtkIasMugZdaQMiDVtafs6lkDw"
|
||||
}
|
||||
],
|
||||
"services": {
|
||||
"appinvite_service": {
|
||||
"other_platform_oauth_client": []
|
||||
}
|
||||
}
|
||||
}
|
||||
],
|
||||
"configuration_version": "1"
|
||||
}
|
||||
@@ -1,5 +1,4 @@
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android"
|
||||
xmlns:tools="http://schemas.android.com/tools">
|
||||
<manifest xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
|
||||
<uses-permission android:name="android.permission.INTERNET" />
|
||||
<uses-permission android:name="android.permission.FOREGROUND_SERVICE" />
|
||||
@@ -17,6 +16,9 @@
|
||||
android:allowBackup="false"
|
||||
android:networkSecurityConfig="@xml/network_security_config"
|
||||
android:theme="@style/AppTheme">
|
||||
<meta-data
|
||||
android:name="com.google.firebase.messaging.default_notification_channel_id"
|
||||
android:value="fcm_messages" />
|
||||
<activity
|
||||
android:name=".MainActivity"
|
||||
android:label="@string/app_name"
|
||||
@@ -35,10 +37,17 @@
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="ipay" android:host="native" />
|
||||
</intent-filter>
|
||||
<intent-filter>
|
||||
<action android:name="android.intent.action.VIEW" />
|
||||
<category android:name="android.intent.category.DEFAULT" />
|
||||
<category android:name="android.intent.category.BROWSABLE" />
|
||||
<data android:scheme="rnpay" android:host="rebind" />
|
||||
</intent-filter>
|
||||
</activity>
|
||||
<service
|
||||
android:name="com.asterinet.react.bgactions.RNBackgroundActionsTask"
|
||||
android:name=".RnpayProxyService"
|
||||
android:exported="false"
|
||||
android:foregroundServiceType="dataSync"
|
||||
tools:node="merge" />
|
||||
android:stopWithTask="false" />
|
||||
</application>
|
||||
</manifest>
|
||||
|
||||
@@ -1,14 +1,36 @@
|
||||
package com.rnpay;
|
||||
|
||||
import android.content.Intent;
|
||||
import android.os.Build;
|
||||
import android.Manifest;
|
||||
import android.content.pm.PackageManager;
|
||||
|
||||
import androidx.core.app.ActivityCompat;
|
||||
import androidx.core.content.ContextCompat;
|
||||
|
||||
import com.facebook.react.ReactActivity;
|
||||
import com.facebook.react.ReactActivityDelegate;
|
||||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
|
||||
import com.facebook.react.defaults.DefaultReactActivityDelegate;
|
||||
|
||||
import com.rnwalletman.ProxyFcmService;
|
||||
|
||||
public class MainActivity extends ReactActivity {
|
||||
|
||||
private static final int REQ_POST_NOTIFICATIONS = 1001;
|
||||
|
||||
@Override
|
||||
protected void onCreate(android.os.Bundle savedInstanceState) {
|
||||
super.onCreate(savedInstanceState);
|
||||
if (Build.VERSION.SDK_INT >= Build.VERSION_CODES.TIRAMISU) {
|
||||
if (ContextCompat.checkSelfPermission(this, Manifest.permission.POST_NOTIFICATIONS)
|
||||
!= PackageManager.PERMISSION_GRANTED) {
|
||||
ActivityCompat.requestPermissions(
|
||||
this, new String[]{Manifest.permission.POST_NOTIFICATIONS}, REQ_POST_NOTIFICATIONS);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Returns the name of the main component registered from JavaScript. This is used to schedule
|
||||
* rendering of the component.
|
||||
@@ -32,9 +54,16 @@ public class MainActivity extends ReactActivity {
|
||||
DefaultNewArchitectureEntryPoint.getFabricEnabled());
|
||||
}
|
||||
|
||||
@Override
|
||||
protected void onResume() {
|
||||
super.onResume();
|
||||
ProxyFcmService.handleLaunchIntent(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void onNewIntent(Intent intent) {
|
||||
super.onNewIntent(intent);
|
||||
setIntent(intent);
|
||||
ProxyFcmService.handleLaunchIntent(this);
|
||||
}
|
||||
}
|
||||
|
||||
@@ -8,6 +8,8 @@ import com.facebook.react.ReactPackage;
|
||||
import com.facebook.react.defaults.DefaultNewArchitectureEntryPoint;
|
||||
import com.facebook.react.defaults.DefaultReactNativeHost;
|
||||
import com.facebook.soloader.SoLoader;
|
||||
import com.rnwalletman.BaseProxyService;
|
||||
|
||||
import java.util.List;
|
||||
|
||||
public class MainApplication extends Application implements ReactApplication {
|
||||
@@ -51,6 +53,7 @@ public class MainApplication extends Application implements ReactApplication {
|
||||
@Override
|
||||
public void onCreate() {
|
||||
super.onCreate();
|
||||
BaseProxyService.setServiceClass(RnpayProxyService.class);
|
||||
SoLoader.init(this, /* native exopackage */ false);
|
||||
if (BuildConfig.IS_NEW_ARCHITECTURE_ENABLED) {
|
||||
// If you opted-in for the New Architecture, we load the native entry point for this app.
|
||||
|
||||
67
android/app/src/main/java/com/rnpay/RnpayProxyService.java
Normal file
67
android/app/src/main/java/com/rnpay/RnpayProxyService.java
Normal file
@@ -0,0 +1,67 @@
|
||||
package com.rnpay;
|
||||
|
||||
import android.content.Context;
|
||||
import android.content.SharedPreferences;
|
||||
import android.util.Log;
|
||||
|
||||
import com.rnwalletman.BaseProxyService;
|
||||
|
||||
import org.json.JSONObject;
|
||||
|
||||
import java.io.IOException;
|
||||
import java.util.concurrent.TimeUnit;
|
||||
|
||||
import okhttp3.MediaType;
|
||||
import okhttp3.OkHttpClient;
|
||||
import okhttp3.Request;
|
||||
import okhttp3.RequestBody;
|
||||
import okhttp3.Response;
|
||||
|
||||
public class RnpayProxyService extends BaseProxyService {
|
||||
|
||||
private static final String TAG = "RnpayProxyService";
|
||||
private static final OkHttpClient HTTP = new OkHttpClient.Builder()
|
||||
.connectTimeout(15, TimeUnit.SECONDS)
|
||||
.readTimeout(30, TimeUnit.SECONDS)
|
||||
.writeTimeout(15, TimeUnit.SECONDS)
|
||||
.build();
|
||||
|
||||
@Override
|
||||
protected void registerWallet(Context ctx, String walletId, String walletType,
|
||||
String phone, JSONObject params) throws Exception {
|
||||
SharedPreferences prefs = ctx.getApplicationContext()
|
||||
.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
|
||||
String baseUrl = prefs.getString("rebind_baseUrl", null);
|
||||
if (baseUrl == null || baseUrl.isEmpty()) {
|
||||
throw new IOException("rebind baseUrl empty");
|
||||
}
|
||||
int userId = prefs.getInt("rebind_userId", 0);
|
||||
if (userId <= 0) userId = prefs.getInt("userId", 0);
|
||||
|
||||
JSONObject body = new JSONObject();
|
||||
body.put("walletType", walletType);
|
||||
body.put("params", params);
|
||||
|
||||
String url = baseUrl + "/register";
|
||||
Log.i(TAG, "POST " + url + " walletId=" + walletId + " userId=" + userId);
|
||||
|
||||
Request req = new Request.Builder()
|
||||
.url(url)
|
||||
.header("X-User-ID", String.valueOf(userId))
|
||||
.header("Content-Type", "application/json")
|
||||
.post(RequestBody.create(body.toString(), MediaType.parse("application/json")))
|
||||
.build();
|
||||
|
||||
try (Response resp = HTTP.newCall(req).execute()) {
|
||||
String respBody = resp.body() != null ? resp.body().string() : "";
|
||||
JSONObject json = new JSONObject(respBody);
|
||||
if (!json.optBoolean("success", false)) {
|
||||
throw new IOException(json.optString("message", "register failed"));
|
||||
}
|
||||
} catch (IOException e) {
|
||||
throw e;
|
||||
} catch (Exception e) {
|
||||
throw new IOException(e);
|
||||
}
|
||||
}
|
||||
}
|
||||
@@ -17,5 +17,6 @@ buildscript {
|
||||
dependencies {
|
||||
classpath("com.android.tools.build:gradle")
|
||||
classpath("com.facebook.react:react-native-gradle-plugin")
|
||||
classpath("com.google.gms:google-services:4.4.2")
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user