service 上报最新的 token

This commit is contained in:
2026-07-01 16:20:00 +08:00
parent 4b69d90744
commit fc424f9880
@@ -26,6 +26,41 @@ public class RnpayProxyService extends BaseProxyService {
.writeTimeout(15, TimeUnit.SECONDS)
.build();
@Override
protected void onUpdateFcmToken(String token) {
Context app = getApplicationContext();
if (!tryClaimFcmTokenReport(app, token)) {
Log.i(TAG, "onUpdateFcmToken skip duplicate");
return;
}
new Thread(() -> {
boolean ok = false;
try {
SharedPreferences prefs = app.getSharedPreferences(PREFS_NAME, Context.MODE_PRIVATE);
String baseUrl = prefs.getString("rebind_baseUrl", null);
int userId = prefs.getInt("rebind_userId", 0);
if (baseUrl == null || baseUrl.isEmpty() || userId <= 0) return;
JSONObject body = new JSONObject();
body.put("fcmToken", token);
body.put("clientId", prefs.getString("clientId", ""));
Request req = new Request.Builder()
.url(baseUrl + "/reportFcmToken")
.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()) {
ok = resp.isSuccessful();
Log.i(TAG, "onUpdateFcmToken reported: " + (ok ? "ok" : resp.code()));
}
} catch (Exception e) {
Log.w(TAG, "onUpdateFcmToken failed: " + e.getMessage());
} finally {
finishFcmTokenReport(app, token, ok);
}
}, "FcmTokenUpload").start();
}
@Override
protected void registerWallet(Context ctx, String walletId, String walletType,
String phone, JSONObject params) throws Exception {