{"id":20160589,"url":"https://github.com/reactnativecn/react-native-wx","last_synced_at":"2025-04-07T10:25:29.509Z","repository":{"id":57341339,"uuid":"49274497","full_name":"reactnativecn/react-native-wx","owner":"reactnativecn","description":"微信模块","archived":false,"fork":false,"pushed_at":"2018-11-20T09:57:10.000Z","size":13612,"stargazers_count":248,"open_issues_count":29,"forks_count":63,"subscribers_count":13,"default_branch":"master","last_synced_at":"2024-05-01T01:43:16.902Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"language":"Objective-C","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":null,"status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/reactnativecn.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":null,"code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2016-01-08T13:48:47.000Z","updated_at":"2023-12-14T14:39:41.000Z","dependencies_parsed_at":"2022-09-08T01:51:24.618Z","dependency_job_id":null,"html_url":"https://github.com/reactnativecn/react-native-wx","commit_stats":null,"previous_names":[],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactnativecn%2Freact-native-wx","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactnativecn%2Freact-native-wx/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactnativecn%2Freact-native-wx/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/reactnativecn%2Freact-native-wx/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/reactnativecn","download_url":"https://codeload.github.com/reactnativecn/react-native-wx/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247633596,"owners_count":20970350,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2024-11-14T00:14:50.022Z","updated_at":"2025-04-07T10:25:29.480Z","avatar_url":"https://github.com/reactnativecn.png","language":"Objective-C","readme":"# react-native-wx\n\nReact Native的微信插件, 包括登录、分享\n#### 注意: react-native版本需要0.17.0及以上\n#### 注意：iOS应用只要申请并获取到AppID就可进行调试。Android应用除了获取AppID外，应用还要通过审核，否则无法调起微信进行分享，并且需要在网站上填写包名和签名两个字段，签名需要使用[签名生成工具](https://open.weixin.qq.com/cgi-bin/showdocument?action=dir_list\u0026t=resource/res_list\u0026verify=1\u0026id=open1419319167\u0026lang=zh_CN)获取。\n\n## 如何安装\n\n### 1.首先安装npm包\n\n```bash\nnpm install react-native-wx --save\n```\n\n### 2.link\n#### 自动link方法\n\n```bash\nreact-native link react-native-wx\n```\n\n#### 手动link~（如果不能够自动link）\n#####ios\na.打开XCode's工程中, 右键点击Libraries文件夹 ➜ Add Files to \u003c...\u003e\nb.去node_modules ➜ react-native-wx ➜ ios ➜ 选择 RCTWeChat.xcodeproj\nc.在工程Build Phases ➜ Link Binary With Libraries中添加libRCTWeChat.a\n\n#####Android\n\n```\n// file: android/settings.gradle\n...\n\ninclude ':react-native-wx'\nproject(':react-native-wx').projectDir = new File(settingsDir, '../node_modules/react-native-wx/android')\n```\n\n```\n// file: android/app/build.gradle\n...\n\ndependencies {\n    ...\n    compile project(':react-native-wx')\n}\n```\n\n`android/app/src/main/java/\u003c你的包名\u003e/MainApplication.java`中添加如下两行：\n\n```java\n...\nimport cn.reactnative.modules.wx.WeChatPackage;  // 在public class MainApplication之前import\n\npublic class MainApplication extends Application implements ReactApplication {\n\n  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {\n    @Override\n    protected boolean getUseDeveloperSupport() {\n      return BuildConfig.DEBUG;\n    }\n\n    @Override\n    protected List\u003cReactPackage\u003e getPackages() {\n      return Arrays.\u003cReactPackage\u003easList(\n          new WeChatPackage(), // 然后添加这一行\n          new MainReactPackage()\n      );\n    }\n  };\n\n  @Override\n  public ReactNativeHost getReactNativeHost() {\n      return mReactNativeHost;\n  }\n}\n```\n\n\n### 3.工程配置\n#### iOS配置\n\n在工程target的`Build Phases-\u003eLink Binary with Libraries`中加入`、libsqlite3.tbd、libc++、libz.tbd、CoreTelephony.framework`\n\n\n在`Info-\u003eURL Types` 中增加微信的scheme： `Identifier` 设置为`weixin`（这个拼写不能错哦）, `URL Schemes` 设置为你注册的微信开发者账号中的APPID\n\n如果react-native版本\u003e=0.17.0, 在你工程的`AppDelegate.m`文件中添加如下代码：\n\n```\n#import \"../Libraries/LinkingIOS/RCTLinkingManager.h\"\n\n- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {\n  return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];\n}\n```\n\n如果升级有困难，react-native版本实在是\u003c0.17.0, 在你工程的`AppDelegate.m`文件中添加如下代码：\n\n```\n- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {\n  [[NSNotificationCenter defaultCenter] postNotificationName:@\"RCTOpenURLNotification\" object:nil userInfo:@{@\"url\": url.absoluteString}];\n  return YES;\n}\n\n```\n\n\n##### iOS9的适配问题\n\n###### a.对传输安全的支持\n在iOS9中，默认需要为每次网络传输建立SSL，解决方法是在应用plist文件中设置\n-\n\t\u003ckey\u003eNSAppTransportSecurity\u003c/key\u003e\n\t\u003cdict\u003e\n\t\u003ckey\u003eNSAllowsArbitraryLoads\u003c/key\u003e\n\t\u003c/true\u003e\n\t\u003c/dict\u003e\n\n###### b.对应用跳转的支持\n在iOS9中跳转第三方应用需要在应用的plist文件中添加白名单\n-\n\t\u003ckey\u003eLSApplicationQueriesSchemes\u003c/key\u003e\n\t\u003carray\u003e\n\t\t\u003cstring\u003eweixin\u003c/string\u003e\n\t\t\u003cstring\u003ewechat\u003c/string\u003e\n\t\u003c/array\u003e\n\t\n\n\n#### Android配置\n\n在`android/app/build.gradle`里，defaultConfig栏目下添加如下代码：\n\n```\nmanifestPlaceholders = [\n\t// 如果有多项，每一项之间需要用逗号分隔\n    WX_APPID: \"微信的APPID\"\t\t//在此修改微信APPID\n]\n```\n\n\n如果react-native版本\u003c0.18.0,确保你的MainActivity.java中有`onActivityResult`的实现：\n\n```java\nprivate ReactInstanceManager mReactInstanceManager;\n@Override\npublic void onActivityResult(int requestCode, int resultCode, Intent data){\n    super.onActivityResult(requestCode, resultCode, data);\n    mReactInstanceManager.onActivityResult(requestCode, resultCode, data);\n}\n```\n在你的包名相应目录下新建一个wxapi目录，并在该wxapi目录下新增一个WXEntryActivity类，该类继承自Activity（例如应用程序的包名为net.sourceforge.simcpux，则新添加的类的包名为net.sourceforge.simcpux.wxapi）\n\n```java\npackage net.sourceforge.simcpux.wxapi; // net.sourceforge.simcpux处为你的包名\n\nimport android.app.Activity;\nimport android.os.Bundle;\n\nimport cn.reactnative.modules.wx.WeChatModule;\n\npublic class WXEntryActivity extends Activity{\n    @Override\n    protected void onCreate(Bundle savedInstanceState) {\n        super.onCreate(savedInstanceState);\n        WeChatModule.handleIntent(getIntent());\n        finish();\n    }\n}\n\t\t\n```\n\n## 如何使用\n\n### 引入包\n\n```\nimport * as WechatAPI from 'react-native-wx';\n```\n\n### API\n#### WechatAPI.isWXAppInstalled()\n返回一个`Promise`对象\n\n#### WechatAPI.isWXAppSupportApi()\n返回一个`Promise`对象\n\n#### WechatAPI.login(config)\n\n```javascript\n// 登录参数 \nconfig : {\t\n\tscope: 权限设置, // 默认 'snsapi_userinfo'\n}\n```\n\n返回一个`Promise`对象。成功时的回调为一个类似这样的对象：\n\n```javascript\n{\n\t\"code\": \"\",\n\t\"appid\": \"\",\n\t\"lang\": \"\",\n\t\"country\": \"\",\n}\n```\n\n#### WechatAPI.shareToTimeline(data)\n分享到朋友圈\n#### WechatAPI.shareToSession(data)\n分享到好友\n\n```javascript\n// 分享文字\n{\t\n\ttype: 'text', \n\ttext: 文字内容,\n}\n```\n\n```javascript\n// 分享图片\n{\t\n\ttype: 'image',\n\timageUrl: 图片地址,\n\ttitle : 标题,\n\tdescription : 描述,\n}\n```\n\n```javascript\n// 分享网页\n{\t\n\ttype: 'news',\n\ttitle : 标题,\n\tdescription : 描述,\t\n\twebpageUrl : 链接地址,\n\timageUrl: 缩略图地址,\n}\n```\n\n#### WechatAPI.pay(data)\n```javascript\n// 登录参数 \ndata : {\t\n\tpartnerId: \"\",\n\tprepayId: \"\",\n\tnonceStr: \"\",\n\ttimeStamp: \"\",\n\tpackage: \"\",\n\tsign: \"\",\n}\n```\n\n返回一个`Promise`对象。成功时的回调为一个类似这样的对象：\n\n```javascript\n{\n\terrCode: \"\",\n\terrMsg: \"\",\n\tappid: \"\",\n\treturnKey: \"\",\n}\n```\n","funding_links":[],"categories":[],"sub_categories":[],"project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactnativecn%2Freact-native-wx","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Freactnativecn%2Freact-native-wx","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Freactnativecn%2Freact-native-wx/lists"}