Ejemplo n.º 1
0
 public WeixinpayHelper(Context context)
 {
     _context = context;
     _payRequest = new PayReq();
     _msgApi = WXAPIFactory.CreateWXAPI(_context, null);
     _sb = new System.Text.StringBuilder();
     _msgApi.RegisterApp(Constants.ApiKey);
 }
Ejemplo n.º 2
0
        protected override void OnCreate(Bundle bundle)
        {
            base.OnCreate(bundle);

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

            show = (TextView)FindViewById(Resource.Id.editText_prepay_id);
            req = new PayReq();
            sb = new System.Text.StringBuilder();
            msgApi = WXAPIFactory.CreateWXAPI(this, null);
            msgApi.RegisterApp(Constants.APP_ID);
            //生成prepay_id
            Button payBtn = FindViewById<Button>(Resource.Id.unifiedorder_btn);

            Dictionary<string, string> xml = new Dictionary<string, string>();

            payBtn.Click += (o, e) => {
                ProgressDialog dialog = ProgressDialog.Show(this, "abc".ToString(), "def");

                IRunnable payRunnable = new Runnable(() => {
                    string url = string.Format("https://api.mch.weixin.qq.com/pay/unifiedorder");
                    string entity = genProductArgs();

                    byte[] buf = Util.httpPost(url, entity);

                    string content = Encoding.Default.GetString(buf);

                    xml = decodeXml(content);
                });

                AsyncTask.Execute(payRunnable);

                if (dialog != null)
                {
                    dialog.Dismiss();
                }
                sb.Append("prepay_id\n" + resultunifiedorder["prepay_id"] + "\n\n");
                show.Text = sb.ToString();
            };

    		Button appayBtn = FindViewById<Button>(Resource.Id.appay_btn);
            appayBtn.Click += (o, e) => {
                sendPayReq();
            };
            //生成签名参数
            Button appay_pre_btn = FindViewById<Button>(Resource.Id.appay_pre_btn);
            appay_pre_btn.Click += (o, e) => {
                genPayReq();
            };
        }