Giter Site home page Giter Site logo

react-native-wx's Introduction

react-native-wx

React Native的微信插件, 包括登录、分享

注意: react-native版本需要0.17.0及以上

注意:iOS应用只要申请并获取到AppID就可进行调试。Android应用除了获取AppID外,应用还要通过审核,否则无法调起微信进行分享,并且需要在网站上填写包名和签名两个字段,签名需要使用签名生成工具获取。

如何安装

1.首先安装npm包

npm install react-native-wx --save

2.link

自动link方法

react-native link react-native-wx

手动link~(如果不能够自动link)

#####ios a.打开XCode's工程中, 右键点击Libraries文件夹 ➜ Add Files to <...> b.去node_modules ➜ react-native-wx ➜ ios ➜ 选择 RCTWeChat.xcodeproj c.在工程Build Phases ➜ Link Binary With Libraries中添加libRCTWeChat.a

#####Android

// file: android/settings.gradle
...

include ':react-native-wx'
project(':react-native-wx').projectDir = new File(settingsDir, '../node_modules/react-native-wx/android')
// file: android/app/build.gradle
...

dependencies {
    ...
    compile project(':react-native-wx')
}

android/app/src/main/java/<你的包名>/MainApplication.java中添加如下两行:

...
import cn.reactnative.modules.wx.WeChatPackage;  // 在public class MainApplication之前import

public class MainApplication extends Application implements ReactApplication {

  private final ReactNativeHost mReactNativeHost = new ReactNativeHost(this) {
    @Override
    protected boolean getUseDeveloperSupport() {
      return BuildConfig.DEBUG;
    }

    @Override
    protected List<ReactPackage> getPackages() {
      return Arrays.<ReactPackage>asList(
          new WeChatPackage(), // 然后添加这一行
          new MainReactPackage()
      );
    }
  };

  @Override
  public ReactNativeHost getReactNativeHost() {
      return mReactNativeHost;
  }
}

3.工程配置

iOS配置

在工程target的Build Phases->Link Binary with Libraries中加入、libsqlite3.tbd、libc++、libz.tbd、CoreTelephony.framework

Info->URL Types 中增加微信的scheme: Identifier 设置为weixin(这个拼写不能错哦), URL Schemes 设置为你注册的微信开发者账号中的APPID

如果react-native版本>=0.17.0, 在你工程的AppDelegate.m文件中添加如下代码:

#import "../Libraries/LinkingIOS/RCTLinkingManager.h"

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  return [RCTLinkingManager application:application openURL:url sourceApplication:sourceApplication annotation:annotation];
}

如果升级有困难,react-native版本实在是<0.17.0, 在你工程的AppDelegate.m文件中添加如下代码:

- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(NSString *)sourceApplication annotation:(id)annotation {
  [[NSNotificationCenter defaultCenter] postNotificationName:@"RCTOpenURLNotification" object:nil userInfo:@{@"url": url.absoluteString}];
  return YES;
}

iOS9的适配问题
a.对传输安全的支持

在iOS9中,默认需要为每次网络传输建立SSL,解决方法是在应用plist文件中设置

<key>NSAppTransportSecurity</key>
<dict>
<key>NSAllowsArbitraryLoads</key>
</true>
</dict>
b.对应用跳转的支持

在iOS9中跳转第三方应用需要在应用的plist文件中添加白名单

<key>LSApplicationQueriesSchemes</key>
<array>
	<string>weixin</string>
	<string>wechat</string>
</array>

Android配置

android/app/build.gradle里,defaultConfig栏目下添加如下代码:

manifestPlaceholders = [
	// 如果有多项,每一项之间需要用逗号分隔
    WX_APPID: "微信的APPID"		//在此修改微信APPID
]

如果react-native版本<0.18.0,确保你的MainActivity.java中有onActivityResult的实现:

private ReactInstanceManager mReactInstanceManager;
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data){
    super.onActivityResult(requestCode, resultCode, data);
    mReactInstanceManager.onActivityResult(requestCode, resultCode, data);
}

在你的包名相应目录下新建一个wxapi目录,并在该wxapi目录下新增一个WXEntryActivity类,该类继承自Activity(例如应用程序的包名为net.sourceforge.simcpux,则新添加的类的包名为net.sourceforge.simcpux.wxapi)

package net.sourceforge.simcpux.wxapi; // net.sourceforge.simcpux处为你的包名

import android.app.Activity;
import android.os.Bundle;

import cn.reactnative.modules.wx.WeChatModule;

public class WXEntryActivity extends Activity{
    @Override
    protected void onCreate(Bundle savedInstanceState) {
        super.onCreate(savedInstanceState);
        WeChatModule.handleIntent(getIntent());
        finish();
    }
}
		

如何使用

引入包

import * as WechatAPI from 'react-native-wx';

API

WechatAPI.isWXAppInstalled()

返回一个Promise对象

WechatAPI.isWXAppSupportApi()

返回一个Promise对象

WechatAPI.login(config)

// 登录参数 
config : {	
	scope: 权限设置, // 默认 'snsapi_userinfo'
}

返回一个Promise对象。成功时的回调为一个类似这样的对象:

{
	"code": "",
	"appid": "",
	"lang": "",
	"country": "",
}

WechatAPI.shareToTimeline(data)

分享到朋友圈

WechatAPI.shareToSession(data)

分享到好友

// 分享文字
{	
	type: 'text', 
	text: 文字内容,
}
// 分享图片
{	
	type: 'image',
	imageUrl: 图片地址,
	title : 标题,
	description : 描述,
}
// 分享网页
{	
	type: 'news',
	title : 标题,
	description : 描述,	
	webpageUrl : 链接地址,
	imageUrl: 缩略图地址,
}

WechatAPI.pay(data)

// 登录参数 
data : {	
	partnerId: "",
	prepayId: "",
	nonceStr: "",
	timeStamp: "",
	package: "",
	sign: "",
}

返回一个Promise对象。成功时的回调为一个类似这样的对象:

{
	errCode: "",
	errMsg: "",
	appid: "",
	returnKey: "",
}

react-native-wx's People

Contributors

codeherecn avatar lekenny avatar lvbingru avatar sunnylqm avatar tdzl2003 avatar

Stargazers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

Watchers

 avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar  avatar

react-native-wx's Issues

RCTWeChatAPI.m compile error

mylocalpath/node_modules/react-native-wx/ios/RCTWeChatAPI/RCTWeChatAPI.m:208:30: error: no visible @interface for 'RCTImageLoader' declares the selector
'loadImageWithURLRequest:size:scale:clipped:resizeMode:progressBlock:completionBlock:'
[_bridge.imageLoader loadImageWithURLRequest:imageUrl size:size scale:1 clipped:true resizeMode:UIViewContentModeScaleToFill progressBlock:nil completionBlock:^(NSError *err...
~~~~~~~~~~~~~~~~~~~ ^~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
mylocalpath/node_modules/react-native-wx/ios/RCTWeChatAPI/RCTWeChatAPI.m:299:34: warning: 'sendAppEventWithName:body:' is deprecated: Subclass RCTEventEmitter
instead [-Wdeprecated-declarations]
[self.bridge.eventDispatcher sendAppEventWithName:@"WeChat_Resp" body:body];
^
In file included frommylocalpath/node_modules/react-native-wx/ios/RCTWeChatAPI/RCTWeChatAPI.m:14:
../../react-native/React/Base/RCTEventDispatcher.h:64:1: note: 'sendAppEventWithName:body:' has been explicitly marked deprecated here

  • (void)sendAppEventWithName:(NSString *)name body:(id)body
    ^
    1 warning and 1 error generated.

微信分享的小图标怎么修改

image
如上图,所有,其它参数都设置生效了,但是不知道这个小图标是怎么修改的,貌似参数并没有这一项,请问有人知道吗?

打包失败

微信插件打包提示Ignoring InnerClasses attribute for an anonymous inner class","sources":[{}]}。。。之类的,生成的apk闪退,请问怎么解决

分享至朋友圈功能无法使用本地图片

在分享api的参数中设置imageurl为"xx.png"并将图片放置于drawable文件夹内,shareToSession会读取工程目录下的图片,然而shareToTimeline不会。

var data = {
imageUrl: 'ic_launcher.png',
...
}

Error:Execution failed for task ':react-native-wx:processDebugAndroidTestManifest'. > Manifest merger failed : Attribute meta-data#WX_APPID@value at manifestMerger7048962468923408949.xml requires a placeholder substitution but no value for <WX_APPID> is provided.

Error:Execution failed for task ':react-native-wx:processDebugAndroidTestManifest'.

Manifest merger failed : Attribute meta-data#WX_APPID@value at manifestMerger7048962468923408949.xml requires a placeholder substitution but no value for <WX_APPID> is provided. 无法打包

模块

大佬有没有vx防撤回模块呀

安卓微信分享点击好友无反应

logcat报 image no null

const data = {
      type: 'news',
      title: articleTitle,
      description: 'describe',
      webpageUrl: url,
      imageUrl: 'http://img4.imgtn.bdimg.com/it/u=356358824,983689058&fm=200&gp=0.jpg',
    };

不支持 react-native: 0.35.0?

您好,请问:

DuangLink-MacBook-Pro:bizapp3.test duanglink$ react-native -v
react-native-cli: 1.0.0
react-native: 0.35.0

DuangLink-MacBook-Pro:bizapp3.test duanglink$ npm install react-native-wx --save
[email protected] /Users/duanglink/ReactNativeProjects/bizapp3.test
├── UNMET PEER DEPENDENCY [email protected]
└─┬ [email protected]
  └─┬ [email protected]
    └── [email protected]

npm WARN [email protected] requires a peer of react-native@^0.33.0 but none was installed.

应该如何解决?谢谢。

安卓下登录有问题。

在ios下面没有问题。但是安卓下,微信授权界面打开后,点击授权,没有返回数据。分享功能中,发送给朋友文字信息,能打开微信的界面,但是点击朋友后,发送界面一闪而过,不能发出去。请问是什么原因?

分享后有回调么

分享后有回调么,传入callback,或者返回promise之类的?我看现在分享返回后否没有触发

iOS 下 login 方法无返回结果

编译通过,login() 方法能呼起微信客户端,但在微信客户端点击授权完成后,回到我的客户端后,login() 方法返回的 promise.then()catch() 都没有继续执行,无法获取结果,也一直没有报错。

执行 isWXAppSupportApi() 能返回 true

已确保微信 app id 正确可用,客户端 bundle id 也已经填写正确。

我的环境是:
react-native: v0.42
react-native-wx: v3.0.3
xCode: v8.2.1
macOS: v10.12
微信:v6.5.5

十分感谢 😂

请问为什么分享给好友的图片不显示,好严重!

分享给好友的图片默认不显示,非要点击灰色默认图跳转到另一个页面,下载后才显示? 请请教大家一下是什么原因?

补充说明:Android 手机分享给 iOS 手机,分享代码如下:

await WechatAPI.shareToSession({
    type: 'image',
    //imageUrl: 'http://www.ncloud.hk/email-signature-262x100.png'
    imageUrl: 'http://img.tougudashi.com/share/1463218403.3611000.png'
});

分享的图片不显示

@sunnylqm @lvbingru @lqs6910 @tdzl2003 @cham1985 请帮忙看看,不好意思,打扰到这么多人,谢谢!

请问现在有获得用户openid的Api吗?

我试过:

      WechatAPI.login({  
        scope: 'snsapi_base', // 默认 'snsapi_userinfo'
      })

这样不行,报“Scope参数错误或没有 Scope权限”。 是不是我调用错了?

run-android报错

  • What went wrong:
    Execution failed for task ':app:processDebugManifest'.

Manifest merger failed : Attribute meta-data#WX_APPID@value at AndroidManifest.xml:18:9-20:43 requires a placeholder substitution but no value for <WX_APPID> is provided.

run-android 报这个错

android 一旦在页面引入包就报错

undefined is not a function (evaluating 'globalObject.hasOwnProperty("Promise")')

index.android.bundle?platform=android&dev=true&hot=false&minify=false:58519:41

index.android.bundle?platform=android&dev=true&hot=false&minify=false:58546:6

index.android.bundle?platform=android&dev=true&hot=false&minify=false:58553:2
loadModuleImplementation
index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12
guardedLoadModule
index.android.bundle?platform=android&dev=true&hot=false&minify=false:70:36
_require
index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77

index.android.bundle?platform=android&dev=true&hot=false&minify=false:58438:29

index.android.bundle?platform=android&dev=true&hot=false&minify=false:58494:2
loadModuleImplementation
index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12
guardedLoadModule
index.android.bundle?platform=android&dev=true&hot=false&minify=false:70:36
_require
index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77

index.android.bundle?platform=android&dev=true&hot=false&minify=false:58273:28
loadModuleImplementation
index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12
guardedLoadModule
index.android.bundle?platform=android&dev=true&hot=false&minify=false:70:36
_require
index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77

index.android.bundle?platform=android&dev=true&hot=false&minify=false:57658:29
loadModuleImplementation
index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12
guardedLoadModule
index.android.bundle?platform=android&dev=true&hot=false&minify=false:70:36
_require
index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77

index.android.bundle?platform=android&dev=true&hot=false&minify=false:50158:21
loadModuleImplementation
index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12
guardedLoadModule
index.android.bundle?platform=android&dev=true&hot=false&minify=false:70:36
_require
index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77

index.android.bundle?platform=android&dev=true&hot=false&minify=false:50060:20
loadModuleImplementation
index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12
guardedLoadModule
index.android.bundle?platform=android&dev=true&hot=false&minify=false:70:36
_require
index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77

index.android.bundle?platform=android&dev=true&hot=false&minify=false:1241:23
loadModuleImplementation
index.android.bundle?platform=android&dev=true&hot=false&minify=false:109:12
guardedLoadModule
index.android.bundle?platform=android&dev=true&hot=false&minify=false:63:45
_require
index.android.bundle?platform=android&dev=true&hot=false&minify=false:54:77
global code
index.android.bundle?platform=android&dev=true&hot=false&minify=false:74953:9

Android登录点击没反应

微信没登录会跳转到微信登录界面,登录之后跳转回应用,再次点击微信登录没反应

自动link for安卓好像有点问题

自动link返回成功后。

发现下面的步骤还是手动要做,否则报错。

android/app/src/main/java/<你的包名>/MainApplication.java中,public class MainApplication 之前增加:

import cn.reactnative.modules.wx.WeChatPackage;

如果react-native版本 >=0.18.0 在new MainReactPackage()之后增加

,new WeChatPackage()

android 支付闪退

rn版本0.30 , android 支付闪退,android测试版本5.1 ,6.0 。登录没有问题。
IOS没有任何问题!

react-native run-android时输出:

react-native run-android时输出:

 that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.tencent.mm.sdk.openapi.WXApiImplV10$ActivityLifecycleCb$2) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.
warning: Ignoring InnerClasses attribute for an anonymous inner class
(com.tencent.mm.sdk.b.b) that doesn't come with an
associated EnclosingMethod attribute. This class was probably produced by a
compiler that did not target the modern .class file format. The recommended
solution is to recompile the class from source, using an up-to-date compiler
and without specifying any "-target" type options. The consequence of ignoring
this warning is that reflective operations on this class will incorrectly
indicate that it is *not* an inner class.

APP端支付无法调起

登录与分享都没有问题,APP端支付拿data : {
partnerId: "",
prepayId: "",
nonceStr: "",
timeStamp: "",
package: "",
sign: "",
}这些参数去请求,android无法调起微信返回Error,ios调起微信只有一个确定按钮,点击之后返回error:用户点击了取消

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.