private static void SendWXReqInner(String url, String title, String contentmsg, Bitmap bmp, int type) { SendMessageToWX.Req req; WXWebpageObject textObj = new WXWebpageObject(); textObj.WebpageUrl = url; WXMediaMessage msg = new WXMediaMessage(); msg.Title = title; msg.Description = contentmsg; if (bmp != null) { bmp = Bitmap.CreateScaledBitmap(bmp, 50, 50, true); } msg.MyEediaObject = textObj; req = new SendMessageToWX.Req(); req.Transaction = BuildTransaction("webpage"); req.Message = msg; if (type == 1) { req.Scene = SendMessageToWX.Req.WXSceneSession; } else { if (type == 0) { req.Scene = SendMessageToWX.Req.WXSceneTimeline; } } bool res = vipcompany.wxApi.SendReq(req); }
//分享图片类型 private void BtnImage_Click(object sender, EventArgs e) { Bitmap bitmap = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon); //设置缩略图 Bitmap thumb = Bitmap.CreateScaledBitmap(bitmap, 50, 50, true); bitmap.Recycle(); MemoryStream ms = new MemoryStream(); thumb.Compress(Bitmap.CompressFormat.Png, 0, ms); byte[] bytes = ms.ToArray(); //初始化WXImageObject,设置分享的图片 WXImageObject imgObj = new WXImageObject(bitmap); //初始化WXMediaMessage对象 WXMediaMessage msg = new WXMediaMessage(); msg.MyMediaObject = imgObj; msg.ThumbData = bytes; //构造一个Req请求 SendMessageToWX.Req req = new SendMessageToWX.Req(); req.Transaction = Guid.NewGuid().ToString(); req.Message = msg; req.Scene = SendMessageToWX.Req.WXSceneSession; //发送数据 api.SendReq(req); }
public async void ShareText() { var shareScene = ComboBox.SelectionBoxItem as ShareScene; if (shareScene == null) { return; } try { var scene = shareScene.Scene; var message = new WXTextMessage { Title = "Sharing a text title!", Text = "This is text content", Description = "This is a text message.这是一个文本消息。", ThumbData = null }; SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene); IWXAPI api = WXAPIFactory.CreateWXAPI("[YOUR APP ID]"); var isValid = await api.SendReqAsync(req); } catch (WXException ex) { Debug.WriteLine(ex.Message); } }
//网页类型分享 private void BtnHtml_Click(object sender, EventArgs e) { WXWebpageObject webObj = new WXWebpageObject(); webObj.WebpageUrl = "https://www.xamarin.com/"; WXMediaMessage msg = new WXMediaMessage(webObj); msg.Title = "Xamarin官网"; msg.Description = "官方网站描述"; //分享的缩略图 Bitmap thumb = BitmapFactory.DecodeResource(this.Resources, Resource.Drawable.Icon); MemoryStream ms = new MemoryStream(); thumb.Compress(Bitmap.CompressFormat.Png, 0, ms); byte[] bytes = ms.ToArray(); //构造一个Req请求 SendMessageToWX.Req req = new SendMessageToWX.Req(); //唯一的请求标志 req.Transaction = System.Guid.NewGuid().ToString(); req.Message = msg; req.Scene = SendMessageToWX.Req.WXSceneTimeline; //发送数据 api.SendReq(req); }
//分享音乐类型 private void BtnMusic_Click(object sender, EventArgs e) { //初始化一个WXMusicObject对象,填写音乐地址 WXMusicObject musicObj = new WXMusicObject(); //音乐url musicObj.MusicUrl = "http://www.qq.com"; //设置WXMediaMessage对象 WXMediaMessage msg = new WXMediaMessage(); msg.MyMediaObject = musicObj; msg.Title = "音乐标题"; msg.Description = "音乐描述"; //设置缩略图 Bitmap thumb = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon); MemoryStream ms = new MemoryStream(); thumb.Compress(Bitmap.CompressFormat.Png, 0, ms); byte[] bytes = ms.ToArray(); msg.ThumbData = bytes; //构造一个Req SendMessageToWX.Req req = new SendMessageToWX.Req(); req.Transaction = Guid.NewGuid().ToString(); req.Message = msg; req.Scene = SendMessageToWX.Req.WXSceneTimeline; //发送数据 api.SendReq(req); }
//分享小程序 private void BtnProject_Click(object sender, EventArgs e) { //初始化一个WXMiniProgramObject对象,设置小程序url和ID WXMiniProgramObject miniProgram = new WXMiniProgramObject(); //低版本微信将打开url miniProgram.WebpageUrl = "http://www.qq.com"; //跳转的小程序原始ID miniProgram.UserName = "******"; //小程序的Path miniProgram.Path = ""; //设置WXMediaMessage对象 WXMediaMessage msg = new WXMediaMessage(miniProgram); msg.Title = "小程序标题"; msg.Description = "小程序的描述"; //设置缩略图 Bitmap thumb = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon); MemoryStream ms = new MemoryStream(); thumb.Compress(Bitmap.CompressFormat.Png, 0, ms); byte[] bytes = ms.ToArray(); msg.ThumbData = bytes; //构造一个Req对象 SendMessageToWX.Req req = new SendMessageToWX.Req(); req.Transaction = Guid.NewGuid().ToString(); req.Message = msg; req.Scene = SendMessageToWX.Req.WXSceneTimeline; //发送数据 api.SendReq(req); }
/// <summary> /// 分享一段视频 /// </summary> /// <param name="videoUrl">音乐链接</param> /// <param name="isWXSceneTimeline">true:分享到朋友圈;false:分享给好友</param> /// <param name="showImgResId">链接显示的图标</param> /// <param name="title">别人看到的标题</param> /// <param name="description">别人看到的描述</param> /// <returns>无</returns> public void ShareVideo(string videoUrl, bool isWXSceneTimeline, int showImgResId, string title, string description) { WXVideoObject musciObj = new WXVideoObject(); musciObj.VideoUrl = videoUrl; WXMediaMessage msg = new WXMediaMessage(); msg.MyMediaObject = musciObj; msg.Title = title; msg.Description = description; Bitmap thumbBmp = BitmapFactory.DecodeResource(mContext.Resources, showImgResId); using (MemoryStream stream = new MemoryStream()) { thumbBmp.Compress(Bitmap.CompressFormat.Png, 100, stream); msg.ThumbData = stream.ToArray(); //设置缩略图 } SendMessageToWX.Req req = new SendMessageToWX.Req() { Transaction = buildTransaction("video"), Message = msg, Scene = isWXSceneTimeline ? WECHAT_SHARE_TYPE_FRENDS : WECHAT_SHARE_TYPE_TALK, }; mWXApi.SendReq(req); }
public bool SendImage(Android.Graphics.Bitmap bitmap, WXScene scene = 0) { if (bitmap == null) { throw new Exception("(Android.Graphics.Bitmap) bitmap is null"); } WXImageObject imgObj = new WXImageObject(bitmap); WXMediaMessage wxMediaMessage = new WXMediaMessage(); wxMediaMessage.MyMediaObject = imgObj; // 设置缩略图 int thumbSize = 150; // 150是根据官网demo设置 Android.Graphics.Bitmap thumbBmp = bitmap.ScaledBitmap(thumbSize, thumbSize, false); // 扩展方法 bitmap.Recycle(); wxMediaMessage.ThumbData = thumbBmp.ToArray(true); // 扩展方法 //构造一个Req请求 SendMessageToWX.Req req = new SendMessageToWX.Req(); //唯一的请求标志 req.Transaction = System.Guid.NewGuid().ToString(); req.Message = wxMediaMessage; // req.Scene = SendMessageToWX.Req.WXSceneSession; // 发送信息 // req.Scene = SendMessageToWX.Req.WXSceneTimeline; // 发送朋友圈 req.Scene = (int)scene; //发送数据 return(api.SendReq(req)); }
/// <summary> /// 分享一个网页 /// </summary> /// <param name="httpUrl">网页链接</param> /// <param name="isWXSceneTimeline">true:分享到朋友圈;false:分享给好友</param> /// <param name="icon">链接显示的图标</param> /// <param name="title">别人看到的标题</param> /// <param name="description">别人看到的描述</param> /// <returns>无</returns> public void ShareWebPage(string httpUrl, bool isWXSceneTimeline, Bitmap icon, string title, string description) { WXWebpageObject webpage = new WXWebpageObject() { WebpageUrl = httpUrl, }; WXMediaMessage msg = new WXMediaMessage(webpage) { Title = title, Description = description, }; using (MemoryStream stream = new MemoryStream()) { icon.Compress(Bitmap.CompressFormat.Png, 100, stream); msg.ThumbData = stream.ToArray(); //设置缩略图 } SendMessageToWX.Req req = new SendMessageToWX.Req() { Transaction = buildTransaction("webpage"), Message = msg, Scene = isWXSceneTimeline ? WECHAT_SHARE_TYPE_FRENDS : WECHAT_SHARE_TYPE_TALK, }; mWXApi.SendReq(req); }
//分享视频类型 private void BtnVideo_Click(object sender, EventArgs e) { //初始化一个WXVideoObject对象,填写视频url WXVideoObject videoObj = new WXVideoObject(); //视频地址 videoObj.VideoUrl = "https://www.qq.com"; //设置WXMediaMessage对象 WXMediaMessage msg = new WXMediaMessage(videoObj); msg.Title = "测试视频"; msg.Description = "测试视频描述"; //设置缩略图 Bitmap thumb = BitmapFactory.DecodeResource(Resources, Resource.Drawable.Icon); MemoryStream ms = new MemoryStream(); thumb.Compress(Bitmap.CompressFormat.Png, 0, ms); byte[] bytes = ms.ToArray(); msg.ThumbData = bytes; //构造一个Req请求 SendMessageToWX.Req req = new SendMessageToWX.Req(); req.Transaction = Guid.NewGuid().ToString(); req.Message = msg; req.Scene = SendMessageToWX.Req.WXSceneTimeline; //发送数据 api.SendReq(req); }
/// <summary> /// 分享 /// </summary> /// <param name="type">分享类型</param> /// <param name="msg">分享信息</param> /// <param name="scene">分享场景</param> /// <returns>是否发送成功,不等于分享成功</returns> private bool share(string type, WXMediaMessage msg, shareScene scene) { SendMessageToWX.Req req = new SendMessageToWX.Req(); req.Transaction = type; req.Message = msg; req.Scene = (int)scene; return(Api.SendReq(req)); }
public static void SendReqInternal(SendMessageToWX.Req req) { try { mApi.SendReq(req); } catch (WXException e) { System.Diagnostics.Debugger.Log(0, "[asWXHelper]", e.ToString()); } }
/// <summary> /// 页面分享 /// </summary> /// <param name="text"></param> /// <param name="title"></param> /// <param name="thumb"></param> public async void WebPageShareByUserChooseRequest(string url, string title, byte[] thumb) { var message = new WXWebpageMessage { WebpageUrl = url, ThumbData = thumb, Title = title }; SendMessageToWX.Req request = new SendMessageToWX.Req(message, SendMessageToWX.Req.WXSceneChooseByUser); IWXAPI api = WXAPIFactory.CreateWXAPI(_appId); await api.SendReq(request); }
/// <summary> /// 文本分享到微信朋友圈 /// </summary> /// <param name="text"></param> /// <param name="title"></param> /// <param name="thumb"></param> public async void TextShare2TimelineRequest(string text, string title, byte[] thumb) { var message = new WXTextMessage { Text = text, ThumbData = thumb, Title = title }; SendMessageToWX.Req request = new SendMessageToWX.Req(message, SendMessageToWX.Req.WXSceneTimeline); IWXAPI api = WXAPIFactory.CreateWXAPI(_appId); await api.SendReq(request); }
/// <summary> /// 分享网页 /// </summary> /// <param name="title"></param> /// <param name="description"></param> /// <param name="url"></param> /// <param name="thumbnailUri"></param> /// <returns></returns> public static async Task ShareWebAsync(string title, string description, string url, string thumbnailUri) { if (!DeviceUtils.IsMobile) { ToastService.SendToast("PC上不支持微信分享"); return; } try { var scene = SendMessageToWX.Req.WXSceneChooseByUser; var message = new WXWebpageMessage { WebpageUrl = url, Title = title, Description = description }; if (!string.IsNullOrEmpty(thumbnailUri)) { IBuffer buffer = await HttpBaseService.GetBytesAsync(thumbnailUri); message.ThumbData = WindowsRuntimeBufferExtensions.ToArray(buffer); } else { var thumbnail = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Images/ic_logo.png")); using (var stream = await thumbnail.OpenReadAsync()) { byte[] pic = new byte[stream.Size]; await stream.AsStream().ReadAsync(pic, 0, pic.Length); message.ThumbData = pic; } } SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene); IWXAPI api = WXAPIFactory.CreateWXAPI(APP_ID); await api.SendReq(req); } catch (WXException ex) { Debug.WriteLine(ex.Message); } }
public async Task ShareToWechatAsync(byte[] image, string text) { if (image == null) { throw new ArgumentNullException(nameof(image)); } const int scene = SendMessageToWX.Req.WXSceneChooseByUser; var message = new WXImageMessage() { Title = text, ImageData = image }; var req = new SendMessageToWX.Req(message, scene); var api = WXAPIFactory.CreateWXAPI(Constants.WechatAppId); var isValid = await api.SendReq(req); }
protected override void OnCreate (Bundle bundle) { base.OnCreate (bundle); wxApi = WXAPIFactory.CreateWXAPI(this, APP_ID, true); wxApi.RegisterApp(APP_ID); // Set our view from the "main" layout resource SetContentView (Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById<Button>(Resource.Id.myButton); button.Click += delegate { if(wxApi.IsWXAppInstalled && wxApi.IsWXAppSupportAPI){ SendMessageToWX.Req req; WXWebpageObject textObj = new WXWebpageObject(); textObj.WebpageUrl = "http://lucazulian.it"; WXMediaMessage msg = new WXMediaMessage(); msg.Title = "Luca Zulian website"; msg.Description = "Hello xamarin from wechat"; msg.mediaObject = textObj; req = new SendMessageToWX.Req(); req.Transaction = BuildTransaction("webpage"); req.Message = msg; req.Scene = SendMessageToWX.Req.WXSceneSession; bool res = MainActivity.wxApi.SendReq(req); if(res){ Console.WriteLine("successfully sent message"); } } else{ Toast.MakeText(this, "wxApi does not supported!", ToastLength.Long).Show(); } }; }
public static async Task SendWechatShareToUserChoiceRequestAsync(string url, string title, byte[] thumb, string desc = "", ShareType toTimeLine = ShareType.WechatTimeLine) { try { var message = new WXWebpageMessage { WebpageUrl = url, Title = title, Description = desc, ThumbData = thumb }; var requset = new SendMessageToWX.Req( message, toTimeLine == ShareType.WechatTimeLine ? SendMessageToWX.Req.WXSceneTimeline : SendMessageToWX.Req.WXSceneSession); IWXAPI api = WXAPIFactory.CreateWXAPI("wxdfa382a79b754759"); var tes = await api.SendReq(requset); } catch (WXException e) { System.Diagnostics.Debug.WriteLine(e.StackTrace); } }
protected override void OnCreate(Bundle bundle) { base.OnCreate(bundle); wxApi = WXAPIFactory.CreateWXAPI(this, APP_ID, true); wxApi.RegisterApp(APP_ID); // Set our view from the "main" layout resource SetContentView(Resource.Layout.Main); // Get our button from the layout resource, // and attach an event to it Button button = FindViewById <Button>(Resource.Id.myButton); button.Click += delegate { if (wxApi.IsWXAppInstalled && wxApi.IsWXAppSupportAPI) { SendMessageToWX.Req req; WXWebpageObject textObj = new WXWebpageObject(); textObj.WebpageUrl = "http://lucazulian.it"; WXMediaMessage msg = new WXMediaMessage(); msg.Title = "Luca Zulian website"; msg.Description = "Hello xamarin from wechat"; msg.mediaObject = textObj; req = new SendMessageToWX.Req(); req.Transaction = BuildTransaction("webpage"); req.Message = msg; req.Scene = SendMessageToWX.Req.WXSceneSession; bool res = MainActivity.wxApi.SendReq(req); if (res) { Console.WriteLine("successfully sent message"); } } else { Toast.MakeText(this, "wxApi does not supported!", ToastLength.Long).Show(); } }; }
/// <summary> /// 分享图片 /// </summary> /// <param name="title"></param> /// <param name="description"></param> /// <param name="imageUrl"></param> /// <param name="thumbnail"></param> public static async Task ShareImageAsync(string title, string description, string imageUrl, StorageFile thumbnail = null) { if (!DeviceUtils.IsMobile) { ToastService.SendToast("PC上不支持微信分享"); return; } try { var scene = SendMessageToWX.Req.WXSceneChooseByUser; var message = new WXImageMessage { Title = title, Description = description, ImageUrl = imageUrl }; if (thumbnail == null) { thumbnail = await StorageFile.GetFileFromApplicationUriAsync(new Uri("ms-appx:///Assets/Images/ic_logo.png")); } if (thumbnail != null) { using (var stream = await thumbnail.OpenReadAsync()) { var pic = new byte[stream.Size]; await stream.AsStream().ReadAsync(pic, 0, pic.Length); message.ThumbData = pic; } } SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene); IWXAPI api = WXAPIFactory.CreateWXAPI(APP_ID); await api.SendReq(req); } catch (WXException ex) { Debug.WriteLine(ex.Message); } }
const string APP_ID = "wx167b8355f065339c";//wxc6d5cff9be60265d //--读读日报 public async void ShareLink(string url, string title, string description, byte[] thumb, int scene = SendMessageToWX.Req.WXSceneChooseByUser) { try { var message = new WXWebpageMessage { WebpageUrl = url, Title = title, Description = description, ThumbData = thumb }; SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene); IWXAPI api = WXAPIFactory.CreateWXAPI(APP_ID); var isValid = await api.SendReq(req); } catch (WXException) { } }
public async void ShareSong() { try { var scene = SendMessageToWX.Req.WXSceneTimeline; var message = new WXTextMessage { Title = "Sharing a text title!", Text = "This is text content", Description = "This is a text message.这是一个文本消息。", ThumbData = null }; 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); } }
//文字类型分享 private void BtnText_Click(object sender, EventArgs e) { //初始化一个WXTextObject对象,填写分享的文本内容 WXTextObject textObj = new WXTextObject(); textObj.Text = "Hello Xamarin"; //用WXTextObject对象初始化一个WXMediaMessage对象 WXMediaMessage msg = new WXMediaMessage(); msg.MyMediaObject = textObj; msg.Description = "Hello World"; //构造一个Req请求 SendMessageToWX.Req req = new SendMessageToWX.Req(); //唯一的请求标志 req.Transaction = System.Guid.NewGuid().ToString(); req.Message = msg; req.Scene = SendMessageToWX.Req.WXSceneSession; //发送数据 api.SendReq(req); }
/// <summary> /// 分享一段文字 /// </summary> /// <param name="shareContent">参数array注释</param> /// <param name="isWXSceneTimeline">true:分享到朋友圈;false:分享给好友</param> /// <returns>无</returns> public void ShareText(string shareContent, bool isWXSceneTimeline) { if (!TextUtils.IsEmpty(shareContent)) { WXTextObject textObj = new WXTextObject() { Text = shareContent, }; WXMediaMessage msg = new WXMediaMessage() { MyMediaObject = textObj, Description = shareContent, }; SendMessageToWX.Req req = new SendMessageToWX.Req() { Transaction = buildTransaction("text"), Message = msg, Scene = isWXSceneTimeline ? WECHAT_SHARE_TYPE_FRENDS : WECHAT_SHARE_TYPE_TALK, }; mWXApi.SendReq(req); } }
/// <summary> /// 分享一张图片 /// </summary> /// <param name="shareBitmap">网页链接</param> /// <param name="isWXSceneTimeline">true:分享到朋友圈;false:分享给好友</param> /// <returns>无</returns> public void ShareImage(Bitmap shareBitmap, bool isWXSceneTimeline) { WXImageObject imgObj = new WXImageObject(shareBitmap); WXMediaMessage msg = new WXMediaMessage(); msg.MyMediaObject = imgObj; Bitmap thumbBmp = Bitmap.CreateScaledBitmap(shareBitmap, THUMB_SIZE, THUMB_SIZE, true); using (MemoryStream stream = new MemoryStream()) { shareBitmap.Compress(Bitmap.CompressFormat.Png, 100, stream); msg.ThumbData = stream.ToArray(); //设置缩略图 } SendMessageToWX.Req req = new SendMessageToWX.Req() { Transaction = buildTransaction("img"), Message = msg, Scene = isWXSceneTimeline ? WECHAT_SHARE_TYPE_FRENDS : WECHAT_SHARE_TYPE_TALK, }; mWXApi.SendReq(req); }
public async Task <Boolean> ShareAnswerToWeChatTimeline(String wechatAppId, String title, String description, String pageUrl) { try { var scene = SendMessageToWX.Req.WXSceneTimeline; var folder = await Package.Current.InstalledLocation.GetFolderAsync("Resource"); var file = await folder.GetFileAsync("zhihu_m.jpg"); using (var stream = await file.OpenReadAsync()) { var pic = new byte[stream.Size]; await stream.AsStream().ReadAsync(pic, 0, pic.Length); var message = new WXWebpageMessage { WebpageUrl = pageUrl, Title = title, Description = description, ThumbData = pic, }; var req = new SendMessageToWX.Req(message, scene); IWXAPI api = WXAPIFactory.CreateWXAPI(wechatAppId); var isValid = await api.SendReq(req); return(!String.IsNullOrEmpty(isValid)); } } catch (WXException ex) { await UmengAnalytics.TrackException(ex, "ShareAnswerToWeChatTimeline: " + ex.Message); return(false); } }
public async void ShareLink() { 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 WXWebpageMessage { WebpageUrl = "http://www.baidu.com", Title = "Sharing a link!", Description = "This is a link message.这是一个链接消息", ThumbData = pic }; 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); } }
/// <summary> /// 分享文字信息 /// </summary> /// <param name="msg">显示在微信聊天记录的信息</param> /// <param name="description">显示在按[分享]时候的信息</param> /// <returns>返回记录</returns> public bool SendMsg(string msg, string description = "", WXScene scene = 0) { // 初始化一个 WXTextObject 对象,填写分享的文本内容 WXTextObject textObj = new WXTextObject(); textObj.Text = msg; // 用 WXTextObject 对象初始化一个 WXMediaMessage 对象 WXMediaMessage wxMediaMessage = new WXMediaMessage(); wxMediaMessage.MyMediaObject = textObj; wxMediaMessage.Description = description; SendMessageToWX.Req req = new SendMessageToWX.Req(); req.Transaction = System.Guid.NewGuid().ToString(); // 唯一的请求标志 req.Message = wxMediaMessage; // req.Scene = SendMessageToWX.Req.WXSceneSession; // 发送信息 // req.Scene = SendMessageToWX.Req.WXSceneTimeline; // 发送朋友圈 req.Scene = (int)scene; return(api.SendReq(req)); }
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.SendReqAsync(req); } } catch (WXException ex) { Debug.WriteLine(ex.Message); } }
public static void callback_ShareImageUrl(string imgUrl, byte[] thumbData, string title, string desc, int type) { SendMessageToWX.Req req = new SendMessageToWX.Req(msg_image(title, desc, imgUrl, thumbData), getScene(type)); SendReqInternal(req); }
protected override void OnCreate(Bundle savedInstanceState) { TabLayoutResource = Resource.Layout.Tabbar; ToolbarResource = Resource.Layout.Toolbar; //Resources.DisplayMetrics.ScaledDensity = 2;//告诉android不要把自己大小单位缩放 //double systemDensity = DeviceDisplay.MainDisplayInfo.Density; //Resources.DisplayMetrics.Density = 2; //var temp = Resources.DisplayMetrics; //var device = DeviceDisplay.MainDisplayInfo; //if (DeviceDisplay.MainDisplayInfo.Density >= 3) //{ // Resources.DisplayMetrics.ScaledDensity = 1.5F;//告诉android不要把自己大小单位缩放 // Resources.DisplayMetrics.Density = 2.5F; //} //else //{ // Resources.DisplayMetrics.ScaledDensity = 2;//告诉android不要把自己大小单位缩放 // Resources.DisplayMetrics.Density = 2; //} App.ScreenWidth = Resources.DisplayMetrics.WidthPixels; App.ScreenHeight = Resources.DisplayMetrics.HeightPixels; //var width = Resources.DisplayMetrics.WidthPixels; //var height = Resources.DisplayMetrics.HeightPixels; //var density = Resources.DisplayMetrics.Density; //屏幕密度 //App.ScreenWidth = width / density; //屏幕宽度 //App.ScreenHeight = height / density; //屏幕高度 含24个单位的标题栏高度 通过OnSizeAllocated获取的高度不含标题栏高度 if (Build.VERSION.SdkInt >= BuildVersionCodes.Kitkat) { //透明状态栏 //Window.AddFlags(WindowManagerFlags.TranslucentStatus); Window.SetStatusBarColor(Android.Graphics.Color.LightGray); //不遮挡导航栏 Window.AddFlags(WindowManagerFlags.ForceNotFullscreen); } CrossCurrentActivity.Current.Init(this, savedInstanceState); Rg.Plugins.Popup.Popup.Init(this, savedInstanceState); //弹出框 CarouselViewRenderer.Init(); //轮播图 CachedImageRenderer.Init(true); //Forms.SetFlags("CarouselView_Experimental"); Forms.SetFlags("SwipeView_Experimental"); Plugin.XF.AppInstallHelper.CrossInstallHelper.Current.Init("com.wyhl.XMart.fileprovider"); /* #region X5内核 * preInitCallback = new PreInitCallback(); * tbsListener = new TbsListener(); * //加载X5内核 * QbSdk.DownloadWithoutWifi = true; * QbSdk.SetTbsListener(tbsListener); * QbSdk.InitX5Environment(this, preInitCallback); * MessagingCenter.Subscribe<object, string>(this, "PlayVideo", (o, url) => * { * TbsVideo.OpenVideo(this, url); * }); * MessagingCenter.Subscribe<object, string>(this, "OpenFile", async (o, file) => * { * var backingFile = System.IO.Path.Combine(System.Environment.GetFolderPath(System.Environment.SpecialFolder.Personal), file); * if (System.IO.File.Exists(backingFile) == false) * { * using (var stream = Assets.Open(file)) * { * using (var newStream = System.IO.File.Create(backingFile)) * { * await stream.CopyToAsync(newStream); * } * } * } * var openResult = QbSdk.OpenFileReader(this, backingFile, null, new ValueCallback()); * }); #endregion */ //支付宝 MessagingCenter.Subscribe <object, string>(this, "Pay", (sender, sign) => { try { Thread the = new Thread(new ParameterizedThreadStart(Pay)); the.Start(sign); } catch (ThreadAbortException) { } }); #region 微信相关 //注册 MessagingCenter.Subscribe <object>(this, "Register", d => { var result = RegToWx(); }); MessagingCenter.Subscribe <object>(this, "Login", d => { // send oauth request SendAuth.Req req = new SendAuth.Req() { Scope = "snsapi_userinfo", State = "xmart_wechat_login" }; bool result = wxApi.SendReq(req); }); //分享小程序给朋友 MessagingCenter.Subscribe <object, string>(this, "ShareMiniProgramToFriend", (sender, arg) => { string[] args = arg.Split(','); WXMiniProgramObject miniProgramObj = new WXMiniProgramObject { WebpageUrl = "https://www.qq.com", // 兼容低版本的网页链接 MiniprogramType = WXMiniProgramObject.MiniprogramTypePreview, // 正式版:0,测试版:1,体验版:2 UserName = "******", // 小程序原始id Path = "/pages/detail/detail?productId=" + args[0] + "&shareId=" + args[1] //小程序页面路径;对于小游戏,可以只传入 query 部分,来实现传参效果,如:传入 "?foo=bar" }; WXMediaMessage msg = new WXMediaMessage(miniProgramObj) { Title = args[2] + "-美而好,让生活更美好。", // 小程序消息title Description = "这是美而好的简介" // 小程序消息desc }; Stream s = Resources.OpenRawResource(Resource.Drawable.logo); Bitmap mBitmap = BitmapFactory.DecodeStream(s); msg.SetThumbImage(mBitmap); SendMessageToWX.Req req = new SendMessageToWX.Req { Transaction = DateTime.Now.ToFileTimeUtc().ToString(), Message = msg, Scene = SendMessageToWX.Req.WXSceneSession // 目前只支持会话 }; wxApi.SendReq(req); //br.Dispose(); //s.Dispose(); }); //分享文字给朋友 /* * MessagingCenter.Subscribe<object, string>(this, "ShareToFriend", (sender, arg) => * { * WXTextObject textObj = new WXTextObject { Text = arg };//定义wx文本对象 * WXMediaMessage msg = new WXMediaMessage { MyMediaObject = textObj, Description = arg };//定义wxmsg对象 * SendMessageToWX.Req req = new SendMessageToWX.Req() * { * Transaction = DateTime.Now.ToFileTimeUtc().ToString(), * Message = msg, * Scene = SendMessageToWX.Req.WXSceneSession//分享到对话 * }; * wxApi.SendReq(req); * }); * * //分享文字到朋友圈 * MessagingCenter.Subscribe<object, string>(this, "ShareTextToTimeline", (sender, arg) => * { * WXTextObject textObj = new WXTextObject { Text = arg };//定义wx文本对象 * WXMediaMessage msg = new WXMediaMessage { MyMediaObject = textObj, Description = arg };//定义wxmsg对象 * SendMessageToWX.Req req = new SendMessageToWX.Req() * { * Transaction = DateTime.Now.ToFileTimeUtc().ToString(), * Message = msg, * Scene = SendMessageToWX.Req.WXSceneTimeline//分享到朋友圈 * }; * wxApi.SendReq(req); * }); * * //分享网页到朋友圈 * MessagingCenter.Subscribe<object, string>(this, "ShareWebPageToTimeline", (sender, arg) => * { * //初始化一个WXWebpageObject,填写url * WXWebpageObject webpage = new WXWebpageObject * { * WebpageUrl = arg * }; * * //用 WXWebpageObject 对象初始化一个 WXMediaMessage 对象 * WXMediaMessage msg = new WXMediaMessage(webpage) * { * Title = "万联家具批发平台", * Description = "网页描述" * }; * Stream s = Resources.OpenRawResource(Resource.Drawable.logo); * Bitmap mBitmap = BitmapFactory.DecodeStream(s); * msg.SetThumbImage(mBitmap); * * //构造一个Req * SendMessageToWX.Req req = new SendMessageToWX.Req * { * Transaction = DateTime.Now.ToFileTimeUtc().ToString(), * Message = msg, * Scene = SendMessageToWX.Req.WXSceneTimeline, * UserOpenId = getOpenId() * }; * * //调用api接口,发送数据到微信 * wxApi.SendReq(req); * });*/ #endregion base.OnCreate(savedInstanceState); Instance = this; Platform.Init(this, savedInstanceState); // add this line to your code, it may also be called: bundle Forms.Init(this, savedInstanceState); LoadApplication(new App()); }