Ejemplo n.º 1
0
 public void Pay(string payCode, PayCallback payResultHandler)
 {
     if (Application.platform == RuntimePlatform.Android)
     {
         AndroidJavaClass  jc = new AndroidJavaClass("com.unity3d.player.UnityPlayer");
         AndroidJavaObject jo = jc.GetStatic <AndroidJavaObject>("currentActivity");
         jo.Call("Pay", payCode);
         _payResultHandler = payResultHandler;
     }
 }
Ejemplo n.º 2
0
    public void PayCallbackHandler(string str)
    {
        result = str;
        int rt = str.Contains("success")? 1 : -1; //-1 充值失败, 1 充值成功

        if (_payResultHandler != null)
        {
            _payResultHandler(rt);
            _payResultHandler = null;
        }
    }
Ejemplo n.º 3
0
 /**
  * 查询支付结果
  **/
 public void queryPayResult(String prepayId, PayCallback payCallback)
 {
     checkBaseInfo();
     if (payCallback == null)
     {
         throw new Exception("缺少回调");
     }
     if (String.IsNullOrEmpty(prepayId))
     {
         payCallback.onFailed("-2", "prepayId不能为空");
         return;
     }
     queryPayResult(false, prepayId, payCallback);
 }
Ejemplo n.º 4
0
        private async void prepayment(String qrCode, PayCallback callback)
        {
            if (String.IsNullOrEmpty(qrCode))
            {
                pay.prePayment("海洋王国",
                               "LYY0060001",
                               "海洋乐园",
                               "100046",
                               "冰雪乐园门店",
                               "test",
                               "海洋世界票务两张",
                               "海洋世界购票两张",
                               orderNoLb.Text,
                               Convert.ToDecimal(orderPriceTb.Text),
                               Convert.ToDecimal(orderPriceTb.Text),
                               new decimal(0.00),
                               "test",
                               "test",
                               callback);
            }
            else
            {
                pay.prePayment(qrCode, "海洋王国",
                               "LYY0060001",
                               "海洋乐园",
                               "100046",
                               "冰雪乐园门店",
                               "test",
                               "海洋世界票务两张",
                               "海洋世界购票两张",
                               orderNoLb.Text,
                               Convert.ToDecimal(orderPriceTb.Text),
                               Convert.ToDecimal(orderPriceTb.Text),
                               new decimal(0.00),
                               "test",
                               "test",
                               callback);
            };

            writeLog();
        }
Ejemplo n.º 5
0
        private void queryPayResult(bool needPoll, String prepayId, PayCallback payCallback)
        {
            String     url    = Config.HOST + Config.QUERY_PREPAY + prepayId;
            HttpClient client = new HttpClient();
            BaseResponse <QueryPrepayResult> response = client.GetDataHttp <BaseResponse <QueryPrepayResult> >(mchId, url);

            if (response == null)
            {
                payCallback.onFailed("-1", "Result is null!");
            }
            else if ("000000".Equals(response.Code))
            {
                if (needPoll)
                {
                    //支付结束:可能成功可能失败,看交易状态状态
                    if (CommonUtil.isFinishTrade(response.Data.TradeState))
                    {
                        payCallback.onSuccess(response.Data.toPayResult());
                    }
                    else
                    {
                        //开始轮询
                        queryPayResult(true, prepayId, payCallback);
                    }
                }
                else
                {
                    payCallback.onPrepayId(response.Data.PrepayId);
                    payCallback.onSuccess(response.Data.toPayResult());
                }
            }
            else
            {
                payCallback.onFailed(response.Code, response.Message);
            }
        }
Ejemplo n.º 6
0
        /**
         * B扫C接口
         * */
        public void prePayment(String qrCode,
                               String mchName,
                               String formatNumber,
                               String formatName,
                               String storeNumber,
                               String storeName,
                               String sourceCode,
                               String subject,
                               String goodsDetail,
                               String orderId,
                               Decimal totalAmount,
                               Decimal amount,
                               Decimal discountAmount,
                               String desc, String notifyUrl,
                               PayCallback payCallback)
        {
            checkBaseInfo();
            if (payCallback == null)
            {
                throw new Exception("缺少回调");
            }
            if (String.IsNullOrEmpty(qrCode))
            {
                payCallback.onFailed("-2", "qrCode不能为空");
                return;
            }
            if (String.IsNullOrEmpty(formatNumber))
            {
                payCallback.onFailed("-2", "formatNumber不能为空");
                return;
            }
            if (String.IsNullOrEmpty(storeNumber))
            {
                payCallback.onFailed("-2", "storeNumber不能为空");
                return;
            }
            if (String.IsNullOrEmpty(sourceCode))
            {
                payCallback.onFailed("-2", "sourceCode不能为空");
                return;
            }
            if (String.IsNullOrEmpty(subject))
            {
                payCallback.onFailed("-2", "subject不能为空");
                return;
            }
            if (String.IsNullOrEmpty(orderId))
            {
                payCallback.onFailed("-2", "orderId不能为空");
                return;
            }
            if (totalAmount < amount)
            {
                payCallback.onFailed("-2", "总金额不能小于支付金额");
                return;
            }
            if (totalAmount < (amount + discountAmount))
            {
                payCallback.onFailed("-2", "总金额不能小于支付金额+折扣金额");
                return;
            }
            ReqPaymentBean reqPaymentBean = new ReqPaymentBean();

            reqPaymentBean.appId          = "100007";
            reqPaymentBean.qrCode         = qrCode;
            reqPaymentBean.mchId          = mchId;
            reqPaymentBean.mchName        = mchName;
            reqPaymentBean.formatNumber   = formatNumber;
            reqPaymentBean.formatName     = formatName;
            reqPaymentBean.storeNumber    = storeNumber;
            reqPaymentBean.storeName      = storeName;
            reqPaymentBean.sourceCode     = sourceCode;
            reqPaymentBean.subject        = subject;
            reqPaymentBean.goodsDetail    = goodsDetail;
            reqPaymentBean.outTradeNo     = orderId;
            reqPaymentBean.totalAmount    = totalAmount;
            reqPaymentBean.amount         = amount;
            reqPaymentBean.discountAmount = discountAmount;
            reqPaymentBean.paymentScene   = 1;
            reqPaymentBean.desc           = desc;
            reqPaymentBean.payType        = "H02";
            reqPaymentBean.currency       = "CNY";
            reqPaymentBean.timeExpire     = null;
            reqPaymentBean.timestamp      = CommonUtil.GetTimeStamp();
            reqPaymentBean.notifyUrl      = notifyUrl;
            reqPaymentBean.generateSign(mchKey);

            HttpClient client   = new HttpClient();
            String     url      = Config.HOST + Config.B_2_C_PREPAY;
            String     jsonBody = JsonUtil.SerializeObject(reqPaymentBean);
            BaseResponse <PayResultBean> response = client.PostDataHttp <BaseResponse <PayResultBean> >(mchId, url, null, null, jsonBody);

            if (response == null)
            {
                payCallback.onFailed("-1", "Result is null!");
            }
            else if ("000000".Equals(response.Code))
            {
                //支付结束:可能成功可能失败,看交易状态状态
                if (CommonUtil.isFinishTrade(response.Data.TradeState))
                {
                    payCallback.onSuccess(response.Data);
                }
                else
                {
                    String prepayId = response.Data.PrepayId;
                    //开始轮询
                    payCallback.onPrepayId(prepayId);
                    queryPayResult(true, prepayId, payCallback);
                }
            }
            else
            {
                payCallback.onFailed(response.Code, response.Message);
            }
        }