Getting Started
インストール手順とこのプラグインの全てのマークダウン ガイドを含む設定プロンプトをコピーする
Set up this Capacitor plugin in the project.
Use the package manager already used by the project.
Install these package(s): `@capgo/capacitor-wechat`
Run the required Capacitor sync/update step after installation.
Read this markdown guide for the full setup steps: https://raw.githubusercontent.com/Cap-go/website/refs/heads/main/apps/docs/src/content/docs/docs/plugins/wechat/getting-started.mdx
Use that guide for platform-specific steps, native file edits, permissions, config changes, imports, and usage setup.
If that guide references other docs pages, read them too.
Install
Section titled “Install”bun add @capgo/capacitor-wechatbunx cap syncImport
Section titled “Import”import { CapacitorWechat } from '@capgo/capacitor-wechat';API の概要
API の概要というセクションinitialize
「initialize」というセクションSDK を使用して、WeChat アプリをアプリケーション クレデンシャルとともに初期化します。
また、これらの値を capacitor.config.ts プラグインの構成 CapacitorWechat
このメソッドを呼び出すと、実行時に組み込まれた構成を上書きします。
import { CapacitorWechat } from '@capgo/capacitor-wechat';
await CapacitorWechat.initialize({ appId: 'wx1234567890', universalLink: 'https://example.com/app/'});isInstalled
__CAPGO_KEEP_0__ の概要というセクションデバイス上の WeChat アプリがインストールされているかどうかを確認します。
import { CapacitorWechat } from '@capgo/capacitor-wechat';
const { installed } = await CapacitorWechat.isInstalled();if (installed) { console.log('WeChat is installed');}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 servershare
セクションのタイトル “share”WeChatにコンテンツを共有します。
import { CapacitorWechat } from '@capgo/capacitor-wechat';
// Share textawait CapacitorWechat.share({ scene: 0, // 0 = Session, 1 = Timeline, 2 = Favorite type: 'text', text: 'Hello WeChat!'});
// Share linkawait 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
セクションのタイトル “sendPaymentRequest”WeChat Payに支払い要求を送信します。
import { CapacitorWechat } from '@capgo/capacitor-wechat';
// Get payment params from your server firstconst 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
セクションのタイトル “openMiniProgram”WeChat miniプログラムを開きます。
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});chooseInvoice
「chooseInvoice」セクションWeChatから請求書を選択してください。
import { CapacitorWechat } from '@capgo/capacitor-wechat';
const { cards } = await CapacitorWechat.chooseInvoice({ appId: 'your_app_id', signType: 'SHA1', cardSign: 'signature', timeStamp: '1234567890', nonceStr: 'random_string'});console.log('Selected cards:', cards);型の参照
「型の参照」セクションWechatInitializationOptions
「WechatInitializationOptions」セクションWeChatの初期化オプション
export interface WechatInitializationOptions { /** * Required WeChat application ID. */ appId: string;
/** * iOS universal link that is associated with your WeChat application. */ universalLink?: string;}WechatAuthOptions
「WechatAuthOptions」セクションWeChatの認証オプション
export interface WechatAuthOptions { /** * OAuth scope. Use 'snsapi_userinfo' for user info or 'snsapi_login' for login only. */ scope: string;
/** * Optional state parameter for CSRF protection. */ state?: string;}WechatAuthResponse
「WechatAuthResponse」セクションWeChat認証応答。
export interface WechatAuthResponse { /** * Authorization code to exchange for access token. */ code: string;
/** * State parameter if provided in request. */ state?: string;}WechatShareOptions
WeChat共有オプションコピー
export interface WechatShareOptions { /** * Share scene: 0 = Session (chat), 1 = Timeline (moments), 2 = Favorite. */ scene: number;
/** * Share type: 'text', 'image', 'link', 'music', 'video', 'miniprogram'. */ type: 'text' | 'image' | 'link' | 'music' | 'video' | 'miniprogram';
/** * Text content (for type 'text'). */ text?: string;
/** * Title (for type 'link', 'music', 'video', 'miniprogram'). */ title?: string;
/** * Description (for type 'link', 'music', 'video', 'miniprogram'). */ description?: string;
/** * Link URL (for type 'link'). */ link?: string;
/** * Image URL or base64 data. */ imageUrl?: string;
/** * Thumbnail URL or base64 data (for type 'link', 'music', 'video'). */ thumbUrl?: string;
/** * Music or video URL (for type 'music', 'video'). */ mediaUrl?: string;
/** * Mini-program username (for type 'miniprogram'). */ miniProgramUsername?: string;
/** * Mini-program path (for type 'miniprogram'). */ miniProgramPath?: string;
/** * Mini-program type: 0 = Release, 1 = Test, 2 = Preview (for type 'miniprogram'). */ miniProgramType?: number;
/** * Mini-program web page URL fallback (for type 'miniprogram'). */ miniProgramWebPageUrl?: string;}WechatPaymentOptions
コピーWeChatミニプログラムオプション
export interface WechatPaymentOptions { /** * Partner ID (merchant ID). */ partnerId: string;
/** * Prepay ID from unified order API. */ prepayId: string;
/** * Random string. */ nonceStr: string;
/** * Timestamp. */ timeStamp: string;
/** * Package value, typically 'Sign=WXPay'. */ package: string;
/** * Signature. */ sign: string;}WechatMiniProgramOptions
WeChat請求書オプションコピー
export interface WechatMiniProgramOptions { /** * Mini-program username (original ID). */ username: string;
/** * Path to open in mini-program. */ path?: string;
/** * Mini-program type: 0 = Release, 1 = Test, 2 = Preview. */ type?: number;}WechatInvoiceOptions
WeChat請求書オプションのセクションWeChat請求書の選択肢。
export interface WechatInvoiceOptions { /** * App ID. */ appId: string;
/** * Signature type. */ signType: string;
/** * Card signature. */ cardSign: string;
/** * Timestamp. */ timeStamp: string;
/** * Random string. */ nonceStr: string;}WechatInvoiceResponse
セクション「WechatInvoiceResponse」WeChat請求書の応答。
export interface WechatInvoiceResponse { /** * Array of selected card IDs. */ cards: WechatInvoiceCard[];}WechatInvoiceCard
セクション「WechatInvoiceCard」WeChat請求書のカードアイテム。
export interface WechatInvoiceCard { /** * The selected card identifier. */ cardId: string;
/** * Encrypted code returned by WeChat. */ encryptCode?: string;}このページはプラグインから生成されています。 src/definitions.tsパブリックAPIがアップストリームで変更された場合に再度同期を実行してください。
Getting Startedから続けて
Getting Startedから続けてというセクションCapgoを使用している場合 Getting Started APIのダッシュボードとAPIの操作を計画するには Capgoを使用して、@capgo/capacitor-wechatを接続します。 Capgoのnative capabilityを使用するには、@capgo/capacitor-wechatを使用します。 APIの概要 APIの実装詳細 導入 __CAPGO_KEEP_0__のキー APIのキー 実装詳細については API キーを参照してください。 デバイス 実装詳細についてはデバイスを参照してください。