Exemplo n.º 1
0
        public object Do_Payment(object param)
        {
            PaymentParam paymentParam = JsonConvert.DeserializeObject <PaymentParam>(param.ToString());

            if (paymentParam == null)
            {
                throw new ApiException(CodeMessage.InvalidParam, "InvalidParam");
            }

            try
            {
                SessionBag sessionBag = SessionContainer.GetSession(paymentParam.token);
                var        openId     = sessionBag.OpenId;
                var        billId     = this.createBill(openId, paymentParam);
                var        totalPrice = this.getBillPrice(paymentParam);
                if (totalPrice == 0)
                {
                    throw new ApiException(CodeMessage.PaymentTotalPriceZero, "PaymentTotalPriceZero");
                }
                var timeStamp   = TenPayV3Util.GetTimestamp();
                var nonceStr    = TenPayV3Util.GetNoncestr();
                var product     = paymentParam.product;
                var xmlDataInfo =
                    new TenPayV3UnifiedorderRequestData(
                        tenPayV3Info.AppId,
                        tenPayV3Info.MchId,
                        product,
                        billId,
                        totalPrice,
                        "127.0.0.1",
                        tenPayV3Info.TenPayV3Notify,
                        TenPayV3Type.JSAPI,
                        openId,
                        tenPayV3Info.Key,
                        nonceStr);

                var result = TenPayV3.Html5Order(xmlDataInfo);
                pDao.writePrePayId(billId, result.prepay_id);
                var package = string.Format("prepay_id={0}", result.prepay_id);
                var paySign = TenPayV3.GetJsPaySign(tenPayV3Info.AppId, timeStamp, nonceStr, package, tenPayV3Info.Key);

                PaymentResults paymentResults = new PaymentResults();
                paymentResults.appId     = tenPayV3Info.AppId;
                paymentResults.nonceStr  = nonceStr;
                paymentResults.package   = package;
                paymentResults.paySign   = paySign;
                paymentResults.timeStamp = timeStamp;
                paymentResults.product   = product;
                paymentResults.billId    = billId;

                return(paymentResults);
            }
            catch (Exception ex)
            {
                throw new ApiException(CodeMessage.PaymentError, "PaymentError");
            }
        }
Exemplo n.º 2
0
        private int getBillPrice(PaymentParam paymentParam)
        {
            int totalPrice = pDao.getOrderTotalPrice(paymentParam);

#if DEBUG
            //实际计算具体价格
            totalPrice = 1;
#endif
            return(totalPrice);
        }
Exemplo n.º 3
0
        private string createBill(string openId, PaymentParam paymentParam)
        {
            PaymentDao pDao = new PaymentDao();

            string pre    = DateTime.Now.ToString("yyyyMMddHHmm");
            string billId = pre + "XC" + TenPayV3Util.BuildRandomStr(4);

            if (pDao.saveOrder(openId, billId, paymentParam))
            {
                return(billId);
            }
            else
            {
                throw new ApiException(CodeMessage.InitOrderError, "InitOrderError");
            }
        }