Commit ed81e504c2a69430f6e5f3fb85aa63ed5e5bd6c2

Authored by wdn127929
1 parent accd2e6c

企业微信分享

@@ -2044,8 +2044,8 @@ class Utils { @@ -2044,8 +2044,8 @@ class Utils {
2044 } 2044 }
2045 2045
2046 //分享邀请函 2046 //分享邀请函
2047 - static goShareInvicationToWeChat(  
2048 - BuildContext context, String rid, String uid) async { 2047 + static goShareInvicationToWeChat(BuildContext context, String rid, String uid,
  2048 + {bool isWechat = true}) async {
2049 String _webPageUrl = "http://colorcun.com/"; 2049 String _webPageUrl = "http://colorcun.com/";
2050 // String _thumbnail = 2050 // String _thumbnail =
2051 // "https://xt04.colorcun.com/h5/index.html#/?id=163854&hasInvitation=1"; 2051 // "https://xt04.colorcun.com/h5/index.html#/?id=163854&hasInvitation=1";
@@ -2058,9 +2058,7 @@ class Utils { @@ -2058,9 +2058,7 @@ class Utils {
2058 : sellerImage; 2058 : sellerImage;
2059 String _title = 2059 String _title =
2060 "您预订的${Provider.of<UserModel>(context, listen: false).user.sellername},已经安排,点击查看详情"; 2060 "您预订的${Provider.of<UserModel>(context, listen: false).user.sellername},已经安排,点击查看详情";
2061 - String _userName = "gh_487873d353b3";  
2062 - String _path =  
2063 - "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid"; 2061 +
2064 // if (Provider.of<UserModel>(context, listen: false).user.sellerid == '677') { 2062 // if (Provider.of<UserModel>(context, listen: false).user.sellerid == '677') {
2065 // //京厨九跳转新的邀请函地址 2063 // //京厨九跳转新的邀请函地址
2066 // _path = 2064 // _path =
@@ -2068,41 +2066,48 @@ class Utils { @@ -2068,41 +2066,48 @@ class Utils {
2068 // } 2066 // }
2069 String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店"; 2067 String _description = "进入查看包间详情,转发同行好友,还可一键导航到饭店";
2070 // Uint8List source = await testComporessList(context, _thumbnail); 2068 // Uint8List source = await testComporessList(context, _thumbnail);
2071 - FlutterWxwork flutterWxwork = FlutterWxwork();  
2072 -  
2073 - // bool sss = await flutterWxwork.registerApp('wwauthbdca186ec4257973000006',  
2074 - // 'wwbdca186ec4257973', '1000006');  
2075 - // print(sss);  
2076 - bool isSuccess = await flutterWxwork.shareMiniProgram(  
2077 - userName: 'gh_487873d353b3@app',  
2078 - path: _path,  
2079 - hdImageData: _thumbnail,  
2080 - title: _title);  
2081 -  
2082 - // var isSuccess = await flutterWxwork.shareImage();  
2083 - print(isSuccess);  
2084 - return isSuccess;  
2085 -  
2086 - /*** 注释一下下===========  
2087 2069
2088 - //跳转小程序  
2089 - var model = new WeChatShareMiniProgramModel(  
2090 - webPageUrl: _webPageUrl,  
2091 - userName: _userName,  
2092 - title: _title,  
2093 - path: _path,  
2094 - description: _description,  
2095 - miniProgramType: Constant.wxMiniProgramType, //体验版  
2096 - // miniProgramType: WXMiniProgramType.RELEASE, //正式版  
2097 - // miniProgramType: //开发版  
2098 - // thumbnail: WeChatImage.binary(source)  
2099 - thumbnail: WeChatImage.network(_thumbnail)  
2100 - // thumbnail: WeChatImage.binary(image)  
2101 - ); 2070 + bool isSuccess;
  2071 + if (isWechat) {
  2072 +//跳转小程序
  2073 + String _userName = "gh_487873d353b3";
  2074 + String _path =
  2075 + "pages/customer/index?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
  2076 + var model = new WeChatShareMiniProgramModel(
  2077 + webPageUrl: _webPageUrl,
  2078 + userName: _userName,
  2079 + title: _title,
  2080 + path: _path,
  2081 + description: _description,
  2082 + miniProgramType: Constant.wxMiniProgramType, //体验版
  2083 + // miniProgramType: WXMiniProgramType.RELEASE, //正式版
  2084 + // miniProgramType: //开发版
  2085 + // thumbnail: WeChatImage.binary(source)
  2086 + thumbnail: WeChatImage.network(_thumbnail)
  2087 + // thumbnail: WeChatImage.binary(image)
  2088 + );
  2089 +
  2090 + isSuccess = await shareToWeChat(model);
  2091 + } else {
  2092 +
  2093 + String _path =
  2094 + "pages/customer/index.html?id=$rid&hasInvitation=1&hasSellerShare=1&uid=$uid";
  2095 + FlutterWxwork flutterWxwork = FlutterWxwork();
  2096 +
  2097 + bool registerResult = await flutterWxwork.registerApp(
  2098 + 'wwauthbdca186ec4257973000003', 'wwbdca186ec4257973', '1000003');
  2099 + print(registerResult);
  2100 + bool isSuccess = await flutterWxwork.shareMiniProgram(
  2101 + userName: 'gh_487873d353b3@app',
  2102 + path: _path,
  2103 + hdImageData: _thumbnail,
  2104 + title: _title);
  2105 +
  2106 + // var isSuccess = await flutterWxwork.shareImage();
  2107 + print(isSuccess);
  2108 + }
2102 2109
2103 - bool isSuccess = await shareToWeChat(model);  
2104 return isSuccess; 2110 return isSuccess;
2105 - */  
2106 } 2111 }
2107 2112
2108 //检查网络连接 2113 //检查网络连接
@@ -57,62 +57,134 @@ FlutterMethodChannel *channel; @@ -57,62 +57,134 @@ FlutterMethodChannel *channel;
57 } 57 }
58 58
59 - (void)shareImage:(FlutterMethodCall *)call result:(FlutterResult)result { 59 - (void)shareImage:(FlutterMethodCall *)call result:(FlutterResult)result {
60 -  
61 - WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];  
62 - WWKMessageImageAttachment *attachment = [[WWKMessageImageAttachment alloc] init];  
63 - attachment.filename = @"icon.jpg";  
64 - attachment.path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"];  
65 - // NSURL *imageURL = [NSURL URLWithString:@"http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png"];  
66 - // //下载图片  
67 - // NSData *data= [NSData dataWithContentsOfURL:imageURL];  
68 - // attachment.data = data;  
69 - req.attachment = attachment;  
70 - [WWKApi sendReq:req]; 60 + [WWKApi registerApp:@"wwauthbdca186ec4257973000006" corpId:@"wwbdca186ec4257973" agentId:@"1000006"];
  61 +
  62 + dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);
  63 + dispatch_async(globalQueue, ^{
  64 +
  65 +
  66 + // 使用NSURLSession异步请求网络图片
  67 + NSURL *imageURL = [NSURL URLWithString:call.arguments[@"path"]];
  68 + NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
  69 +
  70 + // 创建URLSession并开始任务
  71 + NSURLSession *session = [NSURLSession sharedSession];
  72 + NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:
  73 + ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  74 + if (error) {
  75 + // 处理错误
  76 + NSLog(@"Error: %@", error);
  77 + } else {
  78 + // 成功获取数据,转换为NSData
  79 + NSData *imageData = data;
  80 +
  81 + dispatch_async(dispatch_get_main_queue(), ^{
  82 + WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
  83 + WWKMessageImageAttachment *attachment = [[WWKMessageImageAttachment alloc] init];
  84 + // attachment.filename = @"icon.jpg";
  85 + // attachment.path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"];
  86 + // NSURL *imageURL = [NSURL URLWithString:@"http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png"];
  87 + // //下载图片
  88 + // NSData *data= [NSData dataWithContentsOfURL:imageURL];
  89 + attachment.filename = @"share_image";
  90 + attachment.data = imageData;
  91 + req.attachment = attachment;
  92 + [WWKApi sendReq:req];
  93 + authResult = result;
  94 + });
  95 +
  96 +
  97 +
  98 + // 此处可以使用imageData,例如保存到本地或者用于其他处理
  99 + // 保存到本地示例代码
  100 + // [imageData writeToFile:@"/path/to/save/image.png" atomically:YES];
  101 +
  102 + // 或者直接使用
  103 + // UIImage *image = [UIImage imageWithData:imageData];
  104 + }
  105 + }];
  106 +
  107 + // 启动任务
  108 + [task resume];
  109 +
  110 +
  111 + });
  112 +
  113 + // WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
  114 + // WWKMessageImageAttachment *attachment = [[WWKMessageImageAttachment alloc] init];
  115 + // attachment.filename = @"icon.jpg";
  116 + // attachment.path = [[NSBundle mainBundle] pathForResource:@"icon" ofType:@"jpg"];
  117 + // // NSURL *imageURL = [NSURL URLWithString:@"http://nosqn.colorcun.com/reserve/images/3x/%E6%9A%82%E6%97%A0.png"];
  118 + // // //下载图片
  119 + // // NSData *data= [NSData dataWithContentsOfURL:imageURL];
  120 + // // attachment.data = data;
  121 + // req.attachment = attachment;
  122 + // [WWKApi sendReq:req];
71 123
72 } 124 }
73 125
74 126
75 - (void)shareMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result { 127 - (void)shareMiniProgram:(FlutterMethodCall *)call result:(FlutterResult)result {
76 128
77 - WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];  
78 - WWKMessageMiniAppAttachment *attachment = [[WWKMessageMiniAppAttachment alloc] init];  
79 - attachment.userName = @"gh_487873d353b3@app"; //必须是应用关联的小程序,注意要有@app后缀  
80 - attachment.path = @"pages/customer/index.html?id=563971&hasInvitation=1&hasSellerShare=1&uid=7035";  
81 -// attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bg_error" ofType:@"png"]], 1.0f);  
82 - NSString *hdImageData = call.arguments[@"hdImageData"];  
83 - NSURL *imageURL = [NSURL URLWithString:hdImageData];  
84 - //下载图片  
85 - NSData *data= [NSData dataWithContentsOfURL:imageURL];  
86 - attachment.hdImageData = data;  
87 - // attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"]], 1.0f);  
88 - attachment.title = @"您预订的长安大排档总店(测试),已经安排,点击查看详情";  
89 - req.attachment = attachment;  
90 - [WWKApi sendReq:req];  
91 - authResult = result;  
92 -  
93 - // dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);  
94 - // dispatch_async(globalQueue, ^{  
95 - // NSString *hdImageData = call.arguments[@"hdImageData"];  
96 - // NSURL *imageURL = [NSURL URLWithString:hdImageData];  
97 - // //下载图片  
98 - // NSData *data= [NSData dataWithContentsOfURL:imageURL];  
99 - // dispatch_async(dispatch_get_main_queue(), ^{  
100 - // WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];  
101 - // WWKMessageMiniAppAttachment *attachment = [[WWKMessageMiniAppAttachment alloc] init];  
102 - // attachment.userName = call.arguments[@"userName"]; //必须是应用关联的小程序,注意要有@app后缀  
103 - // attachment.path = call.arguments[@"path"];  
104 -  
105 - // attachment.hdImageData = data;  
106 - // // attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"]], 1.0f);  
107 - // attachment.title = call.arguments[@"title"];  
108 - // req.attachment = attachment;  
109 - // [WWKApi sendReq:req];  
110 - // // result([NSString stringWithFormat:@"%hhd",[WWKApi sendReq:req]);  
111 -  
112 -  
113 - // });  
114 -  
115 - // }); 129 +// WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
  130 +// WWKMessageMiniAppAttachment *attachment = [[WWKMessageMiniAppAttachment alloc] init];
  131 +// attachment.userName = @"gh_487873d353b3@app"; //必须是应用关联的小程序,注意要有@app后缀
  132 +// attachment.path = @"pages/customer/index.html?id=563971&hasInvitation=1&hasSellerShare=1&uid=7035";
  133 +// // attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"bg_error" ofType:@"png"]], 1.0f);
  134 +// NSString *hdImageData = call.arguments[@"hdImageData"];
  135 +// NSURL *imageURL = [NSURL URLWithString:hdImageData];
  136 +// //下载图片
  137 +// NSData *data= [NSData dataWithContentsOfURL:imageURL];
  138 +// attachment.hdImageData = data;
  139 +// // attachment.hdImageData = UIImageJPEGRepresentation([UIImage imageWithContentsOfFile:[[NSBundle mainBundle] pathForResource:@"test" ofType:@"jpg"]], 1.0f);
  140 +// attachment.title = @"您预订的长安大排档总店(测试),已经安排,点击查看详情";
  141 +// req.attachment = attachment;
  142 +// [WWKApi sendReq:req];
  143 +// authResult = result;
  144 +
  145 + dispatch_queue_t globalQueue = dispatch_get_global_queue(0, 0);
  146 + dispatch_async(globalQueue, ^{
  147 +
  148 +
  149 + // 使用NSURLSession异步请求网络图片
  150 + NSURL *imageURL = [NSURL URLWithString:call.arguments[@"hdImageData"]];
  151 + NSURLRequest *request = [NSURLRequest requestWithURL:imageURL];
  152 +
  153 + // 创建URLSession并开始任务
  154 + NSURLSession *session = [NSURLSession sharedSession];
  155 + NSURLSessionDataTask *task = [session dataTaskWithRequest:request completionHandler:
  156 + ^(NSData * _Nullable data, NSURLResponse * _Nullable response, NSError * _Nullable error) {
  157 + if (error) {
  158 + // 处理错误
  159 + NSLog(@"Error: %@", error);
  160 + } else {
  161 + // 成功获取数据,转换为NSData
  162 + NSData *imageData = data;
  163 +
  164 + dispatch_async(dispatch_get_main_queue(), ^{
  165 +
  166 +
  167 + WWKSendMessageReq *req = [[WWKSendMessageReq alloc] init];
  168 + WWKMessageMiniAppAttachment *attachment = [[WWKMessageMiniAppAttachment alloc] init];
  169 + attachment.userName = call.arguments[@"userName"]; //必须是应用关联的小程序,注意要有@app后缀
  170 + attachment.path = call.arguments[@"path"];
  171 + attachment.hdImageData =imageData;
  172 +
  173 + attachment.title = call.arguments[@"title"];
  174 + req.attachment = attachment;
  175 + [WWKApi sendReq:req];
  176 + authResult = result;
  177 +
  178 + });
  179 +
  180 + }}];
  181 +
  182 +
  183 + // 启动任务
  184 + [task resume];
  185 +
  186 +
  187 + });
116 188
117 189
118 190
@@ -176,7 +248,7 @@ FlutterMethodChannel *channel; @@ -176,7 +248,7 @@ FlutterMethodChannel *channel;
176 NSString *corpId = call.arguments[@"corpId"]; // 第三方App所属企业的ID 248 NSString *corpId = call.arguments[@"corpId"]; // 第三方App所属企业的ID
177 NSString *agentId = call.arguments[@"agentId"]; // 第三方App在企业内部的ID 249 NSString *agentId = call.arguments[@"agentId"]; // 第三方App在企业内部的ID
178 // BOOL isWeChatRegistered = [WXApi registerApp:appId universalLink:universalLink]; 250 // BOOL isWeChatRegistered = [WXApi registerApp:appId universalLink:universalLink];
179 - BOOL isWWKRegistered = [WWKApi registerApp:@"wwauthbdca186ec4257973000006" corpId:@"wwbdca186ec4257973" agentId:@"1000006"]; 251 + BOOL isWWKRegistered = [WWKApi registerApp:scheme corpId:corpId agentId:agentId];
180 result(@(isWWKRegistered)); 252 result(@(isWWKRegistered));
181 // result(@(isWeChatRegistered)); 253 // result(@(isWeChatRegistered));
182 } 254 }
@@ -236,17 +308,12 @@ FlutterMethodChannel *channel; @@ -236,17 +308,12 @@ FlutterMethodChannel *channel;
236 authResult(mDic); 308 authResult(mDic);
237 // [channel invokeMethod:@"auth" arguments:mDic]; 309 // [channel invokeMethod:@"auth" arguments:mDic];
238 }else if([resp isKindOfClass:[WWKSendMessageResp class]]){ 310 }else if([resp isKindOfClass:[WWKSendMessageResp class]]){
239 -// WWKSendMessageResp *r = (WWKSendMessageResp *)resp;  
240 -// NSMutableDictionary *mDic = [[NSMutableDictionary alloc]init];  
241 -// if([self isBlankString:[NSString stringWithFormat:@"%d",r.errCode]]){  
242 -// [mDic setObject:@"1" forKey:@"errCode"];  
243 -// [mDic setObject:@"" forKey:@"code"];  
244 -// }else{  
245 -// [mDic setObject:@"0" forKey:@"errCode"];  
246 -// [mDic setObject:r.errStr forKey:@"code"];  
247 -// }  
248 -// [mDic setObject:r.errStr forKey:@"errStr"];  
249 -// authResult(mDic); 311 +
  312 + // NSMutableDictionary *mDic = [[NSMutableDictionary alloc]init];
  313 +
  314 + // [mDic setObject:[NSString stringWithFormat:@"%@",resp.errStr]] forKey:@"errStr"];
  315 + // [mDic setObject:[NSString stringWithFormat:@"%d",resp.errCode]] forKey:@"errCode"];
  316 + // authResult(mDic);
250 } 317 }
251 318
252 } 319 }
@@ -19,8 +19,8 @@ class FlutterWxwork { @@ -19,8 +19,8 @@ class FlutterWxwork {
19 return FlutterWxworkPlatform.instance.isAppInstalled(); 19 return FlutterWxworkPlatform.instance.isAppInstalled();
20 } 20 }
21 21
22 - Future<bool> shareImage() {  
23 - return FlutterWxworkPlatform.instance.shareImage(); 22 + Future<bool> shareImage(String path) {
  23 + return FlutterWxworkPlatform.instance.shareImage(path);
24 } 24 }
25 25
26 Future<bool> shareMiniProgram( 26 Future<bool> shareMiniProgram(
@@ -37,8 +37,11 @@ class MethodChannelFlutterWxwork extends FlutterWxworkPlatform { @@ -37,8 +37,11 @@ class MethodChannelFlutterWxwork extends FlutterWxworkPlatform {
37 } 37 }
38 38
39 @override 39 @override
40 - Future<bool> shareImage() async {  
41 - final shareImage = await methodChannel.invokeMethod<bool>('shareImage'); 40 + Future<bool> shareImage(String path) async {
  41 + final shareImage =
  42 + await methodChannel.invokeMethod<bool>('shareImage', <String, String>{
  43 + 'path': path,
  44 + });
42 return shareImage; 45 return shareImage;
43 } 46 }
44 47
@@ -35,7 +35,7 @@ abstract class FlutterWxworkPlatform extends PlatformInterface { @@ -35,7 +35,7 @@ abstract class FlutterWxworkPlatform extends PlatformInterface {
35 throw UnimplementedError('isAppInstalled() has not been implemented.'); 35 throw UnimplementedError('isAppInstalled() has not been implemented.');
36 } 36 }
37 37
38 - Future<bool> shareImage() { 38 + Future<bool> shareImage(String path) {
39 throw UnimplementedError('shareImage() has not been implemented.'); 39 throw UnimplementedError('shareImage() has not been implemented.');
40 } 40 }
41 41