Example #1
0
        /// <summary>
        /// 3 调起微信支付,(前提:微信已安装,且没有被应用回收,即正常人工可以使用)
        ///   新建一个包wxapi,建一个类名为WXPayEntryActivity作为接受微信的支付结果(回调名必须是:
        ///     你的包名+.wxapi.WXPayEntryActivity),添加如下代码到Mainfast里面就行了 exported = true
        ///      activity android:name=".wxapi.WXPayEntryActivity" android:exported="true" 实现onResp函数
        ///   不过,最终结果以服务器的返回为准notify_url,App等待并轮询结果,接下来就是要为了做安全性设计,
        ///      把一些重要的东西放到服务器生生成,这样是为防止客户端被反编译,建议GenPackageSign/genProductArgs方法在服务端生成
        /// </summary>
        public bool SendPayReq(PayReq pReq)
        {
            bool isOk = false;

            try {
                if (!msgApi.IsWXAppInstalled)
                {
                    Toast.MakeText(this.Context, "您还没有安装微信,暂不支持此功能!", ToastLength.Short).Show();
                }
                else if (!msgApi.IsWXAppSupportAPI)
                {
                    Toast.MakeText(this.Context, "你安装的微信版本不支持当前开放API!", ToastLength.Short).Show();
                }
                else
                {
                    msgApi.RegisterApp(Constants.APPID);
                    msgApi.OpenWXApp();
                    isOk = msgApi.SendReq(pReq);
                }
            }
            catch (Exception ex) {
                Toast.MakeText(this.Context, ex.GetAllMsg(), ToastLength.Short).Show();
                //throw;
            }

            return(isOk);
        }
Example #2
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(); };
        }
Example #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(); };
        }
Example #4
0
 void butOpenWXApp_Click(object sender, EventArgs e)
 {
     Toast.MakeText(this, "launch result = " + api.OpenWXApp(), ToastLength.Long).Show();
 }