Skip to main content
@capgo/capacitor-wechat Communication Open source

WeChat Capacitor plugin

WeChat SDK for Capacitor - enables authentication, sharing, payments, and mini-programs

Install

bun add @capgo/capacitor-wechat bunx cap sync
npm, pnpm or yarn
  • npm install @capgo/capacitor-wechat
  • pnpm add @capgo/capacitor-wechat
  • yarn add @capgo/capacitor-wechat

Guide

How to use WeChat in Capacitor

Using @capgo/capacitor-wechat

Capacitor WeChat Plugin - WeChat SDK integration for authentication, sharing, payments, and mini-programs.

Install

bun add @capgo/capacitor-wechat
bunx cap sync

bunx cap sync copies the plugin's native code into your native projects. Run it again after every plugin upgrade.

Import

import { CapacitorWechat } from '@capgo/capacitor-wechat';

API at a glance

Method Description
initialize Initialize the WeChat SDK with your application credentials.
isInstalled Check if WeChat app is installed on the device.
auth Authenticate user with WeChat OAuth.
share Share content to WeChat.
sendPaymentRequest Send payment request to WeChat Pay.
openMiniProgram Open WeChat mini-program.
chooseInvoice Choose invoice from WeChat.

Examples

initialize()

Initialize the WeChat SDK with your application credentials.

import { CapacitorWechat } from '@capgo/capacitor-wechat';

await CapacitorWechat.initialize({
  appId: 'wx1234567890',
  universalLink: 'https://example.com/app/'
});

isInstalled()

Check if WeChat app is installed on the device.

import { CapacitorWechat } from '@capgo/capacitor-wechat';

const { installed } = await CapacitorWechat.isInstalled();
if (installed) {
  console.log('WeChat is installed');
}

auth()

Authenticate user with WeChat OAuth.

import { CapacitorWechat } from '@capgo/capacitor-wechat';

const { code, state } = await CapacitorWechat.auth({
  scope: 'snsapi_userinfo',
  state: 'my_state'
});
// Use code to get access token from your server

share()

Share content to WeChat.

import { CapacitorWechat } from '@capgo/capacitor-wechat';

// Share text
await CapacitorWechat.share({
  scene: 0, // 0 = Session, 1 = Timeline, 2 = Favorite
  type: 'text',
  text: 'Hello WeChat!'
});

// Share link
await CapacitorWechat.share({
  scene: 1,
  type: 'link',
  title: 'My Website',
  description: 'Check out my website',
  link: 'https://example.com',
  imageUrl: 'https://example.com/image.jpg'
});

sendPaymentRequest()

Send payment request to WeChat Pay.

import { CapacitorWechat } from '@capgo/capacitor-wechat';

// Get payment params from your server first
const paymentParams = await fetchPaymentParamsFromServer();

await CapacitorWechat.sendPaymentRequest({
  partnerId: paymentParams.partnerId,
  prepayId: paymentParams.prepayId,
  nonceStr: paymentParams.nonceStr,
  timeStamp: paymentParams.timeStamp,
  package: paymentParams.package,
  sign: paymentParams.sign
});

openMiniProgram()

Open WeChat mini-program.

import { CapacitorWechat } from '@capgo/capacitor-wechat';

const { extMsg } = await CapacitorWechat.openMiniProgram({
  username: 'gh_xxxxxxxxxxxxx',
  path: 'pages/index/index',
  type: 0 // 0 = Release, 1 = Test, 2 = Preview
});

The table above lists the 7 core methods. Listener and version helpers, and the full contract of each method, are documented in the GitHub repository.

Full reference

Keep going from Using @capgo/capacitor-wechat

If you are using Using @capgo/capacitor-wechat to plan authentication and account flows, connect it with @capgo/capacitor-wechat for the implementation detail in @capgo/capacitor-wechat, Getting Started for the implementation detail in Getting Started, @capgo/capacitor-social-login for the implementation detail in @capgo/capacitor-social-login, @capgo/capacitor-passkey for the implementation detail in @capgo/capacitor-passkey, and @capgo/capacitor-native-biometric for the implementation detail in @capgo/capacitor-native-biometric.

FAQ

WeChat plugin FAQ

How do I install the WeChat plugin in a Capacitor app?

Run "bun add @capgo/capacitor-wechat" (or "npm install @capgo/capacitor-wechat"), then run "bunx cap sync" so the iOS and Android projects pick up the native code. Import it from "@capgo/capacitor-wechat" in your app code.

Does @capgo/capacitor-wechat work with React, Vue and Angular?

Yes. WeChat is a Capacitor package, so it works with any web framework that runs inside Capacitor, including Ionic, React, Vue, Angular, Svelte and plain JavaScript.

Which Capacitor version does @capgo/capacitor-wechat support?

Capgo plugins follow Capacitor's major version: use the plugin major version that matches your Capacitor major version (for example plugin v8 with Capacitor 8). The compatibility table in the GitHub README lists the maintained versions.

Is @capgo/capacitor-wechat free and open source?

Yes. The source code is public on GitHub at https://github.com/Cap-go/capacitor-wechat/ and the package is free to install from npm. Bug reports and pull requests are welcome.

Can I update code that uses WeChat without an App Store review?

Installing or upgrading the plugin changes native code, so it needs a new store build. After that, JavaScript, HTML and CSS changes that call the plugin can ship instantly with Capgo live updates.

Ship WeChat changes without waiting for app review

Once the plugin is in your store build, Capgo live updates push your JavaScript, HTML and CSS changes to users in minutes.

Start with Capgo