Commit ed81e504c2a69430f6e5f3fb85aa63ed5e5bd6c2

Authored by wdn127929
1 parent accd2e6c

企业微信分享

... ... @@ -2044,8 +2044,8 @@ class Utils {
}
//分享邀请函
static goShareInvicationToWeChat(
BuildContext context, String rid, String uid) async {
static goShareInvicationToWeChat(BuildContext context, String rid, String uid,
{bool isWechat = true}) async {
String _webPageUrl = "http://colorcun.com/";
// String _thumbnail =
// "https://xt04.colorcun.com/h5/index.html#/?id=163854&hasInvitation=1";
... ... @@ -2058,9 +2058,7 @@ class Utils {
: sellerImage;
String _title =
"您预订的${Provider.of<UserModel>(context, listen: false).user.sellername},已经安排,点击查看详情";
String _userName = "gh_487873d353b3";
String _path =
"pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
// if (Provider.of<UserModel>(context, listen: false).user.sellerid == '677') {
// //京厨九跳转新的邀请函地址
// _path =
... ... @@ -2068,41 +2066,48 @@ class Utils {
// }
String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
// Uint8List source = await testComporessList(context, _thumbnail);
FlutterWxwork flutterWxwork = FlutterWxwork();
// bool sss = await flutterWxwork.registerApp('wwauthbdca186ec4257973000006',
// 'wwbdca186ec4257973', '1000006');
// print(sss);
bool isSuccess = await flutterWxwork.shareMiniProgram(
userName: 'gh_487873d353b3@app',
path: _path,
hdImageData: _thumbnail,
title: _title);
// var isSuccess = await flutterWxwork.shareImage();
print(isSuccess);
return isSuccess;
/*** 注释一下下===========
//跳转小程序
var model = new WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl,
userName: _userName,
title: _title,
path: _path,
description: _description,
miniProgramType: Constant.wxMiniProgramType, //体验版
// miniProgramType: WXMiniProgramType.RELEASE, //正式版
// miniProgramType: //开发版
// thumbnail: WeChatImage.binary(source)
thumbnail: WeChatImage.network(_thumbnail)
// thumbnail: WeChatImage.binary(image)
);
bool isSuccess;
if (isWechat) {
//跳转小程序
String _userName = "gh_487873d353b3";
String _path =
"pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
var model = new WeChatShareMiniProgramModel(
webPageUrl: _webPageUrl,
userName: _userName,
title: _title,
path: _path,
description: _description,
miniProgramType: Constant.wxMiniProgramType, //体验版
// miniProgramType: WXMiniProgramType.RELEASE, //正式版
// miniProgramType: //开发版
// thumbnail: WeChatImage.binary(source)
thumbnail: WeChatImage.network(_thumbnail)
// thumbnail: WeChatImage.binary(image)
);
isSuccess = await shareToWeChat(model);
} else {
String _path =
"pages/customer/index.html?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
FlutterWxwork flutterWxwork = FlutterWxwork();
bool registerResult = await flutterWxwork.registerApp(
'wwauthbdca186ec4257973000003', 'wwbdca186ec4257973', '1000003');
print(registerResult);
bool isSuccess = await flutterWxwork.shareMiniProgram(
userName: 'gh_487873d353b3@app',
path: _path,
hdImageData: _thumbnail,
title: _title);
// var isSuccess = await flutterWxwork.shareImage();
print(isSuccess);
}
bool isSuccess = await shareToWeChat(model);
return isSuccess;
*/
}
//检查网络连接
... ...
... ... @@ -57,62 +57,134 @@ FlutterMethodChannel *channel;
}
- (void)shareImage:(FlutterMethodCall *)call result:(FlutterResult)result {
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageImageAttachment *attachment = [[WWKMessageImageAttachment alloc] init];
attachment.filename = @"icon.jpg";
attachment.path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"];
// NSURL *imageURL = [NSURL URLWithString:@"http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png"];
// //下载图片
// NSData *data= [NSData dataWithContentsOfURL:imageURL];
// attachment.data = data;
req.attachment = attachment;
[WWKApi sendReq:req];
[WWKApi registerApp:@"wwauthbdca186ec4257973000006" corpId:@"wwbdca186ec4257973" agentId:@"1000006"];
dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);
dispatch_async(globalQueue, ^{
// 使用NSURLSession异步请求网络图片
NSURL *imageURL = [NSURL URLWithString:call.arguments[@"path"]];
NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
// 创建URLSession并开始任务
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:
^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
// 处理错误
NSLog(@"Error: %@", error);
} else {
// 成功获取数据,转换为NSData
NSData *imageData = data;
dispatch_async(dispatch_get_main_queue(), ^{
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageImageAttachment *attachment = [[WWKMessageImageAttachment alloc] init];
// attachment.filename = @"icon.jpg";
// attachment.path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"];
// NSURL *imageURL = [NSURL URLWithString:@"http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png"];
// //下载图片
// NSData *data= [NSData dataWithContentsOfURL:imageURL];
attachment.filename = @"share_image";
attachment.data = imageData;
req.attachment = attachment;
[WWKApi sendReq:req];
authResult = result;
});
// 此处可以使用imageData,例如保存到本地或者用于其他处理
// 保存到本地示例代码
// [imageData writeToFile:@"/path/to/save/image.png" atomically:YES];
// 或者直接使用
// UIImage *image = [UIImage imageWithData:imageData];
}
}];
// 启动任务
[task resume];
});
// WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
// WWKMessageImageAttachment *attachment = [[WWKMessageImageAttachment alloc] init];
// attachment.filename = @"icon.jpg";
// attachment.path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"];
// // NSURL *imageURL = [NSURL URLWithString:@"http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png"];
// // //下载图片
// // NSData *data= [NSData dataWithContentsOfURL:imageURL];
// // attachment.data = data;
// req.attachment = attachment;
// [WWKApi sendReq:req];
}
- (void)shareMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result {
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageMiniAppAttachment *attachment = [[WWKMessageMiniAppAttachment alloc] init];
attachment.userName = @"gh_487873d353b3@app"; //必须是应用关联的小程序,注意要有@app后缀
attachment.path = @"pages/customer/index.html?id=563971&hasInvitation=1&hasSellerShare=1&uid=7035";
// attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bg_error" ofType:@"png"]], 1.0f);
NSString *hdImageData = call.arguments[@"hdImageData"];
NSURL *imageURL = [NSURL URLWithString:hdImageData];
//下载图片
NSData *data= [NSData dataWithContentsOfURL:imageURL];
attachment.hdImageData = data;
// attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"]], 1.0f);
attachment.title = @"您预订的长安大排档总店(测试),已经安排,点击查看详情";
req.attachment = attachment;
[WWKApi sendReq:req];
authResult = result;
// dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);
// dispatch_async(globalQueue, ^{
// NSString *hdImageData = call.arguments[@"hdImageData"];
// NSURL *imageURL = [NSURL URLWithString:hdImageData];
// //下载图片
// NSData *data= [NSData dataWithContentsOfURL:imageURL];
// dispatch_async(dispatch_get_main_queue(), ^{
// WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
// WWKMessageMiniAppAttachment *attachment = [[WWKMessageMiniAppAttachment alloc] init];
// attachment.userName = call.arguments[@"userName"]; //必须是应用关联的小程序,注意要有@app后缀
// attachment.path = call.arguments[@"path"];
// attachment.hdImageData = data;
// // attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"]], 1.0f);
// attachment.title = call.arguments[@"title"];
// req.attachment = attachment;
// [WWKApi sendReq:req];
// // result([NSString stringWithFormat:@"%hhd",[WWKApi sendReq:req]);
// });
// });
// WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
// WWKMessageMiniAppAttachment *attachment = [[WWKMessageMiniAppAttachment alloc] init];
// attachment.userName = @"gh_487873d353b3@app"; //必须是应用关联的小程序,注意要有@app后缀
// attachment.path = @"pages/customer/index.html?id=563971&hasInvitation=1&hasSellerShare=1&uid=7035";
// // attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bg_error" ofType:@"png"]], 1.0f);
// NSString *hdImageData = call.arguments[@"hdImageData"];
// NSURL *imageURL = [NSURL URLWithString:hdImageData];
// //下载图片
// NSData *data= [NSData dataWithContentsOfURL:imageURL];
// attachment.hdImageData = data;
// // attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"]], 1.0f);
// attachment.title = @"您预订的长安大排档总店(测试),已经安排,点击查看详情";
// req.attachment = attachment;
// [WWKApi sendReq:req];
// authResult = result;
dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);
dispatch_async(globalQueue, ^{
// 使用NSURLSession异步请求网络图片
NSURL *imageURL = [NSURL URLWithString:call.arguments[@"hdImageData"]];
NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
// 创建URLSession并开始任务
NSURLSession *session = [NSURLSession sharedSession];
NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:
^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
if (error) {
// 处理错误
NSLog(@"Error: %@", error);
} else {
// 成功获取数据,转换为NSData
NSData *imageData = data;
dispatch_async(dispatch_get_main_queue(), ^{
WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
WWKMessageMiniAppAttachment *attachment = [[WWKMessageMiniAppAttachment alloc] init];
attachment.userName = call.arguments[@"userName"]; //必须是应用关联的小程序,注意要有@app后缀
attachment.path = call.arguments[@"path"];
attachment.hdImageData =imageData;
attachment.title = call.arguments[@"title"];
req.attachment = attachment;
[WWKApi sendReq:req];
authResult = result;
});
}}];
// 启动任务
[task resume];
});
... ... @@ -176,7 +248,7 @@ FlutterMethodChannel *channel;
NSString *corpId = call.arguments[@"corpId"]; // 第三方App所属企业的ID
NSString *agentId = call.arguments[@"agentId"]; // 第三方App在企业内部的ID
// BOOL isWeChatRegistered = [WXApi registerApp:appId universalLink:universalLink];
BOOL isWWKRegistered = [WWKApi registerApp:@"wwauthbdca186ec4257973000006" corpId:@"wwbdca186ec4257973" agentId:@"1000006"];
BOOL isWWKRegistered = [WWKApi registerApp:scheme corpId:corpId agentId:agentId];
result(@(isWWKRegistered));
// result(@(isWeChatRegistered));
}
... ... @@ -236,17 +308,12 @@ FlutterMethodChannel *channel;
authResult(mDic);
// [channel invokeMethod:@"auth" arguments:mDic];
}else if([resp isKindOfClass:[WWKSendMessageResp class]]){
// WWKSendMessageResp *r = (WWKSendMessageResp *)resp;
// NSMutableDictionary *mDic = [[NSMutableDictionary alloc]init];
// if([self isBlankString:[NSString stringWithFormat:@"%d",r.errCode]]){
// [mDic setObject:@"1" forKey:@"errCode"];
// [mDic setObject:@"" forKey:@"code"];
// }else{
// [mDic setObject:@"0" forKey:@"errCode"];
// [mDic setObject:r.errStr forKey:@"code"];
// }
// [mDic setObject:r.errStr forKey:@"errStr"];
// authResult(mDic);
// NSMutableDictionary *mDic = [[NSMutableDictionary alloc]init];
// [mDic setObject:[NSString stringWithFormat:@"%@",resp.errStr]] forKey:@"errStr"];
// [mDic setObject:[NSString stringWithFormat:@"%d",resp.errCode]] forKey:@"errCode"];
// authResult(mDic);
}
}
... ...
... ... @@ -19,8 +19,8 @@ class FlutterWxwork {
return FlutterWxworkPlatform.instance.isAppInstalled();
}
Future<bool> shareImage() {
return FlutterWxworkPlatform.instance.shareImage();
Future<bool> shareImage(String path) {
return FlutterWxworkPlatform.instance.shareImage(path);
}
Future<bool> shareMiniProgram(
... ...
... ... @@ -37,8 +37,11 @@ class MethodChannelFlutterWxwork extends FlutterWxworkPlatform {
}
@override
Future<bool> shareImage() async {
final shareImage = await methodChannel.invokeMethod<bool>('shareImage');
Future<bool> shareImage(String path) async {
final shareImage =
await methodChannel.invokeMethod<bool>('shareImage', <String, String>{
'path': path,
});
return shareImage;
}
... ...
... ... @@ -35,7 +35,7 @@ abstract class FlutterWxworkPlatform extends PlatformInterface {
throw UnimplementedError('isAppInstalled() has not been implemented.');
}
Future<bool> shareImage() {
Future<bool> shareImage(String path) {
throw UnimplementedError('shareImage() has not been implemented.');
}
... ...