safepay.tsx 1.7 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455
  1. import { Colors } from "@/constants/Colors";
  2. import { useLocalSearchParams, useRouter } from "expo-router";
  3. import { useEffect } from "react";
  4. import { ActivityIndicator, StyleSheet, Text, View } from "react-native";
  5. /**
  6. * Alipay Callback Handler
  7. * Handles the "asios://safepay" deep link from Alipay.
  8. * Automatically goes back to invoke the native SDK's callback handling.
  9. */
  10. export default function AlipayResult() {
  11. const router = useRouter();
  12. const params = useLocalSearchParams();
  13. useEffect(() => {
  14. console.log("Alipay callback params:", params);
  15. // The native SDK (expo-native-alipay) listens for the app verify event
  16. // and resolves the Promise in the calling component (Recharge/Checkout).
  17. // This route mainly exists to prevent "Unmatched Route" errors.
  18. // We simply dismiss it to reveal the underlying screen.
  19. const timer = setTimeout(() => {
  20. // Use router.dismiss() if available in stack, or back()
  21. if (router.canGoBack()) {
  22. router.back();
  23. } else {
  24. // Fallback if launched directly (unlikely for payment callback)
  25. router.replace("/");
  26. }
  27. }, 500); // Short delay to allow smooth transition
  28. return () => clearTimeout(timer);
  29. }, []);
  30. return (
  31. <View style={styles.container}>
  32. <ActivityIndicator size="large" color={Colors.neonBlue || "#00F3FF"} />
  33. <Text style={styles.text}>正在返回应用...</Text>
  34. </View>
  35. );
  36. }
  37. const styles = StyleSheet.create({
  38. container: {
  39. flex: 1,
  40. justifyContent: "center",
  41. alignItems: "center",
  42. backgroundColor: Colors.darkBg || "#121212",
  43. },
  44. text: {
  45. marginTop: 20,
  46. color: Colors.textSecondary || "#aaa",
  47. fontSize: 14,
  48. },
  49. });