Fluwx Documentation

repository·main·Indexed 25 days ago

https://github.com/openflutter/fluwx

A Flutter plugin providing a bridge to the WeChat SDK. It enables features such as sharing, payments, authentication, and launching mini-programs. The project is distributed as a monorepo containing two packages: 'fluwx' (with payment support) and 'fluwx_no_pay' (without payment support for App Store compliance). It supports Android, iOS, and OpenHarmony platforms.

Tokens
11.8K
Snippets
36
Records
110
Agent score
83%

What's inside Fluwx

  1. Overview of Fluwx capabilities

    main

    Fluwx is a WeChat SDK plugin for Flutter that provides the following capabilities:

    • Sharing: Images, text, music, video, etc., to chats, Moments, or Favorites.
    • WeChat Pay: Integrated payment support.
    • WeChat Login: Retrieve Auth Codes during login.
    • Mini Programs: Launch WeChat Mini Programs.
    • Subscription Messages: Support for subscription messaging.
    • App Interaction: Open WeChat, open apps from WeChat tags, and launch WeChat Customer Service from your app.
  2. Customize iOS Launch Screen Assets

    main

    To customize the launch screen for the iOS version of the example project, you can either replace the image files directly in the LaunchImage.imageset directory or use Xcode.

    To use Xcode:

    1. Open the iOS project using open ios/Runner.xcworkspace.
    2. In the Project Navigator, select Runner/Assets.xcassets.
    3. Drag and drop your desired images into the asset catalog.
  3. Clone and initialize the Fluwx monorepo

    main

    To set up the local development environment, clone the repository, install workspace dependencies, and link the packages using Melos.

    Note for Windows users: Ensure git is configured to support symlinks by setting core.symlinks=true, as the repository uses symlinks to share native source code between fluwx and fluwx_no_pay.

    After initialization, verify that all symlinks are correctly established using the symlinks:check command.

    git clone https://github.com/OpenFlutter/fluwx.git
    cd fluwx
    
    # Install workspace dependencies and link packages
    dart pub get
    melos bootstrap
    
    # Verify symlinks
    melos run symlinks:check
  4. Migrate to Fluwx V6 (iOS Breaking Changes)

    main

    V6 is a major version containing breaking changes for iOS. The SDK no longer automatically handles certain configurations that were previously managed via pubspec.yaml. You must now manually configure the following in your iOS project:

    • Universal Links: Must be configured manually.
    • URL Schemes: Must be configured manually.
    • LSApplicationQueriesSchemes: Must be configured manually.

    Note: Any previous configurations for these items in pubspec.yaml will no longer take effect in V6.

    For guidance on setting up Universal Links, URL schemes, and LSApplicationQueriesSchemes, refer to the official WeChat Developer documentation.

  5. Install Fluwx

    main

    To use Fluwx with WeChat payment support, add the fluwx package to your pubspec.yaml dependencies. If you do not require payment features, use the fluwx_no_pay package instead.

    Note: Always replace ${latestVersion} with the actual version from pub.dev.

    dependencies:
      fluwx: ^${latestVersion}
  6. Set up the Fluwx development environment

    main

    To develop locally with this repository, ensure you have the following prerequisites installed:

    • Flutter SDK (stable channel)
    • Dart SDK ≥ 3.10
    • Melos 7.5.1 (Install via dart pub global activate melos 7.5.1)
    • For iOS development: Xcode and CocoaPods (sudo gem install cocoapods)

    Windows Users: Ensure git is configured to support symlinks, as the repository relies on them to share native source between packages: git config core.symlinks true.

  7. Install Melos and prepare development environment

    main

    This repository is a Melos monorepo containing two packages: fluwx (includes WeChat Pay) and fluwx_no_pay (excludes WeChat Pay for App Store compliance).

    Prerequisites:

    • Flutter SDK (stable channel)
    • Dart SDK ≥ 3.10
    • Melos 7.5.1
    • iOS development: Xcode + CocoaPods

    To install Melos globally, run:

    dart pub global activate melos 7.5.1
  8. Configure OpenHarmony for WeChat

    main

    To allow your OpenHarmony module to check if WeChat is installed, add the weixin scheme to your module.json5 file:

    {
      "module": {
        "querySchemes": [
          "weixin"
        ],
      }
    }

    Note: Do not use the IDE's automatic signing for HarmonyOS. You must manually apply for a debug certificate for signing and debugging.

  9. Configure Android for WeChat Integration

    main

    For Android, you must ensure the MD5 fingerprint of your app's signature is registered in the WeChat Developer Platform.

    Warning: If you use a standard debug key, WeChat will not recognize it, resulting in errCode = -1. To test in debug mode, you must modify your debug key to match the signature registered with WeChat.

  10. Handle App launch from WeChat H5 (wx-open-launch-app)

    main

    When a user launches your app from a WeChat H5 page using the <wx-open-launch-app> tag, you can listen for the response using fluwx.addSubscriber. Note that the event type differs by platform:

    • Android: Use WeChatShowMessageFromWXRequest.
    • iOS: Use WeChatLaunchFromWXRequest.

    To retrieve specific data passed from the web page (extinfo), call fluwx.getExtMsg().

    void handle_launch_from_h5() {
      Fluwx fluwx = Fluwx();
    
      fluwx.addSubscriber((response) {
        // 1. Handle platform-specific responses
        if (response is WeChatShowMessageFromWXRequest) {
          debugPrint("launch-app-from-h5 on android");
          // Android specific logic
        } else if (response is WeChatLaunchFromWXRequest) {
          debugPrint("launch-app-from-h5 on ios");
          // iOS specific logic
        }
    
        // 2. Handle both platforms together
        if (response is WeChatLaunchFromWXRequest ||
            response is WeChatShowMessageFromWXRequest) {
          debugPrint("launch-app-from-h5");
          // Shared logic for both Android and iOS
        }
      });
    }
  11. Install Fluwx via pubspec.yaml

    main

    Add fluwx to your pubspec.yaml dependencies. By default, the fluwx package includes WeChat Pay functionality. If you do not require payment features, use the fluwx_no_pay package instead to reduce package size.

    dependencies:
      fluwx: ^${latestVersion}