commit
7e90d9d7d2
@ -226,7 +226,7 @@ ShareFileMetadata
|
||||
|
||||
| name | type | description |
|
||||
| ----- | ------ | -------------- |
|
||||
| url | String | 文件地址 |
|
||||
| url | String | 文件地址。如果是远程文件,则为 http 开头;如果是本地文件,则为绝对路径,如 /storage/emulated/0/Android/xxx |
|
||||
| title | String | 文件标题 |
|
||||
| scene | Number | 分享到, 0:会话 |
|
||||
|
||||
@ -237,6 +237,9 @@ Return:
|
||||
| errCode | Number | 0 if authorization succeed |
|
||||
| errStr | String | Error message if any error occurred |
|
||||
|
||||
|
||||
安卓实现分享本地文件需要对工程进行一些配置,详见 [Android 安装](./docs/build-setup-android.md#分享本地文件)
|
||||
|
||||
```js
|
||||
import * as WeChat from 'react-native-wechat-lib';
|
||||
|
||||
|
||||
@ -255,6 +255,21 @@ public class WeChatLibModule extends ReactContextBaseJavaModule implements IWXAP
|
||||
return data;
|
||||
}
|
||||
|
||||
public String getFileUri(Context context, File file) {
|
||||
if (file == null || !file.exists()) {
|
||||
return null;
|
||||
}
|
||||
|
||||
Uri contentUri = FileProvider.getUriForFile(context,
|
||||
context.getPackageName() + ".fileprovider", // 要与`AndroidManifest.xml`里配置的`authorities`一致
|
||||
file);
|
||||
|
||||
// 授权给微信访问路径
|
||||
context.grantUriPermission("com.tencent.mm", // 这里填微信包名
|
||||
contentUri, Intent.FLAG_GRANT_READ_URI_PERMISSION);
|
||||
|
||||
return contentUri.toString(); // contentUri.toString() 即是以"content://"开头的用于共享的路径
|
||||
}
|
||||
|
||||
/**
|
||||
* 分享文本
|
||||
@ -265,7 +280,15 @@ public class WeChatLibModule extends ReactContextBaseJavaModule implements IWXAP
|
||||
@ReactMethod
|
||||
public void shareFile(ReadableMap data, Callback callback) throws Exception {
|
||||
WXFileObject fileObj = new WXFileObject();
|
||||
fileObj.fileData = loadRawDataFromURL(data.getString("url"));
|
||||
|
||||
String url = data.getString("url");
|
||||
if (url.startsWith("http")) {
|
||||
fileObj.fileData = loadRawDataFromURL(url);
|
||||
} else {
|
||||
File file = new File(url);
|
||||
String fileUri = getFileUri(getReactApplicationContext(), file);
|
||||
fileObj.filePath = fileUri;
|
||||
}
|
||||
|
||||
WXMediaMessage msg = new WXMediaMessage();
|
||||
msg.mediaObject = fileObj;
|
||||
|
||||
@ -114,6 +114,43 @@ android:launchMode="singleTask"
|
||||
</manifest>
|
||||
```
|
||||
|
||||
## 分享本地文件
|
||||
如果你需要分享本地文件,需要在 Android 的工程里进行一些设置,否则会有权限问题
|
||||
|
||||
步骤 1:app/src/main/AndroidManifest.xml 中添加 provider 标签,其中 com.yourapp.xxx 要替换为你自己的包名,记得保留后面的 `.fileprovider`
|
||||
|
||||
```xml
|
||||
<application ...>
|
||||
...
|
||||
<provider
|
||||
android:name="androidx.core.content.FileProvider"
|
||||
android:authorities="com.yourapp.xxx.fileprovider"
|
||||
android:exported="false"
|
||||
android:grantUriPermissions="true">
|
||||
<meta-data
|
||||
android:name="android.support.FILE_PROVIDER_PATHS"
|
||||
android:resource="@xml/filepaths" />
|
||||
</provider>
|
||||
...
|
||||
</application>
|
||||
```
|
||||
|
||||
步骤 2:实现 app/src/main/res/xml/filepaths.xml
|
||||
|
||||
```xml
|
||||
<?xml version="1.0" encoding="utf-8"?>
|
||||
<paths xmlns:android="http://schemas.android.com/apk/res/android">
|
||||
<external-files-path name="myexternalimages" path="Download/" />
|
||||
<cache-path name="my_cache_files" path="." />
|
||||
<root-path name="root" path="" />
|
||||
<files-path name="files-path" path="." />
|
||||
</paths>
|
||||
```
|
||||
|
||||
在这个 XML 文件中,你可以定义不同的路径类型(如 cache-path、external-path 等),以及对应的路径前缀。这样,在使用 FileProvider.getUriForFile() 时,就可以根据这些定义来获取正确的 URI。
|
||||
|
||||
请注意,当组件库被集成到不同的应用中时,你可能需要根据你自己的需求调整 filepaths.xml 中的路径定义。
|
||||
|
||||
## 关于 Android11
|
||||
微信将于近期发布 targetSdkVersion 30的客户端版本,因Android11系统特性,该微信版本在Android 11及以上系统版本的设备上运行时,授权登录、分享、微信支付等功能受到影响,可能无法正常使用。为了适配 Android 系统新版本特性,保证微信功能正常使用,请第三方应用2021年11月1日之前进行更新
|
||||
|
||||
|
||||
227
ios/WechatLib.mm
227
ios/WechatLib.mm
@ -1,10 +1,10 @@
|
||||
// Created by little-snow-fox on 2019-10-9.
|
||||
#import "WechatLib.h"
|
||||
#import "WXApiObject.h"
|
||||
#import <React/RCTEventDispatcher.h>
|
||||
#import "WechatLib.h"
|
||||
#import <React/RCTBridge.h>
|
||||
#import <React/RCTLog.h>
|
||||
#import <React/RCTEventDispatcher.h>
|
||||
#import <React/RCTImageLoader.h>
|
||||
#import <React/RCTLog.h>
|
||||
|
||||
@implementation WechatLib
|
||||
|
||||
@ -16,8 +16,7 @@
|
||||
|
||||
RCT_EXPORT_MODULE()
|
||||
|
||||
- (instancetype)init
|
||||
{
|
||||
- (instancetype)init {
|
||||
self = [super init];
|
||||
if (self) {
|
||||
[[NSNotificationCenter defaultCenter] addObserver:self selector:@selector(handleOpenURL:) name:@"RCTOpenURLNotification" object:nil];
|
||||
@ -25,26 +24,22 @@ RCT_EXPORT_MODULE()
|
||||
return self;
|
||||
}
|
||||
|
||||
- (void)dealloc
|
||||
{
|
||||
- (void)dealloc {
|
||||
[[NSNotificationCenter defaultCenter] removeObserver:self];
|
||||
}
|
||||
|
||||
- (BOOL)handleOpenURL:(NSNotification *)aNotification
|
||||
{
|
||||
- (BOOL)handleOpenURL:(NSNotification *)aNotification {
|
||||
NSString *aURLString = [aNotification userInfo][@"url"];
|
||||
NSURL *aURL = [NSURL URLWithString:aURLString];
|
||||
|
||||
if ([WXApi handleOpenURL:aURL delegate:self])
|
||||
{
|
||||
if ([WXApi handleOpenURL:aURL delegate:self]) {
|
||||
return YES;
|
||||
} else {
|
||||
return NO;
|
||||
}
|
||||
}
|
||||
|
||||
- (dispatch_queue_t)methodQueue
|
||||
{
|
||||
- (dispatch_queue_t)methodQueue {
|
||||
return dispatch_get_main_queue();
|
||||
}
|
||||
|
||||
@ -104,10 +99,10 @@ RCT_EXPORT_MODULE()
|
||||
return data;
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(registerApp:(NSString *)appid
|
||||
RCT_EXPORT_METHOD(registerApp
|
||||
:(NSString *)appid
|
||||
:(NSString *)universalLink
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
self.appId = appid;
|
||||
callback(@[[WXApi registerApp:appid universalLink:universalLink] ? [NSNull null] : INVOKE_FAILED]);
|
||||
}
|
||||
@ -119,56 +114,49 @@ RCT_EXPORT_METHOD(registerApp:(NSString *)appid
|
||||
// callback(@[[WXApi registerApp:appid withDescription:appdesc] ? [NSNull null] : INVOKE_FAILED]);
|
||||
// }
|
||||
|
||||
RCT_EXPORT_METHOD(isWXAppInstalled:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(isWXAppInstalled:(RCTResponseSenderBlock)callback) {
|
||||
callback(@[[NSNull null], @([WXApi isWXAppInstalled])]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(isWXAppSupportApi:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(isWXAppSupportApi:(RCTResponseSenderBlock)callback) {
|
||||
callback(@[[NSNull null], @([WXApi isWXAppSupportApi])]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(getWXAppInstallUrl:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(getWXAppInstallUrl:(RCTResponseSenderBlock)callback) {
|
||||
callback(@[[NSNull null], [WXApi getWXAppInstallUrl]]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(getApiVersion:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(getApiVersion:(RCTResponseSenderBlock)callback) {
|
||||
callback(@[[NSNull null], [WXApi getApiVersion]]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(openWXApp:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(openWXApp:(RCTResponseSenderBlock)callback) {
|
||||
callback(@[([WXApi openWXApp] ? [NSNull null] : INVOKE_FAILED)]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(sendRequest:(NSString *)openid
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(sendRequest
|
||||
:(NSString *)openid
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
BaseReq *req = [[BaseReq alloc] init];
|
||||
req.openID = openid;
|
||||
// callback(@[[WXApi sendReq:req] ? [NSNull null] : INVOKE_FAILED]);
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
[WXApi sendReq:req completion:completion];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(sendAuthRequest:(NSString *)scope
|
||||
RCT_EXPORT_METHOD(sendAuthRequest
|
||||
:(NSString *)scope
|
||||
:(NSString *)state
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
SendAuthReq *req = [[SendAuthReq alloc] init];
|
||||
req.scope = scope;
|
||||
req.state = state;
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -176,13 +164,12 @@ RCT_EXPORT_METHOD(sendAuthRequest:(NSString *)scope
|
||||
[WXApi sendAuthReq:req viewController:rootViewController delegate:self completion:completion];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(sendSuccessResponse:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(sendSuccessResponse
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
BaseResp *resp = [[BaseResp alloc] init];
|
||||
resp.errCode = WXSuccess;
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -190,15 +177,14 @@ RCT_EXPORT_METHOD(sendSuccessResponse:(RCTResponseSenderBlock)callback)
|
||||
// callback(@[[WXApi sendResp:resp] ? [NSNull null] : INVOKE_FAILED]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(sendErrorCommonResponse:(NSString *)message
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(sendErrorCommonResponse
|
||||
:(NSString *)message
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
BaseResp *resp = [[BaseResp alloc] init];
|
||||
resp.errCode = WXErrCodeCommon;
|
||||
resp.errStr = message;
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -206,15 +192,14 @@ RCT_EXPORT_METHOD(sendErrorCommonResponse:(NSString *)message
|
||||
// callback(@[[WXApi sendResp:resp] ? [NSNull null] : INVOKE_FAILED]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(sendErrorUserCancelResponse:(NSString *)message
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(sendErrorUserCancelResponse
|
||||
:(NSString *)message
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
BaseResp *resp = [[BaseResp alloc] init];
|
||||
resp.errCode = WXErrCodeUserCancel;
|
||||
resp.errStr = message;
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -223,16 +208,15 @@ RCT_EXPORT_METHOD(sendErrorUserCancelResponse:(NSString *)message
|
||||
}
|
||||
|
||||
// 分享文本
|
||||
RCT_EXPORT_METHOD(shareText:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(shareText
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
SendMessageToWXReq *req = [[SendMessageToWXReq alloc] init];
|
||||
req.bText = YES;
|
||||
req.text = data[@"text"];
|
||||
req.scene = [data[@"scene"] intValue];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -240,9 +224,9 @@ RCT_EXPORT_METHOD(shareText:(NSDictionary *)data
|
||||
}
|
||||
|
||||
// 选择发票
|
||||
RCT_EXPORT_METHOD(chooseInvoice:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(chooseInvoice
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
WXChooseInvoiceReq *req = [[WXChooseInvoiceReq alloc] init];
|
||||
req.appID = self.appId;
|
||||
req.timeStamp = [data[@"timeStamp"] intValue];
|
||||
@ -251,8 +235,7 @@ RCT_EXPORT_METHOD(chooseInvoice:(NSDictionary *)data
|
||||
req.signType = data[@"signType"];
|
||||
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -260,13 +243,19 @@ RCT_EXPORT_METHOD(chooseInvoice:(NSDictionary *)data
|
||||
}
|
||||
|
||||
// 分享文件
|
||||
RCT_EXPORT_METHOD(shareFile:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(shareFile
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
NSString *url = data[@"url"];
|
||||
WXFileObject *file = [[WXFileObject alloc] init];
|
||||
file.fileExtension = data[@"ext"];
|
||||
NSData *fileData = [NSData dataWithContentsOfURL:[NSURL URLWithString: url]];
|
||||
|
||||
NSData *fileData;
|
||||
if ([url hasPrefix:@"http"]) {
|
||||
fileData = [NSData dataWithContentsOfURL:[NSURL URLWithString:url]];
|
||||
} else {
|
||||
fileData = [NSData dataWithContentsOfFile:url];
|
||||
}
|
||||
file.fileData = fileData;
|
||||
|
||||
WXMediaMessage *message = [WXMediaMessage message];
|
||||
@ -278,8 +267,7 @@ RCT_EXPORT_METHOD(shareFile:(NSDictionary *)data
|
||||
req.message = message;
|
||||
req.scene = [data[@"scene"] intValue];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -287,17 +275,16 @@ RCT_EXPORT_METHOD(shareFile:(NSDictionary *)data
|
||||
}
|
||||
|
||||
// 分享图片
|
||||
RCT_EXPORT_METHOD(shareImage:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(shareImage
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
NSString *imageUrl = data[@"imageUrl"];
|
||||
if (imageUrl == NULL || [imageUrl isEqual:@""]) {
|
||||
callback([NSArray arrayWithObject:@"shareImage: The value of ImageUrl cannot be empty."]);
|
||||
return;
|
||||
}
|
||||
NSRange range = [imageUrl rangeOfString:@"."];
|
||||
if ( range.length == 0)
|
||||
{
|
||||
if (range.length == 0) {
|
||||
callback([NSArray arrayWithObject:@"shareImage: ImageUrl value, Could not find file suffix."]);
|
||||
return;
|
||||
}
|
||||
@ -323,8 +310,7 @@ RCT_EXPORT_METHOD(shareImage:(NSDictionary *)data
|
||||
req.scene = [data[@"scene"] intValue];
|
||||
// [WXApi sendReq:req];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -332,17 +318,16 @@ RCT_EXPORT_METHOD(shareImage:(NSDictionary *)data
|
||||
}
|
||||
|
||||
// 分享本地图片
|
||||
RCT_EXPORT_METHOD(shareLocalImage:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(shareLocalImage
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
NSString *imageUrl = data[@"imageUrl"];
|
||||
if (imageUrl == NULL || [imageUrl isEqual:@""]) {
|
||||
callback([NSArray arrayWithObject:@"shareLocalImage: The value of ImageUrl cannot be empty."]);
|
||||
return;
|
||||
}
|
||||
NSRange range = [imageUrl rangeOfString:@"."];
|
||||
if ( range.length == 0)
|
||||
{
|
||||
if (range.length == 0) {
|
||||
callback([NSArray arrayWithObject:@"shareLocalImage: ImageUrl value, Could not find file suffix."]);
|
||||
return;
|
||||
}
|
||||
@ -368,8 +353,7 @@ RCT_EXPORT_METHOD(shareLocalImage:(NSDictionary *)data
|
||||
req.scene = [data[@"scene"] intValue];
|
||||
// [WXApi sendReq:req];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -377,9 +361,9 @@ RCT_EXPORT_METHOD(shareLocalImage:(NSDictionary *)data
|
||||
}
|
||||
|
||||
// 分享音乐
|
||||
RCT_EXPORT_METHOD(shareMusic:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(shareMusic
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
WXMusicObject *musicObject = [WXMusicObject object];
|
||||
musicObject.musicUrl = data[@"musicUrl"];
|
||||
musicObject.musicLowBandUrl = data[@"musicLowBandUrl"];
|
||||
@ -401,8 +385,7 @@ RCT_EXPORT_METHOD(shareMusic:(NSDictionary *)data
|
||||
req.message = message;
|
||||
req.scene = [data[@"scene"] intValue];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -410,9 +393,9 @@ RCT_EXPORT_METHOD(shareMusic:(NSDictionary *)data
|
||||
}
|
||||
|
||||
// 分享视频
|
||||
RCT_EXPORT_METHOD(shareVideo:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(shareVideo
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
WXVideoObject *videoObject = [WXVideoObject object];
|
||||
videoObject.videoUrl = data[@"videoUrl"];
|
||||
videoObject.videoLowBandUrl = data[@"videoLowBandUrl"];
|
||||
@ -430,18 +413,16 @@ RCT_EXPORT_METHOD(shareVideo:(NSDictionary *)data
|
||||
req.message = message;
|
||||
req.scene = [data[@"scene"] intValue];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
[WXApi sendReq:req completion:completion];
|
||||
}
|
||||
|
||||
// 分享网页
|
||||
RCT_EXPORT_METHOD(shareWebpage:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(shareWebpage
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
WXWebpageObject *webpageObject = [WXWebpageObject object];
|
||||
webpageObject.webpageUrl = data[@"webpageUrl"];
|
||||
WXMediaMessage *message = [WXMediaMessage message];
|
||||
@ -458,8 +439,7 @@ RCT_EXPORT_METHOD(shareWebpage:(NSDictionary *)data
|
||||
req.message = message;
|
||||
req.scene = [data[@"scene"] intValue];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -467,9 +447,9 @@ RCT_EXPORT_METHOD(shareWebpage:(NSDictionary *)data
|
||||
}
|
||||
|
||||
// 分享小程序
|
||||
RCT_EXPORT_METHOD(shareMiniProgram:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(shareMiniProgram
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
WXMiniProgramObject *object = [WXMiniProgramObject object];
|
||||
object.webpageUrl = data[@"webpageUrl"];
|
||||
object.userName = data[@"userName"];
|
||||
@ -499,8 +479,7 @@ RCT_EXPORT_METHOD(shareMiniProgram:(NSDictionary *)data
|
||||
req.message = message;
|
||||
req.scene = [data[@"scene"] integerValue];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -508,25 +487,24 @@ RCT_EXPORT_METHOD(shareMiniProgram:(NSDictionary *)data
|
||||
}
|
||||
|
||||
// 一次性订阅消息
|
||||
RCT_EXPORT_METHOD(subscribeMessage:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(subscribeMessage
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
WXSubscribeMsgReq *req = [[WXSubscribeMsgReq alloc] init];
|
||||
req.scene = [data[@"scene"] integerValue];
|
||||
req.templateId = data[@"templateId"];
|
||||
req.reserved = data[@"reserved"];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
[WXApi sendReq:req completion:completion];
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(launchMiniProgram:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(launchMiniProgram
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
WXLaunchMiniProgramReq *launchMiniProgramReq = [WXLaunchMiniProgramReq object];
|
||||
// 拉起的小程序的 username
|
||||
launchMiniProgramReq.userName = data[@"userName"];
|
||||
@ -537,8 +515,7 @@ RCT_EXPORT_METHOD(launchMiniProgram:(NSDictionary *)data
|
||||
launchMiniProgramReq.miniProgramType = [self integerToWXMiniProgramType:miniProgramType];
|
||||
// launchMiniProgramReq.miniProgramType = [data[@"miniProgramType"] integerValue];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -547,9 +524,9 @@ RCT_EXPORT_METHOD(launchMiniProgram:(NSDictionary *)data
|
||||
// callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
}
|
||||
|
||||
RCT_EXPORT_METHOD(pay:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
RCT_EXPORT_METHOD(pay
|
||||
:(NSDictionary *)data
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
PayReq *req = [PayReq new];
|
||||
req.partnerId = data[@"partnerId"];
|
||||
req.prepayId = data[@"prepayId"];
|
||||
@ -558,8 +535,7 @@ RCT_EXPORT_METHOD(pay:(NSDictionary *)data
|
||||
req.package = data[@"package"];
|
||||
req.sign = data[@"sign"];
|
||||
void (^completion)(BOOL);
|
||||
completion = ^( BOOL success )
|
||||
{
|
||||
completion = ^(BOOL success) {
|
||||
callback(@[success ? [NSNull null] : INVOKE_FAILED]);
|
||||
return;
|
||||
};
|
||||
@ -569,10 +545,10 @@ RCT_EXPORT_METHOD(pay:(NSDictionary *)data
|
||||
}
|
||||
|
||||
// 跳转微信客服
|
||||
RCT_EXPORT_METHOD(openCustomerServiceChat:(NSString *)corpId
|
||||
RCT_EXPORT_METHOD(openCustomerServiceChat
|
||||
:(NSString *)corpId
|
||||
:(NSString *)kfUrl
|
||||
:(RCTResponseSenderBlock)callback)
|
||||
{
|
||||
:(RCTResponseSenderBlock)callback) {
|
||||
WXOpenCustomerServiceReq *req = [[WXOpenCustomerServiceReq alloc] init];
|
||||
req.corpid = corpId; // 企业 ID
|
||||
req.url = kfUrl; // 客服 URL
|
||||
@ -581,8 +557,7 @@ RCT_EXPORT_METHOD(openCustomerServiceChat:(NSString *)corpId
|
||||
|
||||
#pragma mark - wx callback
|
||||
|
||||
-(void) onReq:(BaseReq*)req
|
||||
{
|
||||
- (void)onReq:(BaseReq *)req {
|
||||
if ([req isKindOfClass:[LaunchFromWXReq class]]) {
|
||||
LaunchFromWXReq *launchReq = req;
|
||||
NSString *appParameter = launchReq.message.messageExt;
|
||||
@ -595,10 +570,8 @@ RCT_EXPORT_METHOD(openCustomerServiceChat:(NSString *)corpId
|
||||
}
|
||||
}
|
||||
|
||||
-(void) onResp:(BaseResp*)resp
|
||||
{
|
||||
if([resp isKindOfClass:[SendMessageToWXResp class]])
|
||||
{
|
||||
- (void)onResp:(BaseResp *)resp {
|
||||
if ([resp isKindOfClass:[SendMessageToWXResp class]]) {
|
||||
SendMessageToWXResp *r = (SendMessageToWXResp *)resp;
|
||||
|
||||
NSMutableDictionary *body = @{ @"errCode": @(r.errCode) }.mutableCopy;
|
||||
@ -622,8 +595,7 @@ RCT_EXPORT_METHOD(openCustomerServiceChat:(NSString *)corpId
|
||||
[body addEntriesFromDictionary:@{ @"appid": self.appId, @"code": r.code }];
|
||||
[self.bridge.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body];
|
||||
}
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
[self.bridge.eventDispatcher sendDeviceEventWithName:RCTWXEventName body:body];
|
||||
}
|
||||
} else if ([resp isKindOfClass:[PayResp class]]) {
|
||||
@ -673,4 +645,3 @@ RCT_EXPORT_METHOD(openCustomerServiceChat:(NSString *)corpId
|
||||
}
|
||||
|
||||
@end
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user