npm package: @gyjshow/react-native-wechat
Description: React Native WeChat plugin for WeChat Pay and Share (iOS & Android)
Author: Allen.ge
Latest version: 1.2.8

# @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

~~~bash
# npm
npm install @gyjshow/react-native-wechat

# pnpm
pnpm add @gyjshow/react-native-wechat
~~~

---

## Platform Setup
## iOS Setup
~~~bash
s.dependency 'WechatOpenSDK-XCFramework'
# CocoaPods 会拉取最新版本

👉 See detailed iOS configuration:
⚠️ **参考 `Code下 README_iOS.md` 配置**
cd ios && pod install
 ~~~

## Android Setup
 ~~~bash
api 'com.tencent.mm.opensdk:wechat-sdk-android:+' 
# Maven Central 最新版本

👉 See detailed Android WXEntryActivity:
⚠️ **参考 `Code下 README_WXEntryActivity.md` 配置**
Sync Project
~~~

---


## Usage

## Import

~~~ts
import WeChat from '@gyjshow/react-native-wechat';
~~~

---

## Register App (Required)

~~~ts
WeChat.registerApp('wx1234567890abcdef');
~~~

Call this once when your app starts.

---

## WeChat Pay

~~~ts
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

~~~ts
await WeChat.shareText('Hello WeChat!', 'session');
await WeChat.shareText('Hello Moments!', 'timeline');
~~~

---

## Share Webpage

~~~ts
await WeChat.shareWebpage(
  'https://your-website.com',
  'Website Title',
  'Website description',
  null,
  'session'
);
~~~

---

## Share Image

~~~ts
await WeChat.shareImage(base64ImageString, 'timeline');
~~~

---

## Get WeChat SDK Version

~~~ts
const version = await WeChat.getVersion();
~~~

---

## Event & Callback Handling

### Event Listener

~~~ts
const sub = WeChat.addListener(resp => {
  console.log(resp);
});

// remove
sub.remove();
~~~

---

### One-time Promise

~~~ts
const resp = await WeChat.once();
~~~

---

## Response Structure

~~~ts
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