internal static WXBaseMessage CreateMessage(int type) { WXBaseMessage result = null; switch (type) { case 1: result = new WXTextMessage(); break; case 2: result = new WXImageMessage(); break; case 3: result = new WXMusicMessage(); break; case 4: result = new WXVideoMessage(); break; case 5: result = new WXWebpageMessage(); break; case 6: result = new WXFileMessage(); break; case 7: result = new WXAppExtendMessage(); break; case 8: result = new WXEmojiMessage(); break; } return(result); }
private async Task WechatShare() { try { var scene = SendMessageToWX.Req.WXSceneChooseByUser; var pic = await GetImageData(); var message = new WXImageMessage() { Title = GetImageTitle(), ImageData = pic }; SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene); IWXAPI api = WXAPIFactory.CreateWXAPI(App.WechatAppId); var isValid = await api.SendReq(req); } catch { await new MessageDialog(LocalizedStrings.ShareFailed).ShowAsyncEnqueue(); } }
public async void ShareImage() { var shareScene = ComboBox.SelectionBoxItem as ShareScene; if (shareScene == null) { return; } try { var scene = shareScene.Scene; var file = await Package.Current.InstalledLocation.GetFileAsync("1.png"); using (var stream = await file.OpenReadAsync()) { var pic = new byte[stream.Size]; await stream.AsStream().ReadAsync(pic, 0, pic.Length); var message = new WXImageMessage { Title = "Sharing a picture!", Description = "This is a image message.这是一个图片消息", ThumbData = pic, ImageUrl = "http://tp3.sinaimg.cn/1882347990/180/5725518284/1" }; SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene); IWXAPI api = WXAPIFactory.CreateWXAPI("[YOUR APP ID]"); var isValid = await api.SendReq(req); } } catch (WXException ex) { Debug.WriteLine(ex.Message); } }
public void share(string argsJSON) { var args = JsonHelper.Deserialize<string[]>(argsJSON); var options = JsonHelper.Deserialize<WeChatShareOptions>(args[0]); if (options == null) { dispatchResult(PluginResult.Status.JSON_EXCEPTION, ERR_INVALID_OPTIONS); return; } WXBaseMessage message = null; var messageOptions = options.message; if (messageOptions != null) { switch (messageOptions.type) { case WeChatShareType.app: break; case WeChatShareType.emotion: break; case WeChatShareType.file: break; case WeChatShareType.image: if (!String.IsNullOrEmpty(messageOptions.url)) { message = new WXImageMessage(messageOptions.url); } else if (!String.IsNullOrEmpty(messageOptions.data)) { message = new WXImageMessage(Convert.FromBase64String(messageOptions.data)); } else { dispatchResult(PluginResult.Status.ERROR, ERR_INVALID_OPTIONS); return; } break; case WeChatShareType.music: break; case WeChatShareType.video: break; case WeChatShareType.webpage: default: message = new WXWebpageMessage(messageOptions.url); break; } if (message == null) { dispatchResult(PluginResult.Status.ERROR, ERR_UNSUPPORTED_MEDIA_TYPE); return; } message.Title = messageOptions.title; message.Description = messageOptions.description; if (!String.IsNullOrEmpty(messageOptions.thumbData)) { message.ThumbData = Convert.FromBase64String(messageOptions.thumbData); } } else if (options.text != null) { message = new WXTextMessage(options.text); } else { dispatchResult(PluginResult.Status.ERROR, ERR_INVALID_OPTIONS); return; } var scene = options.scene; if (scene == null) { scene = WeChatScene.timeline; } try { var request = new SendMessageToWX.Req(message, (int)scene); api.SendReq(request); } catch (WXException e) { dispatchResult(PluginResult.Status.ERROR, e.Message); } }