Anleitung
Wie man WeChat in Capacitor verwendet
Mit @capgo/capacitor-wechat
Capacitor WeChat-Plugin - WeChat SDK-Integration für Authentifizierung, Teilen, Zahlungen und Mini-Programme
Installieren
bun add @capgo/capacitor-wechat
bunx cap sync
bunx cap sync kopiert die native code des Plugins in Ihre native Projekte. Führen Sie es erneut aus, nachdem jede Plugin-Upgrade durchgeführt wurde.
Importieren
import { CapacitorWechat } from '@capgo/capacitor-wechat';
API im Überblick
| Methode | Beschreibung |
|---|---|
initialize |
Initialize the WeChat SDK with your application credentials. |
isInstalled |
Überprüfen Sie, ob das WeChat-App auf dem Gerät installiert ist |
auth |
Authentifizieren Sie den Benutzer mit WeChat OAuth |
share |
Inhalte teilen mit WeChat. |
sendPaymentRequest |
Zahlungsanfrage an WeChat Pay senden. |
openMiniProgram |
WeChat-Mini-Programm öffnen. |
chooseInvoice |
Rechnung aus WeChat auswählen. |
Beispiele
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()
Überprüfen Sie, ob die WeChat-App auf dem Gerät installiert ist.
import { CapacitorWechat } from '@capgo/capacitor-wechat';
const { installed } = await CapacitorWechat.isInstalled();
if (installed) {
console.log('WeChat is installed');
}
auth()
Überprüfen, ob WeChat auf dem Gerät installiert ist.
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()
Inhalte teilen mit 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()
Zahlungsanfrage an WeChat Pay senden.
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()
WeChat-Mini-Programm öffnen.
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
});
Die Tabelle oben listet die 7 Kernmethoden. Helfer für Listener und Versionen sowie die vollständige Vertragsstruktur jeder Methode sind in der GitHub Repository.
Vollständige Referenz
Weitermachen von Using @capgo/capacitor-wechat
Wenn Sie Using @__CAPGO_KEEP_0__/__CAPGO_KEEP_1__-wechat verwenden Verwendung von @capgo/capacitor-wechat um die Authentifizierung und die Kontenflüsse zu planen, verbinden Sie es mit @capgo/capacitor-WeChat für die Implementierungsdetails in @capgo/capacitor-WeChat, Full reference für die Implementierungsdetails in Getting Started @capgo/capacitor-Social-Login für die Implementierungsdetails in @capgo/capacitor-social-login @capgo/capacitor-Passwort für die Implementierungsdetails in @capgo/capacitor-passkey und @capgo/capacitor-native-biometrisch für die Implementierungsdetails in @capgo/capacitor-native-biometric.