Beispiel #1
0
        /// <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 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);
        }
Beispiel #3
0
        //分享网页
        partial void UIButton5_TouchUpInside(UIButton sender)
        {
            try
            {
                WXMediaMessage msg = new WXMediaMessage();
                msg.Title       = "Xamarin官方网站";
                msg.Description = "Xamarin官方网站的描述";
                msg.SetThumbImage(UIImage.FromFile("icon.png"));

                WXWebpageObject webObj = new WXWebpageObject();
                webObj.WebpageUrl = "https://www.xamarin.com";
                msg.MediaObject   = webObj;

                SendMessageToWXReq req = new SendMessageToWXReq();
                req.BText   = false;
                req.Message = msg;
                req.Scene   = (int)WXScene.Timeline;

                var result = WXApi.SendReq(req);

                UIAlertView alertView = new UIAlertView("", "分享结果:" + result, null, "取消");
                alertView.Show();
            }
            catch (Exception ex)
            {
                UIAlertView alertView = new UIAlertView("", "异常:" + ex, null, "取消");
                alertView.Show();
            }
        }
Beispiel #4
0
        //网页类型分享
        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);
        }
Beispiel #5
0
 /// <summary>
 /// 分享网页
 /// </summary>
 /// <param name="url">网页 URI</param>
 /// <param name="title">标题</param>
 /// <param name="description">描述</param>
 /// <param name="thumbnail">缩略图</param>
 /// <param name="thumbnailNeedRecycle">缩略图是否需要回收</param>
 /// <param name="scene">分享场景</param>
 /// <returns>是否发送成功,不等于分享成功</returns>
 public bool ShareWeb(string url, string title, string description = null, Bitmap thumbnail = null, bool thumbnailNeedRecycle = true, shareScene scene = shareScene.WXSceneSession)
 {
     if (IsApi)
     {
         WXWebpageObject web = new WXWebpageObject(url);
         return(share("webpage", web, title, description, thumbnail, thumbnailNeedRecycle, scene));
     }
     return(false);
 }
		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();
				}

			};

		}
Beispiel #7
0
        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();
                }
            };
        }