コード例 #1
0
        /// <summary>
        /// 网页分享到微信朋友圈
        /// </summary>
        /// <param name="url"></param>
        /// <param name="title"></param>
        /// <param name="thumb"></param>
        public async void WebPageShare2TimelineRequest(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.WXSceneTimeline);
            IWXAPI api = WXAPIFactory.CreateWXAPI(APP_ID);

            await api.SendReq(request);
        }
コード例 #2
0
        public async void SendAuth()
        {
            try
            {
                SendAuth.Req req = new SendAuth.Req(AppSettings.Scope, "test");

                IWXAPI api     = WXAPIFactory.CreateWXAPI(AppSettings.AppId);
                var    isValid = await api.SendReq(req);
            }
            catch (WXException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
コード例 #3
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);
            api     = WXAPIFactory.CreateWXAPI(this, appID, true);
            handler = new MyHandler(this);

            try
            {
                Intent intent = this.Intent;
                bool   b      = api.HandleIntent(intent, this);
            }
            catch (Exception e)
            {
                Log.Error(TAG, e.StackTrace);
            }
        }
コード例 #4
0
        /// <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);
            }
        }
コード例 #5
0
        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);
        }
コード例 #6
0
 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); }
 }
コード例 #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();
                }
            };
        }
コード例 #8
0
        /// <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);
            }
        }
コード例 #9
0
 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)
     {
     }
 }
コード例 #10
0
            /*
             * 初始化操作,参数为AppID
             *
             * 如果参数留空,则必须在其他操作调用前执行asWXHelper::RegisterApp()。
             *
             */
            public static void init(string appID = null)
            {
                if (appID != null)
                {
                    mApi = WXAPIFactory.CreateWXAPI(appID);
                    System.Diagnostics.Debugger.Log(0, "[asWXHelperImplMetro]", "init");
                }

                mRef.cb_RegisterApp       += callback_RegisterApp;
                mRef.cb_IsWXAppInstalled  += callback_IsWXAppInstalled;
                mRef.cb_IsWXAppSupportAPI += callback_IsWXAppSupportAPI;

                mRef.cb_ShareText     += callback_ShareText;
                mRef.cb_ShareUrl      += callback_ShareUrl;
                mRef.cb_ShareImage    += callback_ShareImage;
                mRef.cb_ShareImageUrl += callback_ShareImageUrl;

                mInitialized = true;
            }
コード例 #11
0
 /// <summary>
 /// API 包装
 /// </summary>
 /// <param name="context"></param>
 /// <param name="appId"></param>
 /// <param name="isRegisterApp">是否自动注册</param>
 public api(Context context, string appId, bool isRegisterApp = true)
 {
     if (isRegisterApp)
     {
         Api   = WXAPIFactory.CreateWXAPI(context, null);
         IsApi = Api.IsWXAppInstalled && Api.IsWXAppSupportAPI;
         if (!IsApi || !Api.RegisterApp(appId))
         {
             Api   = null;
             IsApi = false;
             fastCSharp.log.Default.Add("微信 API 注册失败", new System.Diagnostics.StackFrame(), false);
         }
     }
     else
     {
         Api   = WXAPIFactory.CreateWXAPI(context, appId);
         IsApi = Api.IsWXAppInstalled && Api.IsWXAppSupportAPI;
     }
 }
コード例 #12
0
 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);
     }
 }
コード例 #13
0
ファイル: MainActivity.cs プロジェクト: yangkirld/WeChatDemo
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            // Set our view from the "main" layout resource
            SetContentView(Resource.Layout.Main);

            // 通过WXAPIFactory工厂,获取IWXAPI的实例
            api = WXAPIFactory.CreateWXAPI(this, APP_ID, false);

            Button btnRegister = FindViewById <Button>(Resource.Id.btnRegister);

            btnRegister.Click += BtnRegister_Click;
            Button btnText = FindViewById <Button>(Resource.Id.btnText);

            btnText.Click += BtnText_Click;
            Button btnHtml = FindViewById <Button>(Resource.Id.btnHtml);

            btnHtml.Click += BtnHtml_Click;
            Button btnImage = FindViewById <Button>(Resource.Id.btnImage);

            btnImage.Click += BtnImage_Click;
            Button btnVideo = FindViewById <Button>(Resource.Id.btnVideo);

            btnVideo.Click += BtnVideo_Click;
            Button btnMusic = FindViewById <Button>(Resource.Id.btnMusic);

            btnMusic.Click += BtnMusic_Click;
            Button btnProject = FindViewById <Button>(Resource.Id.btnProject);

            btnProject.Click += BtnProject_Click;
            Button btnOpenWeChat = FindViewById <Button>(Resource.Id.btnOpenWeChat);

            btnOpenWeChat.Click += BtnOpenWeChat_Click;
            Button btnIsMoments = FindViewById <Button>(Resource.Id.btnIsMoments);

            btnIsMoments.Click += BtnIsMoments_Click;
        }
コード例 #14
0
        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);
            }
        }
コード例 #15
0
        //拉起微信支付
        private void btnPay_Click(object sender, RoutedEventArgs e)
        {
            if (mReqDict == null || mReqDict.Count == 0)
            {
                MessageBox.Show("please get prepayid first");
                return;
            }
            string AppID = mReqDict["appid"];
            // Summary:
            //      随机串,防重发
            string NonceStr = mReqDict["noncestr"];
            //
            // Summary:
            //      商家根据财付通文档填写的数据和签名
            string Package = mReqDict["packageforsdk"];
            //
            // Summary:
            //      商家向财付通申请的商家id
            string PartnerId = ConstString.PARTNER_ID;
            //
            // Summary:
            //      预支付订单 预支付订单
            string PrepayId = mReqDict["prepayid"];
            //
            // Summary:
            //      商家根据微信开放平台文档对数据做的签名
            string Sign = mReqDict["signsha1"];
            //
            // Summary:
            //      时间戳,防重发
            uint TimeStamp = uint.Parse(mReqDict["timestamp"]);

            SendPay.Req req = new SendPay.Req(PartnerId, PrepayId, NonceStr, TimeStamp, Package, Sign);
            IWXAPI      api = WXAPIFactory.CreateWXAPI(AppID);

            api.SendReq(req);
        }
コード例 #16
0
        /// <summary>
        /// 调起支付
        /// </summary>
        /// <param name="context"></param>
        /// <param name="AppId">微信开放平台审核通过的应用APPID</param>
        /// <param name="partnerId">微信支付分配的商户号</param>
        /// <param name="prepayId">调用接口提交的终端设备号</param>
        /// <param name="nonceStr">随机字符串,不长于32位</param>
        /// <param name="timeStamp">时间戳</param>
        /// <param name="sign">签名</param>
        /// <returns></returns>
        public bool Pay(Context context, string AppId, string partnerId, string prepayId, string nonceStr, string timeStamp, string sign)
        {
            var api = WXAPIFactory.CreateWXAPI(context, AppId);

            api.RegisterApp("APP_ID");

            PayReq payRequest = new PayReq();

            payRequest.AppId = AppId;

            payRequest.PartnerId = partnerId;

            payRequest.PrepayId = prepayId;

            payRequest.PackageValue = "Sign=WXPay";

            payRequest.NonceStr = nonceStr;

            payRequest.TimeStamp = timeStamp;

            payRequest.Sign = sign;

            return(api.SendReq(payRequest));
        }
コード例 #17
0
ファイル: MainPage.xaml.cs プロジェクト: zhxilin/WeChatSDK
        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);
            }
        }
コード例 #18
0
        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);
            }
        }
コード例 #19
0
        //用户选择内容后,应用组织响应数据,发给微信
        //所有发送数据的按钮的处理函数,根据点击不同,组织不同数据发送给微信
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            string        AppID   = ConstString.APPID;
            int           scene   = SendMessageToWX.Req.WXSceneSession;
            WXBaseMessage message = null;

            byte[] png = readRes("Res/1.png");
            byte[] jpg = readRes("Res/1.jpg");
            byte[] gif = readRes("Res/1.gif");
            byte[] txt = readRes("Res/1.txt");
            byte[] doc = readRes("Res/1.doc");

            //文本数据的组装
            if (sender == btnTxt)
            {
                WXTextMessage msg = new WXTextMessage();
                msg.Title     = "text";
                msg.ThumbData = null;
                msg.Text      = "this is a text";
                message       = msg;
            }

            //图片数据的组装
            if (sender == btnImg)
            {
                WXImageMessage msg = new WXImageMessage();
                msg.Title       = "picture";
                msg.Description = "this is a picture";
                msg.ThumbData   = png;

                //图片的byte[]数据
                msg.ImageData = jpg;

                //图片的网络链接,ImageUrl和ImageData二者取其一,不要同时都填值
                //msg.ImageUrl = "http://soso7.gtimg.cn/sosopic/0/4085165533549977883/150";

                msg.ImageUrl = " ";
                message      = msg;
            }

            //动态表情数据的组装
            if (sender == btnEmj)
            {
                WXEmojiMessage msg = new WXEmojiMessage();
                msg.Title       = "Gif";
                msg.Description = "this is a Gif";
                msg.ThumbData   = png;

                msg.EmojiData = gif;

                message = msg;
            }

            //文件数据的组装
            if (sender == btnFile)
            {
                WXFileMessage msg = new WXFileMessage();
                msg.Title       = "file";
                msg.Description = "this is a file";
                msg.ThumbData   = png;

                msg.FileData = doc;
                msg.FileName = "1.doc";

                message = msg;
            }

            //链接数据的组装
            if (sender == btnUrl)
            {
                WXWebpageMessage msg = new WXWebpageMessage();
                msg.Title       = "qq homepage";
                msg.Description = "goto qq homepage";
                msg.ThumbData   = png;

                msg.WebpageUrl = "http://www.qq.com";

                message = msg;
            }

            //音乐数据的组装
            if (sender == btnMusic)
            {
                WXMusicMessage msg = new WXMusicMessage();
                msg.Title       = "music";
                msg.Description = "by XXX";
                msg.ThumbData   = png;

                msg.MusicUrl        = "http://y.qq.com/i/song.html#p=7B22736F6E675F4E616D65223A2220E998BFE5A3ABE58CB9E781B5222C22736F6E675F5761704C69766555524C223A22687474703A2F2F74736D7573696334382E74632E71712E636F6D2F586B30305156374F4141414134674141414250657376594E4D7A55327A4441784E654D35586A4A63366F76484F415942443174754251414F4347384439394B343965776F6244733D2F31313134383332342E6D34613F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D30222C22736F6E675F5769666955524C223A22687474703A2F2F73747265616D31312E71716D757369632E71712E636F6D2F33313134383332342E6D7033222C226E657454797065223A2277696669222C22736F6E675F416C62756D223A22E88BB1E79A87E7B2BEE9808932303038222C22736F6E675F4944223A313134383332342C22736F6E675F54797065223A312C22736F6E675F53696E676572223A22E99988E5A595E8BF85222C22736F6E675F576170446F776E4C6F616455524C223A22687474703A2F2F74736D757369633132382E74632E71712E636F6D2F586C464E4D31376C414141415977414141442F6954452B656E7A457A6D6A59324D4D55314F444C5230483937504B344142713850446D3550476C56436366394D536661644D5464704E7A3163665451344D673D3D2F33313134383332342E6D70333F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D3026616D703B73747265616D5F706F733D35227D";
                msg.MusicLowBandUrl = "http://y.qq.com/i/song.html#p=7B22736F6E675F4E616D65223A2220E998BFE5A3ABE58CB9E781B5222C22736F6E675F5761704C69766555524C223A22687474703A2F2F74736D7573696334382E74632E71712E636F6D2F586B30305156374F4141414134674141414250657376594E4D7A55327A4441784E654D35586A4A63366F76484F415942443174754251414F4347384439394B343965776F6244733D2F31313134383332342E6D34613F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D30222C22736F6E675F5769666955524C223A22687474703A2F2F73747265616D31312E71716D757369632E71712E636F6D2F33313134383332342E6D7033222C226E657454797065223A2263617272696572222C22736F6E675F416C62756D223A22E88BB1E79A87E7B2BEE9808932303038222C22736F6E675F4944223A313134383332342C22736F6E675F54797065223A312C22736F6E675F53696E676572223A22E99988E5A595E8BF85222C22736F6E675F576170446F776E4C6F616455524C223A22687474703A2F2F74736D757369633132382E74632E71712E636F6D2F586C464E4D31376C414141415977414141442F6954452B656E7A457A6D6A59324D4D55314F444C5230483937504B344142713850446D3550476C56436366394D536661644D5464704E7A3163665451344D673D3D2F33313134383332342E6D70333F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D3026616D703B73747265616D5F706F733D35227D";

                message = msg;
            }

            //视频数据的组装
            if (sender == btnVedio)
            {
                WXVideoMessage msg = new WXVideoMessage();
                msg.Title       = "music";
                msg.Description = "by XXX";
                msg.ThumbData   = png;

                msg.VideoUrl        = "http://y.qq.com/i/song.html#p=7B22736F6E675F4E616D65223A2220E998BFE5A3ABE58CB9E781B5222C22736F6E675F5761704C69766555524C223A22687474703A2F2F74736D7573696334382E74632E71712E636F6D2F586B30305156374F4141414134674141414250657376594E4D7A55327A4441784E654D35586A4A63366F76484F415942443174754251414F4347384439394B343965776F6244733D2F31313134383332342E6D34613F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D30222C22736F6E675F5769666955524C223A22687474703A2F2F73747265616D31312E71716D757369632E71712E636F6D2F33313134383332342E6D7033222C226E657454797065223A2277696669222C22736F6E675F416C62756D223A22E88BB1E79A87E7B2BEE9808932303038222C22736F6E675F4944223A313134383332342C22736F6E675F54797065223A312C22736F6E675F53696E676572223A22E99988E5A595E8BF85222C22736F6E675F576170446F776E4C6F616455524C223A22687474703A2F2F74736D757369633132382E74632E71712E636F6D2F586C464E4D31376C414141415977414141442F6954452B656E7A457A6D6A59324D4D55314F444C5230483937504B344142713850446D3550476C56436366394D536661644D5464704E7A3163665451344D673D3D2F33313134383332342E6D70333F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D3026616D703B73747265616D5F706F733D35227D";
                msg.VideoLowBandUrl = "http://y.qq.com/i/song.html#p=7B22736F6E675F4E616D65223A2220E998BFE5A3ABE58CB9E781B5222C22736F6E675F5761704C69766555524C223A22687474703A2F2F74736D7573696334382E74632E71712E636F6D2F586B30305156374F4141414134674141414250657376594E4D7A55327A4441784E654D35586A4A63366F76484F415942443174754251414F4347384439394B343965776F6244733D2F31313134383332342E6D34613F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D30222C22736F6E675F5769666955524C223A22687474703A2F2F73747265616D31312E71716D757369632E71712E636F6D2F33313134383332342E6D7033222C226E657454797065223A2263617272696572222C22736F6E675F416C62756D223A22E88BB1E79A87E7B2BEE9808932303038222C22736F6E675F4944223A313134383332342C22736F6E675F54797065223A312C22736F6E675F53696E676572223A22E99988E5A595E8BF85222C22736F6E675F576170446F776E4C6F616455524C223A22687474703A2F2F74736D757369633132382E74632E71712E636F6D2F586C464E4D31376C414141415977414141442F6954452B656E7A457A6D6A59324D4D55314F444C5230483937504B344142713850446D3550476C56436366394D536661644D5464704E7A3163665451344D673D3D2F33313134383332342E6D70333F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D3026616D703B73747265616D5F706F733D35227D";

                message = msg;
            }

            //给微信发送响应数据,会回到微信的聊天界面,数据错误或发送错误,会抛出WXException。
            try
            {
                GetMessageFromWX.Resp resp = new GetMessageFromWX.Resp(mRequest.Transaction, mRequest.Username, message);
                IWXAPI api = WXAPIFactory.CreateWXAPI(AppID);
                api.SendResp(resp);
            }
            catch (WXException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #20
0
 public WXPay(Context context)
 {
     this.Context = context;
     mSb          = new StringBuilder();
     msgApi       = WXAPIFactory.CreateWXAPI(context, Constants.APPID);
 }
コード例 #21
0
        //所有发送数据的按钮的处理函数,根据点击不同,组织不同数据发送给微信
        private void Button_Click_1(object sender, RoutedEventArgs e)
        {
            System.Diagnostics.Debug.WriteLine("############################");
            System.Diagnostics.Debug.WriteLine("Button_Click_1 in");
            string        AppID   = ConstString.APPID;
            int           scene   = SendMessageToWX.Req.WXSceneSession; //发给微信朋友
            WXBaseMessage message = null;

            //拉起微信
            if (btnLaunch == sender)
            {
                WXAPIFactory.CreateWXAPI(AppID).OpenWXApp();
                return;
            }

            //读取实例数据,示例数据都是从res中读取,实现时根据你的应用实际情况取得数据
            byte[] png = readRes("Res/1.png"); //thumb
            byte[] jpg = readRes("Res/1.jpg"); //pic
            byte[] gif = readRes("Res/1.gif"); //emoji
            byte[] txt = readRes("Res/1.txt"); //text
            byte[] doc = readRes("Res/1.doc"); //word file

            //发送到朋友圈,设置scene为WXSceneTimeline
            if (sender == btnTxtSns || sender == btnImgSns || sender == btnUrlSns || sender == btnMusicSns)
            {
                scene = SendMessageToWX.Req.WXSceneTimeline;
            }

            //用户选择发给好友还是朋友圈,设置scene为WXSceneChooseByUser
            if (sender == btnTxt_ChooseByUser)
            {
                scene = SendMessageToWX.Req.WXSceneChooseByUser;
            }

            //文本数据的组装
            if (sender == btnTxt || sender == btnTxtSns)
            {
                WXTextMessage msg = new WXTextMessage();
                msg.Title     = "text";
                msg.ThumbData = null;
                msg.Text      = "this is a text";
                message       = msg;
            }

            //图片数据的组装
            if (sender == btnImg || sender == btnImgSns)
            {
                WXImageMessage msg = new WXImageMessage();
                msg.Title       = "picture";
                msg.Description = "this is a picture";
                msg.ThumbData   = png;

                //图片的byte[]数据
                //msg.ImageData = jpg;

                //图片的网络链接,ImageUrl和ImageData二者取其一,不要同时都填值
                msg.ImageUrl = "http://soso7.gtimg.cn/sosopic/0/4085165533549977883/150";

                message = msg;
            }

            //动态表情数据的组装
            if (sender == btnEmj)
            {
                WXEmojiMessage msg = new WXEmojiMessage();
                msg.Title       = "Gif";
                msg.Description = "this is a Gif";
                msg.ThumbData   = png;

                msg.EmojiData = gif;

                message = msg;
            }

            //文件数据的组装
            if (sender == btnFile)
            {
                WXFileMessage msg = new WXFileMessage();
                msg.Title       = "file";
                msg.Description = "this is a file";
                msg.ThumbData   = png;

                msg.FileData = doc;
                msg.FileName = "1.doc";

                message = msg;
            }

            //链接数据的组装
            if (sender == btnUrl || sender == btnUrlSns)
            {
                WXWebpageMessage msg = new WXWebpageMessage();
                msg.Title       = "qq homepage";
                msg.Description = "goto qq homepage";
                msg.ThumbData   = png;

                msg.WebpageUrl = "http://www.qq.com";

                message = msg;
            }

            //音乐数据的组装
            if (sender == btnMusic || sender == btnMusicSns || sender == btnTxt_ChooseByUser)
            {
                WXMusicMessage msg = new WXMusicMessage();
                msg.Title       = "music";
                msg.Description = "by XXX";
                msg.ThumbData   = png;

                msg.MusicUrl        = "http://y.qq.com/i/song.html#p=7B22736F6E675F4E616D65223A2220E998BFE5A3ABE58CB9E781B5222C22736F6E675F5761704C69766555524C223A22687474703A2F2F74736D7573696334382E74632E71712E636F6D2F586B30305156374F4141414134674141414250657376594E4D7A55327A4441784E654D35586A4A63366F76484F415942443174754251414F4347384439394B343965776F6244733D2F31313134383332342E6D34613F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D30222C22736F6E675F5769666955524C223A22687474703A2F2F73747265616D31312E71716D757369632E71712E636F6D2F33313134383332342E6D7033222C226E657454797065223A2277696669222C22736F6E675F416C62756D223A22E88BB1E79A87E7B2BEE9808932303038222C22736F6E675F4944223A313134383332342C22736F6E675F54797065223A312C22736F6E675F53696E676572223A22E99988E5A595E8BF85222C22736F6E675F576170446F776E4C6F616455524C223A22687474703A2F2F74736D757369633132382E74632E71712E636F6D2F586C464E4D31376C414141415977414141442F6954452B656E7A457A6D6A59324D4D55314F444C5230483937504B344142713850446D3550476C56436366394D536661644D5464704E7A3163665451344D673D3D2F33313134383332342E6D70333F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D3026616D703B73747265616D5F706F733D35227D";
                msg.MusicLowBandUrl = "http://y.qq.com/i/song.html#p=7B22736F6E675F4E616D65223A2220E998BFE5A3ABE58CB9E781B5222C22736F6E675F5761704C69766555524C223A22687474703A2F2F74736D7573696334382E74632E71712E636F6D2F586B30305156374F4141414134674141414250657376594E4D7A55327A4441784E654D35586A4A63366F76484F415942443174754251414F4347384439394B343965776F6244733D2F31313134383332342E6D34613F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D30222C22736F6E675F5769666955524C223A22687474703A2F2F73747265616D31312E71716D757369632E71712E636F6D2F33313134383332342E6D7033222C226E657454797065223A2263617272696572222C22736F6E675F416C62756D223A22E88BB1E79A87E7B2BEE9808932303038222C22736F6E675F4944223A313134383332342C22736F6E675F54797065223A312C22736F6E675F53696E676572223A22E99988E5A595E8BF85222C22736F6E675F576170446F776E4C6F616455524C223A22687474703A2F2F74736D757369633132382E74632E71712E636F6D2F586C464E4D31376C414141415977414141442F6954452B656E7A457A6D6A59324D4D55314F444C5230483937504B344142713850446D3550476C56436366394D536661644D5464704E7A3163665451344D673D3D2F33313134383332342E6D70333F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D3026616D703B73747265616D5F706F733D35227D";

                message = msg;
            }

            //视频数据的组装
            if (sender == btnVedio)
            {
                WXVideoMessage msg = new WXVideoMessage();
                msg.Title       = "music";
                msg.Description = "by XXX";
                msg.ThumbData   = png;

                msg.VideoUrl        = "http://y.qq.com/i/song.html#p=7B22736F6E675F4E616D65223A2220E998BFE5A3ABE58CB9E781B5222C22736F6E675F5761704C69766555524C223A22687474703A2F2F74736D7573696334382E74632E71712E636F6D2F586B30305156374F4141414134674141414250657376594E4D7A55327A4441784E654D35586A4A63366F76484F415942443174754251414F4347384439394B343965776F6244733D2F31313134383332342E6D34613F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D30222C22736F6E675F5769666955524C223A22687474703A2F2F73747265616D31312E71716D757369632E71712E636F6D2F33313134383332342E6D7033222C226E657454797065223A2277696669222C22736F6E675F416C62756D223A22E88BB1E79A87E7B2BEE9808932303038222C22736F6E675F4944223A313134383332342C22736F6E675F54797065223A312C22736F6E675F53696E676572223A22E99988E5A595E8BF85222C22736F6E675F576170446F776E4C6F616455524C223A22687474703A2F2F74736D757369633132382E74632E71712E636F6D2F586C464E4D31376C414141415977414141442F6954452B656E7A457A6D6A59324D4D55314F444C5230483937504B344142713850446D3550476C56436366394D536661644D5464704E7A3163665451344D673D3D2F33313134383332342E6D70333F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D3026616D703B73747265616D5F706F733D35227D";
                msg.VideoLowBandUrl = "http://y.qq.com/i/song.html#p=7B22736F6E675F4E616D65223A2220E998BFE5A3ABE58CB9E781B5222C22736F6E675F5761704C69766555524C223A22687474703A2F2F74736D7573696334382E74632E71712E636F6D2F586B30305156374F4141414134674141414250657376594E4D7A55327A4441784E654D35586A4A63366F76484F415942443174754251414F4347384439394B343965776F6244733D2F31313134383332342E6D34613F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D30222C22736F6E675F5769666955524C223A22687474703A2F2F73747265616D31312E71716D757369632E71712E636F6D2F33313134383332342E6D7033222C226E657454797065223A2263617272696572222C22736F6E675F416C62756D223A22E88BB1E79A87E7B2BEE9808932303038222C22736F6E675F4944223A313134383332342C22736F6E675F54797065223A312C22736F6E675F53696E676572223A22E99988E5A595E8BF85222C22736F6E675F576170446F776E4C6F616455524C223A22687474703A2F2F74736D757369633132382E74632E71712E636F6D2F586C464E4D31376C414141415977414141442F6954452B656E7A457A6D6A59324D4D55314F444C5230483937504B344142713850446D3550476C56436366394D536661644D5464704E7A3163665451344D673D3D2F33313134383332342E6D70333F7569643D3233343931313534393826616D703B63743D3026616D703B636869643D3026616D703B73747265616D5F706F733D35227D";

                message = msg;
            }

            //把数据发送给微信,数据错误或发送错误,会抛出WXException,调试时,可从WXException中得知是什么错误。
            //发布应用时,可直接向用户提示错误,也可以根据自己实际需要定制错误的处理
            try
            {
                SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene);
                IWXAPI api = WXAPIFactory.CreateWXAPI(AppID);

                Console.WriteLine("api.SendReq in");
                api.SendReq(req);
            }
            catch (WXException ex)
            {
                MessageBox.Show(ex.Message);
            }
        }
コード例 #22
0
 private bool RegToWx()
 {
     wxApi = WXAPIFactory.CreateWXAPI(this, appID, true);
     return(wxApi.RegisterApp(appID));
 }
コード例 #23
0
ファイル: MainPage.xaml.cs プロジェクト: jackjet870/WeChatSDK
        private async void ButtonBase_OnClick(object sender, RoutedEventArgs e)
        {
            try
            {
                try
                {
                    SendAuth.Req req = new SendAuth.Req("[YOUR SCOPE]", "test");

                    IWXAPI api  = WXAPIFactory.CreateWXAPI("[YOUR APP ID]");
                    var    isok = await api.SendReq(req);
                }
                catch (WXException)
                {
                }

                //int scene = SendMessageToWX.Req.WXSceneTimeline; //发给微信朋友

                //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 = "title",
                //        Description = "desc",
                //        ThumbData = pic
                //    };

                //    try
                //    {
                //        SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene);
                //        IWXAPI api = WXAPIFactory.CreateWXAPI("[YOUR APP ID]");
                //        var isok = await api.SendReq(req);
                //    }
                //    catch (WXException)
                //    {
                //    }
                //}

                //var message = new WXTextMessage();
                //message.Title = "flora";
                //message.Text = "这是一段文本内容";
                //message.ThumbData = null;
                //SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene);
                //IWXAPI api = WXAPIFactory.CreateWXAPI("[YOUR APP ID]");
                //var isok = await api.SendReq(req);

                //WXImageMessage message = new WXImageMessage();
                //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);
                //    message.Title = "tupian";
                //    message.Description = "desc";
                //    message.ThumbData = pic;
                //    message.ImageUrl = "http://tp3.sinaimg.cn/1882347990/180/5725518284/1";

                //    try
                //    {
                //        SendMessageToWX.Req req = new SendMessageToWX.Req(message, scene);
                //        IWXAPI api = WXAPIFactory.CreateWXAPI("[YOUR APP ID]");
                //        var isok = await api.SendReq(req);
                //    }
                //    catch (WXException)
                //    {
                //    }
                //}
            }
            catch (Exception ex)
            {
                //new MessageDialog(ex.Message).ShowAsync();
            }
        }
コード例 #24
0
 public MyWeChatOpenSDK(string app_id)
 {
     mAPP_ID = app_id;
     api     = WXAPIFactory.CreateWXAPI(Android.App.Application.Context, mAPP_ID, false); // 通过WXAPIFactory工厂,获取实例
 }