@gyjshow/react-native-wechat
v1.2.8
Published
React Native WeChat plugin for WeChat Pay and Share (iOS & Android)
Maintainers
Readme
@gyjshow/react-native-wechat
A lightweight React Native plugin for integrating WeChat Pay & WeChat Share on iOS and Android.
Supports:
- ✅ WeChat Pay
- ✅ Share Text
- ✅ Share Webpage
- ✅ Share Image
- ✅ Share to Friends & Moments
- ✅ Get WeChat SDK Version
- ✅ Event / Promise callback handling
Compatible with React Native >= 0.83
Features
- 🔹 Unified API for iOS & Android
- 🔹 Supports WeChat Pay
- 🔹 Share text / webpage / image
- 🔹 Share to friends (
session) & Moments (timeline) - 🔹 Fetch WeChat SDK version
- 🔹 Event-based & Promise-based callbacks
- 🔹 Lightweight & easy to integrate
Installation
# npm
npm install @gyjshow/react-native-wechat
# pnpm
pnpm add @gyjshow/react-native-wechatPlatform Setup
iOS Setup
s.dependency 'WechatOpenSDK-XCFramework'
# CocoaPods 会拉取最新版本
👉 See detailed iOS configuration:
⚠️ **参考 `Code下 README_iOS.md` 配置**
cd ios && pod installAndroid Setup
api 'com.tencent.mm.opensdk:wechat-sdk-android:+'
# Maven Central 最新版本
👉 See detailed Android WXEntryActivity:
⚠️ **参考 `Code下 README_WXEntryActivity.md` 配置**
Sync ProjectUsage
Import
import WeChat from '@gyjshow/react-native-wechat';Register App (Required)
WeChat.registerApp('wx1234567890abcdef');Call this once when your app starts.
WeChat Pay
const payParams = {
appId: 'wx123456',
partnerId: '1900000109',
prepayId: 'wx201411101639507cbf6ffd8b0779950874',
nonceStr: '1101000000140429eb40476f8896f4c9',
timeStamp: '1398746574',
package: 'Sign=WXPay',
sign: 'C380BEC2BFD727A4B6845133519F3AD6'
};
const result = await WeChat.wxpay(payParams);Share Text
await WeChat.shareText('Hello WeChat!', 'session');
await WeChat.shareText('Hello Moments!', 'timeline');Share Webpage
await WeChat.shareWebpage(
'https://your-website.com',
'Website Title',
'Website description',
null,
'session'
);Share Image
await WeChat.shareImage(base64ImageString, 'timeline');Get WeChat SDK Version
const version = await WeChat.getVersion();Event & Callback Handling
Event Listener
const sub = WeChat.addListener(resp => {
console.log(resp);
});
// remove
sub.remove();One-time Promise
const resp = await WeChat.once();Response Structure
interface WeChatResp {
errCode: number; // 0 = success, -1 = error, -2 = cancel
errStr: string;
type: 'pay' | 'share' | 'auth';
}API Reference
| Method | Description | |------|------------| | registerApp | Register WeChat App | | wxpay | WeChat Pay | | shareText | Share text | | shareWebpage | Share webpage | | shareImage | Share image | | getVersion | SDK version | | addListener | Add listener | | once | One-time callback |
Notes
- You must register your app in WeChat Open Platform
- WeChat Pay requires backend order generation
- Thumbnail size must be ≤ 32KB
- AppID must match iOS Bundle ID & Android Package Name
License
MIT
