npm package discovery and stats viewer.

Discover Tips

  • General search

    [free text search, go nuts!]

  • Package details

    pkg:[package-name]

  • User packages

    @[username]

Sponsor

Optimize Toolset

I’ve always been into building performant and accessible sites, but lately I’ve been taking it extremely seriously. So much so that I’ve been building a tool to help me optimize and monitor the sites that I build to make sure that I’m making an attempt to offer the best experience to those who visit them. If you’re into performant, accessible and SEO friendly sites, you might like it too! You can check it out at Optimize Toolset.

About

Hi, 👋, I’m Ryan Hefner  and I built this site for me, and you! The goal of this site was to provide an easy way for me to check the stats on my npm packages, both for prioritizing issues and updates, and to give me a little kick in the pants to keep up on stuff.

As I was building it, I realized that I was actually using the tool to build the tool, and figured I might as well put this out there and hopefully others will find it to be a fast and useful way to search and browse npm packages as I have.

If you’re interested in other things I’m working on, follow me on Twitter or check out the open source projects I’ve been publishing on GitHub.

I am also working on a Twitter bot for this site to tweet the most popular, newest, random packages from npm. Please follow that account now and it will start sending out packages soon–ish.

Open Software & Tools

This site wouldn’t be possible without the immense generosity and tireless efforts from the people who make contributions to the world and share their work via open source initiatives. Thank you 🙏

© 2026 – Pkg Stats / Ryan Hefner

felix-react-native-wechat-sdk

v1.0.2

Published

React Native WeChat SDK for authentication, payment and sharing

Readme

React Native WeChat SDK

React Native WeChat SDK 是一个用于 React Native 应用对接微信开放平台的库,支持微信授权登录、微信支付和微信分享功能。本库完全使用原生代码实现,不依赖第三方框架。

功能特点

  • 支持微信授权登录
  • 支持微信支付
  • 支持微信分享(文本、图片、网页、小程序)
  • 支持 iOS (Swift) 和 Android (Kotlin) 平台
  • 支持 TypeScript

安装

# 使用 npm
npm install react-native-wechat-sdk

# 使用 yarn
yarn add react-native-wechat-sdk

配置

iOS 配置

  1. 打开 Xcode 项目,在 Podfile 中添加以下依赖:
pod 'WechatOpenSDK', '~> 1.9.0'
  1. 运行 pod install 安装依赖。

  2. Info.plist 中添加以下配置:

<key>LSApplicationQueriesSchemes</key>
<array>
  <string>weixin</string>
  <string>weixinULAPI</string>
</array>
<key>CFBundleURLTypes</key>
<array>
  <dict>
    <key>CFBundleTypeRole</key>
    <string>Editor</string>
    <key>CFBundleURLName</key>
    <string>weixin</string>
    <key>CFBundleURLSchemes</key>
    <array>
      <string>wxYOUR_APP_ID</string>
    </array>
  </dict>
</array>
  1. AppDelegate.swift 中添加以下代码:
import WechatOpenSDK

// 在 application:didFinishLaunchingWithOptions 方法中添加
WXApi.registerApp("YOUR_APP_ID")

// 添加以下方法
func application(_ application: UIApplication, handleOpen url: URL) -> Bool {
  return WXApi.handleOpen(url, delegate: WeChatManager.sharedInstance)
}

func application(_ app: UIApplication, open url: URL, options: [UIApplication.OpenURLOptionsKey : Any] = [:]) -> Bool {
  return WXApi.handleOpen(url, delegate: WeChatManager.sharedInstance)
}

Android 配置

  1. android/app/build.gradle 中添加以下依赖:
dependencies {
  // ... 其他依赖
  implementation 'com.tencent.mm.opensdk:wechat-sdk-android:+'
}
  1. android/app/src/main/AndroidManifest.xml 中添加以下配置:
<manifest>
  <application>
    <!-- ... 其他配置 -->
    <activity
      android:name=".wxapi.WXEntryActivity"
      android:exported="true"
      android:launchMode="singleTop"
      android:taskAffinity="${applicationId}"
      android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
    <activity
      android:name=".wxapi.WXPayEntryActivity"
      android:exported="true"
      android:launchMode="singleTop"
      android:taskAffinity="${applicationId}"
      android:theme="@android:style/Theme.Translucent.NoTitleBar"/>
  </application>
</manifest>
  1. 创建 WXEntryActivity.ktWXPayEntryActivity.kt 文件:
// WXEntryActivity.kt
package com.yourpackage.wxapi

import android.app.Activity
import android.os.Bundle
import com.reactnativewechatsdk.WeChatSDKModule
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.WXAPIFactory

class WXEntryActivity : Activity() {
  private var wxApi: IWXAPI? = null

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    wxApi = WXAPIFactory.createWXAPI(this, "YOUR_APP_ID")
    wxApi?.handleIntent(intent, WeChatSDKModule(reactContext))
    finish()
  }
}
// WXPayEntryActivity.kt
package com.yourpackage.wxapi

import android.app.Activity
import android.os.Bundle
import com.reactnativewechatsdk.WeChatSDKModule
import com.tencent.mm.opensdk.openapi.IWXAPI
import com.tencent.mm.opensdk.openapi.WXAPIFactory

class WXPayEntryActivity : Activity() {
  private var wxApi: IWXAPI? = null

  override fun onCreate(savedInstanceState: Bundle?) {
    super.onCreate(savedInstanceState)
    wxApi = WXAPIFactory.createWXAPI(this, "YOUR_APP_ID")
    wxApi?.handleIntent(intent, WeChatSDKModule(reactContext))
    finish()
  }
}

使用示例

import WeChatSDK, { WeChatShareType } from 'react-native-wechat-sdk';

// 注册微信SDK
WeChatSDK.registerApp('YOUR_APP_ID')
  .then(result => {
    console.log('注册结果:', result);
  })
  .catch(error => {
    console.error('注册失败:', error);
  });

// 检查微信是否已安装
WeChatSDK.isWXAppInstalled()
  .then(isInstalled => {
    console.log('微信是否已安装:', isInstalled);
  });

// 微信授权登录
WeChatSDK.authorize()
  .then(result => {
    const { code } = result;
    console.log('登录成功, code:', code);
    // 使用code换取access_token
  })
  .catch(error => {
    console.error('登录失败:', error);
  });

// 微信分享
WeChatSDK.share({
  type: WeChatShareType.WEBPAGE,
  title: '分享标题',
  description: '分享描述',
  webpageUrl: 'https://example.com',
  imageUrl: 'https://example.com/image.jpg',
  isTimeline: false // 是否分享到朋友圈
})
  .then(result => {
    console.log('分享结果:', result);
  })
  .catch(error => {
    console.error('分享失败:', error);
  });

// 微信支付
WeChatSDK.pay({
  appId: 'YOUR_APP_ID',
  partnerId: 'YOUR_PARTNER_ID',
  prepayId: 'PREPAY_ID',
  nonceStr: 'NONCE_STR',
  timeStamp: 'TIME_STAMP',
  package: 'PACKAGE',
  sign: 'SIGN'
})
  .then(result => {
    console.log('支付结果:', result);
  })
  .catch(error => {
    console.error('支付失败:', error);
  });

API 文档

枚举类型

WeChatErrorType

  • SUCCESS (0): 成功
  • ERROR_COMMON (-1): 普通错误
  • ERROR_USER_CANCEL (-2): 用户取消
  • ERROR_SENT_FAILED (-3): 发送失败
  • ERROR_AUTH_DENIED (-4): 授权被拒绝
  • ERROR_UNSUPPORT (-5): 不支持

WeChatShareType

  • TEXT (1): 文本
  • IMAGE (2): 图片
  • WEBPAGE (5): 网页
  • MINI_PROGRAM (8): 小程序

方法

registerApp(appId: string): Promise<boolean>

注册微信SDK

isWXAppInstalled(): Promise<boolean>

检查微信是否已安装

authorize(scope: string = 'snsapi_userinfo'): Promise<{ code: string }>

微信授权登录

share(params: ShareParams): Promise<boolean>

微信分享

pay(params: PayParams): Promise<boolean>

微信支付

贡献指南

  1. Fork 本仓库
  2. 创建特性分支 (git checkout -b feature/fooBar)
  3. 提交更改 (git commit -am 'Add some fooBar')
  4. 推送到分支 (git push origin feature/fooBar)
  5. 创建新的 Merge Request

许可证

本项目采用 MIT 许可证 - 详情请见 LICENSE 文件