
Security News
Attackers Are Hunting High-Impact Node.js Maintainers in a Coordinated Social Engineering Campaign
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.
react-native-sns-share
Advanced tools
RN微信、微博、QQ及支付宝分享、授权登陆、支付插件。 暂时支持情况
| 分享 | 授权登陆 | 支付 | |
|---|---|---|---|
| 微信 | ✔ | ✔ | ✔ |
| ✔ | ✔ | × | |
| 微博 | ✔ | ✔ | × |
| 支付宝 | × | ✔ | ✔ |
PS:未支持部分,会在后续迭代中完成。
$ npm install --save react-native-npm-share --save$ react-native link react-native-sns-share$ pod update1.Appdelegate 中添加处理回调
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url options:(NSDictionary<UIApplicationOpenURLOptionsKey,id> *)options
{
return [self application:application openURL:url];
}
// 微博web版本回掉时,会走此方法
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url sourceApplication:(nullable NSString *)sourceApplication annotation:(id)annotation {
return [self application:application openURL:url];
}
- (BOOL)application:(UIApplication *)application openURL:(NSURL *)url {
BOOL handled = NO;
handled = [EVNWeiboManager.defaultManager application:application openURL:url];
if (handled) {
return YES;
}
handled = [EVNAliManager.defaultManager application:application openURL:url];
if (handled) {
return YES;
}
handled = [EVNWXManager.defaultManager application:application openURL:url];
if (handled) {
return YES;
}
handled = [EVNQQManager.defaultManager application:application openURL:url];
if (handled) {
return YES;
}
return handled;
}
- (void)applicationWillEnterForeground:(UIApplication *)application
{
[[EVNWeiboManager defaultManager] applicationWillEnterForeground:application];
[[EVNWXManager defaultManager] applicationWillEnterForeground:application];
[[EVNAliManager defaultManager] applicationWillEnterForeground:application];
[[EVNQQManager defaultManager] applicationWillEnterForeground:application];
}
确认MainApplication,getPackages中是否已经加入RNSnsSharePackage。 若没有加入,getPackages中加入 packages.add(new RNSnsSharePackage());
@Override
protected List<ReactPackage> getPackages() {
@SuppressWarnings("UnnecessaryLocalVariable")
List<ReactPackage> packages = new PackageList(this).getPackages();
// Packages that cannot be autolinked yet can be added manually here, for example:
// packages.add(new MyReactNativePackage());
packages.add(new RNSnsSharePackage());
return packages;
}
1.Android工程代码下创建 包名+wxapi/WXEntryActivity.java / WXPayEntryActivity.java继承com.evan.sns.share.wxapi.WXEntryActivity
package com.snssharedemo.wxapi;
public class WXEntryActivity extends com.evan.sns.share.wxapi.WXEntryActivity {
}
package com.snssharedemo.wxapi;
import com.evan.sns.share.wxapi.WXEntryActivity;
public class WXPayEntryActivity extends WXEntryActivity {
}
2.AndroidManifest.xml中设置
<!--微信支付开始-->
<activity
android:name="com.snssharedemo.wxapi.WXPayEntryActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@android:style/Theme.NoDisplay" />
<!--微信支付结束-->
<!--微信分享开始-->
<activity
android:name="com.snssharedemo.wxapi.WXEntryActivity"
android:exported="true"
android:launchMode="singleTop"
android:theme="@android:style/Theme.NoDisplay" />
<!--微信分享结束-->
3.Project的gradle中设置
allprojects {
repositories {
flatDir {
dirs '../../node_modules/react-native-sns-share/android/libs'
}
...
}
}
1.MainActivity中重载onActivityResult,用于接收微博回调信息
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// 接收微博分享后的返回值
WeiboManager.getInstance().doResultIntent(requestCode, resultCode, data);
}
2.主build.gradle中添加
allprojects {
repositories {
...
maven { url "https://dl.bintray.com/thelasterstar/maven/" }
}
}
1.AndroidManifest.xml中设置。AuthActivity中的Data为tencent+AppId
<!--QQ分享开始-->
<activity
android:name="com.tencent.tauth.AuthActivity"
android:noHistory="true"
android:launchMode="singleTask" >
<intent-filter>
<action android:name="android.intent.action.VIEW" />
<category android:name="android.intent.category.DEFAULT" />
<category android:name="android.intent.category.BROWSABLE" />
<data android:scheme="tencent1111" />
</intent-filter>
</activity>
<activity
android:name="com.tencent.connect.common.AssistActivity"
android:configChanges="orientation|keyboardHidden"
android:screenOrientation="behind"
android:theme="@android:style/Theme.Translucent.NoTitleBar" />
<!--QQ分享结束-->
2.MainActivity中重载onActivityResult,用于接收QQ回调信息
@Override
public void onActivityResult(int requestCode, int resultCode, Intent data) {
super.onActivityResult(requestCode, resultCode, data);
// 接收QQ分享后的返回值
QQManager.getInstance().doResultIntent(requestCode, resultCode, data);
}
import Sns from 'react-native-sns-share'
// 项目启动时,注册微信、微博信息
Sns.snsSocial.registerApp({
'wechart': 'wx11111111',
'weibo': '2222222',
'qq': '33333333',
}, {
'weibo': 'https://www.baidu.com',
}, 'testing');
import Sns from 'src/react-native-sns-share'
const types = Sns.snsShare.TYPES;
Sns.snsShare.share({
webpageUrl: 'https://www.baidu.com',
title: '分享一下',
description: '分享就用我',
imageUrl: 'https://timgsa.baidu.com/timg?image&quality=80&size=b9999_10000&sec=1568635646029&di=4f86fc970153b638fd4a404e2a780ed0&imgtype=0&src=http%3A%2F%2Fwww.cnr.cn%2Fjingji%2Ftxcj%2F20160727%2FW020160727318839106051.jpg',
shareType: types.WECHAT_SESSION
})
.then(() => {
console.log('wx share success');
})
.catch((error) => {
console.log(error);
})
types常量表
| 变量 | 含义 |
|---|---|
| WECHAT_SESSION | 微信好友 |
| WECHAT_TIMELINE | 微信朋友圈 |
| QQ_SESSION | QQ好友 |
| 微博 |
import Sns from 'react-native-sns-share'
let params, type = Sns.snsPayment.TYPES.ALIPAY;
if (type == Sns.snsPayment.TYPES.ALIPAY) {
// order 数据尽量后太组装成功后返回,不要前台自己来拼写。 scheme为ios用的,在plist中配置
params = {
order:'partner=2088101568358171&seller_id=xxx@alipay.com&out_trade_no=0819145412-6177&subject=测试&body=测试测试&total_fee=0.01¬ify_url=http://notify.msp.hk/notify.htm&service=mobile.securitypay.pay&payment_type=1&_input_charset=utf-8&it_b_pay=30m&sign=lBBK%2F0w5LOajrMrji7DUgEqNjIhQbidR13GovA5r3TgIbNqv231yC1NksLdw%2Ba3JnfHXoXuet6XNNHtn7VE%2BeCoRO1O%2BR1KugLrQEZMtG5jmJIe2pbjm%2F3kb%2FuGkpG%2BwYQYI51%2BhA3YBbvZHVQBYveBqK%2Bh8mUyb7GM1HxWs9k4%3D&sign_type=RSA',
scheme: 'xxxx'
}
} else if (type == Sns.snsPayment.TYPES.WECHAT) {
// 信息后台给到
params = {
partnerId:'',
prepayId: 'xxxx',
package: '',
nonceStr: '',
timeStamp:'',
sign: '',
}
}
Sns.snsPayment.pay(type, params)
.then(() => {
console.log('支付成功');
})
.catch((error) => {
console.log(error);
// 失败的场景下,最好重新拉取下api来判定是否成功。 有可能用户支付完成后,不点返回留在支付应用。
})
types常量表
| 变量 | 含义 |
|---|---|
| 微信支付 | |
| ALIPAY | 支付宝支付 |
import Sns from 'react-native-sns-share'
let params, type
if (type == Sns.snsOAuth.TYPES.ALIPAY) {
// authLink 根据支付宝文档,后台做拼装加签
params = {
authLink:'XXX',
scheme: 'xxxx'
}
}
Sns.snsOAuth.auth(type, params)
.then((result) => {
// 调用后台服务,通过result做后续逻辑
// 新浪场景格式为 "user_id=%@&access_token=%@&expiration_date=%@&refresh_token=%@"
console.log('成功' + result);
})
.catch((error) => {
console.log(error);
})
types常量表
| 变量 | 含义 |
|---|---|
| 微信 | |
| ALIPAY | 支付宝 |
| 微博 | |
| 微博 |
FAQs
Did you know?

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Security News
Multiple high-impact npm maintainers confirm they have been targeted in the same social engineering campaign that compromised Axios.

Security News
Axios compromise traced to social engineering, showing how attacks on maintainers can bypass controls and expose the broader software supply chain.

Security News
Node.js has paused its bug bounty program after funding ended, removing payouts for vulnerability reports but keeping its security process unchanged.