Exemplo n.º 1
0
        //分享图片
        partial void UIButton12_TouchUpInside(UIButton sender)
        {
            try
            {
                //初始化一个WXImageObject对象,设置要分享的图片
                WXImageObject imageObj = new WXImageObject();
                NSData        data     = NSData.FromFile("icon.png");
                imageObj.ImageData = data;

                //设置WXMediaMessage对象
                WXMediaMessage msg = new WXMediaMessage();
                msg.SetThumbImage(UIImage.FromFile("icon.png"));
                msg.MediaObject = imageObj;

                //构造SendMessageToWXReq请求
                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();
            }
        }
Exemplo n.º 2
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();
            }
        }
Exemplo n.º 3
0
        //分享视频
        partial void UIButton11_TouchUpInside(UIButton sender)
        {
            try
            {
                //初始化一个WXVideoObject对象,设置分享视频的属性
                WXVideoObject videoObj = new WXVideoObject();
                videoObj.VideoUrl = "http://www.qq.com";

                //设置WXMediaMessage对象
                WXMediaMessage msg = new WXMediaMessage();
                msg.Title       = "视频标题";
                msg.Description = "视频描述";
                msg.SetThumbImage(UIImage.FromFile("icon.png"));
                msg.MediaObject = videoObj;

                //构造SendMessageToWXReq请求
                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();
            }
        }
Exemplo n.º 4
0
        /// <summary>
        /// Sends the auth request.
        /// </summary>
        public void SendAuthRequest(string scope, string state)
        {
            SendAuthReq req = new SendAuthReq()
            {
                Scope = scope,
                State = state
            };

            WXApi.SendReq(req, null);
        }
Exemplo n.º 5
0
 public void WXLogin()
 {
     if (IsWXSupported())
     {
         SendAuthReq req = new SendAuthReq();
         req.Scope = "snsapi_userinfo";
         req.State = "123";
         WXApi.SendReq(req);
     }
 }
Exemplo n.º 6
0
        //发送信息到朋友圈
        public bool SendText(string text)
        {
            SendMessageToWXReq req = new SendMessageToWXReq();

            req.Text  = text;
            req.BText = true;
            req.Scene = 1;
            WXApi.SendReq(req);

            return(true);
        }
Exemplo n.º 7
0
        /// <summary>
        /// 发送信息到朋友圈
        /// </summary>
        /// <param name="text">消息内容.</param>
        /// <param name="scene">发送场景(可以选择发送到会话(Session), 朋友圈(Timeline), 收藏(Favorite), 指定联系人(SpecifiedSession)。 默认发送到会话)</param>
        public void SendText(string text, int scene = 0)
        {
            SendMessageToWXReq req = new SendMessageToWXReq()
            {
                Text  = text,
                BText = true,
                Scene = scene
            };

            WXApi.SendReq(req, null);
        }
        //
        // This method is invoked when the application has loaded and is ready to run. In this
        // method you should instantiate the window, load the UI into it and then make the window
        // visible.
        //
        // You have 17 seconds to return from this method, or iOS will terminate your application.
        //
        public override bool FinishedLaunching(UIApplication app, NSDictionary options)
        {
            wxApiDelegate = new CustomizeWXApiDelegate();
            MessagingCenter.Subscribe <object>(this, PubSubMessage.Register, d =>
            {
                var result = WXApi.RegisterApp(appid: "", universalLink: "");
                MessagingCenter.Send(new object(), PubSubMessage.Registered, result);
            });

            MessagingCenter.Subscribe <object>(this, PubSubMessage.ShareToFriend, d =>
            {
                var req = new SendMessageToWXReq()
                {
                    Scene = (int)WXScene.Session,
                    Text  = "这是Xamarin发送的消息!",
                    BText = true,
                };
                WXApi.SendReq(req, isOK =>
                {
                });
            });

            MessagingCenter.Subscribe <object>(this, PubSubMessage.ShareToFavourite, d =>
            {
                var req = new SendMessageToWXReq()
                {
                    Scene = (int)WXScene.Favorite,
                    Text  = "这是Xamarin发送的消息!",
                    BText = true,
                };
                WXApi.SendReq(req, isOK =>
                {
                });
            });

            MessagingCenter.Subscribe <object>(this, PubSubMessage.ShareToTimeline, d =>
            {
                var req = new SendMessageToWXReq()
                {
                    Scene = (int)WXScene.Timeline,
                    Text  = "这是Xamarin发送的消息!",
                    BText = true,
                };
                WXApi.SendReq(req, isOK =>
                {
                });
            });

            global::Xamarin.Forms.Forms.Init();
            LoadApplication(new App());

            return(base.FinishedLaunching(app, options));
        }
        void WXSendMessage(string text)
        {
            try
            {
                SendMessageToWXReq req = new SendMessageToWXReq();
                req.Text  = text;
                req.BText = true;
                req.Scene = (int)WXScene.Session;

                var         result    = WXApi.SendReq(req);
                UIAlertView alertView = new UIAlertView("", "分享结果:" + result, null, "取消");
                alertView.Show();
            }
            catch (Exception ex)
            {
                UIAlertView alertView = new UIAlertView("", "错误:" + ex, null, "取消");
                alertView.Show();
            }
        }
Exemplo n.º 10
0
        //分享文本
        partial void UIButton9_TouchUpInside(UIButton sender)
        {
            try
            {
                SendMessageToWXReq req = new SendMessageToWXReq();
                req.Text  = @"微信分享及收藏是指第三方App通过接入该功能,让用户可以从App分享文字、图片、音乐、视频、网页至微信好友会话、朋友圈或添加到微信收藏。
                         微信分享及收藏功能已向全体开发者开放,开发者在微信开放平台帐号下申请App并通过审核后,即可获得微信分享及收藏权限。
                         微信分享及收藏目前支持文字、图片、音乐、视频、网页共五种类型。开发者在App中在集成微信SDK后,可调用接口实现,以下依次是文字分享、图片分享、音乐分享、视频分享、网站分享的示例。";
                req.BText = true;
                req.Scene = (int)WXScene.Session;

                var         result    = WXApi.SendReq(req);
                UIAlertView alertView = new UIAlertView("", "分享结果:" + result, null, "取消");
                alertView.Show();
            }
            catch (Exception ex)
            {
                UIAlertView alertView = new UIAlertView("", "异常:" + ex, null, "取消");
                alertView.Show();
            }
        }