Exemplo n.º 1
0
        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);
            }
        }
Exemplo n.º 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

            SetContentView(Resource.Layout.vipcompany);
            am      = (MyApplication)this.Application;
            orderid = DateTime.Now.ToString("yyyyMMddHHmmss") + am.Appuser.Uid;
            var toolbar = inittoolbar("会员企业");

            //注册微信
            satetact = this;
            wxApi    = WXAPIFactory.CreateWXAPI(this, appid, true);
            wxApi.RegisterApp(appid);
            btn_tovip = FindViewById <Button>(Resource.Id.btn_vip);
            vipstate  = FindViewById <TextView>(Resource.Id.vipstate);

            btn_tovip.Click += (s, e) =>
            {
                if (wxApi.IsWXAppInstalled)
                {
                    sendpayorder();
                }
                else
                {
                    Toast.MakeText(satetact, "该手机上未安装微信", ToastLength.Short).Show();
                }
            };
        }
Exemplo n.º 3
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);
            //官方demo的app_id,如使用请用本项目中的debug.keystore!!!可简单的覆盖Xamarin.Android的原有debug.keystore
            //强烈建议使用自建的微信app_id和keystore,注意包名等细节,确保可正常调起,如何创建请百度
            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 { wxapi.WXUtil.sendWxReq(this, "http://www.qmyd360.com", "Xamarin.Android Wechat Binding", "Hello Xmarin", null, 1); };

            Button button1 = FindViewById <Button>(Resource.Id.MyButton1);

            button1.Click += delegate { wxapi.WXUtil.sendWxReq(this, "http://www.qmyd360.com", "Xamarin.Android Wechat Binding", "Hello Xmarin", null, 0); };

            Button button2 = FindViewById <Button>(Resource.Id.MyButton2);

            button2.Click += delegate { wxApi.OpenWXApp(); };
        }
Exemplo n.º 4
0
        protected override void OnCreate(Bundle savedInstanceState)
        {
            base.OnCreate(savedInstanceState);

            // Create your application here
            msgApi = WXAPIFactory.CreateWXAPI(this.ApplicationContext, Constants.APPID);
        }
Exemplo n.º 5
0
        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, Configuration.APP_ID, false);

            // Get our button from the layout resource,
            // and attach an event to it
            Button butRegisterApp = FindViewById <Button>(Resource.Id.butRegisterApp);

            butRegisterApp.Click += butRegisterApp_Click;
            Button butSendTo = FindViewById <Button>(Resource.Id.butSendTo);

            butSendTo.Click += butSendTo_Click;
            Button butOpenWXApp = FindViewById <Button>(Resource.Id.butOpenWXApp);

            butOpenWXApp.Click += butOpenWXApp_Click;
            Button butIsFriendster = FindViewById <Button>(Resource.Id.butIsFriendster);

            butIsFriendster.Click += butIsFriendster_Click;
        }
Exemplo n.º 6
0
 public static void callback_RegisterApp(string appID)
 {
     if (mApi == null)
     {
         mApi = WXAPIFactory.CreateWXAPI(appID);
         System.Diagnostics.Debugger.Log(0, "[asWXHelperImplMetro]", "callback_RegisterApp");
     }
 }
Exemplo n.º 7
0
 void initWechatShare(Context context, string yourWeChatAppId)
 {
     if (mWXApi == null)
     {
         mWXApi = WXAPIFactory.CreateWXAPI(context, yourWeChatAppId, true);
     }
     mWXApi.RegisterApp(yourWeChatAppId);
 }
 public void onCreate(Bundle savedInstanceState)
 {
     base.OnCreate(savedInstanceState);
     //SetContentView(R.layout.pay_result);
     //布局是可以自定义
     api = WXAPIFactory.CreateWXAPI(this, "App_ID");
     api.HandleIntent(Intent, this);
 }
Exemplo n.º 9
0
        //发送授权请求的处理函数,SDK1.0暂不支持,可忽略
        private void btnAuth_Click(object sender, RoutedEventArgs e)
        {
            string AppID = ConstString.APPID;

            SendAuth.Req req = new SendAuth.Req(ConstString.SCOPE, ConstString.STATE);

            IWXAPI api = WXAPIFactory.CreateWXAPI(AppID);

            api.SendReq(req);
        }
Exemplo n.º 10
0
 public async void WeChatAuth(Frame frame)
 {
     frame.Navigate(typeof(AuthPage), this.WeChat);
     currentFrame = new WeakReference <Frame>(frame);
     if (Windows.System.Profile.AnalyticsInfo.VersionInfo.DeviceFamily == "Windows.Mobile")
     {
         var req     = new SendAuth.Req("snsapi_userinfo", "wechat");
         var api     = WXAPIFactory.CreateWXAPI("wx2d00f7c30f52d4aa");
         var isValid = await api.SendReq(req);
     }
 }
Exemplo n.º 11
0
        /// <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);
        }
Exemplo n.º 12
0
        static WeChat()
        {
            var streamInfo = Application.GetResourceStream(new Uri("config.xml", UriKind.Relative));

            var sr       = new StreamReader(streamInfo.Stream);
            var document = XDocument.Parse(sr.ReadToEnd());

            appId = (from results in document.Descendants()
                     where results.Name.LocalName == "preference" && ((string)results.Attribute("name") == WECHAT_APPID_KEY)
                     select(string) results.Attribute("value")).First();

            api = WXAPIFactory.CreateWXAPI(appId);
        }
Exemplo n.º 13
0
 /// <summary>
 /// 授权登录
 /// </summary>
 public static async void Login()
 {
     try
     {
         SendAuth.Req req     = new SendAuth.Req("", "test");
         IWXAPI       api     = WXAPIFactory.CreateWXAPI(APP_ID);
         var          isValid = await api.SendReq(req);
     }
     catch (WXException ex)
     {
         Debug.WriteLine(ex.Message);
     }
 }
Exemplo n.º 14
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.SendReqAsync(req);
            }
            catch (WXException ex)
            {
                Debug.WriteLine(ex.Message);
            }
        }
Exemplo n.º 15
0
        /// <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);
        }
Exemplo n.º 16
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);
            }
        }
Exemplo n.º 17
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);
            }
        }
Exemplo n.º 18
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);
        }
Exemplo n.º 19
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); }
 }
Exemplo n.º 20
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);
            }
        }
Exemplo n.º 21
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();
                }
            };
        }
Exemplo n.º 22
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;
            }
Exemplo n.º 23
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)
     {
     }
 }
Exemplo n.º 24
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;
     }
 }
Exemplo n.º 25
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);
     }
 }
Exemplo n.º 26
0
        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;
        }
Exemplo n.º 27
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);
        }
Exemplo n.º 28
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);
            }
        }
        /// <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));
        }
Exemplo n.º 30
0
        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);
            }
        }