Esempio n. 1
0
 public void handleAliWapPayResultTest()
 {
     BCBill bill = new BCBill(BCPay.PayChannel.ALI_WAP.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
     bill.returnUrl = "http://localhost:50003/return_ali_url.aspx";
     string respString = "{\"result_msg\":\"OK\",\"resultCode\":0,\"errMsg\":\"OK:\",\"err_detail\":\"\",\"result_code\":0,\"html\":\"<form id=\\\"alipaysubmit\\\" name=\\\"alipaysubmit\\\" action=\\\"https://mapi.alipay.com/gateway.do?_input_charset=utf-8\\\" method=\\\"get\\\"><input type=\\\"hidden\\\" name=\\\"payment_type\\\" value=\\\"1\\\"/><input type=\\\"hidden\\\" name=\\\"out_trade_no\\\" value=\\\"370e678e72d04d139d1e623453f9aa1a\\\"/><input type=\\\"hidden\\\" name=\\\"partner\\\" value=\\\"2088711322600312\\\"/><input type=\\\"hidden\\\" name=\\\"subject\\\" value=\\\"dotNet自来水\\\"/><input type=\\\"hidden\\\" name=\\\"_input_charset\\\" value=\\\"utf-8\\\"/><input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"alipay.wap.create.direct.pay.by.user\\\"/><input type=\\\"hidden\\\" name=\\\"total_fee\\\" value=\\\"0.01\\\"/><input type=\\\"hidden\\\" name=\\\"sign\\\" value=\\\"045d7ede0af92f78fd334b726f171465\\\"/><input type=\\\"hidden\\\" name=\\\"return_url\\\" value=\\\"http://localhost:50003/return_ali_url.aspx\\\"/><input type=\\\"hidden\\\" name=\\\"notify_url\\\" value=\\\"http://payservice.beecloud.cn/bcpay/aliPayDynamic/c37d661d-7e61-49ea-96a5-68c34e83db3b_d136a0ca-2be9-4ba7-b5e4-d8293e53bea1.php\\\"/><input type=\\\"hidden\\\" name=\\\"sign_type\\\" value=\\\"MD5\\\"/><input type=\\\"hidden\\\" name=\\\"seller_id\\\" value=\\\"2088711322600312\\\"/><input type=\\\"submit\\\" value=\\\"确认\\\" style=\\\"display:none;\\\"></form><script>document.forms['alipaysubmit'].submit();</script>\",\"id\":\"d136a0ca-2be9-4ba7-b5e4-d8293e53bea1\",\"url\":\"https://mapi.alipay.com/gateway.do?_input_charset=utf-8&payment_type=1&out_trade_no=370e678e72d04d139d1e623453f9aa1a&partner=2088711322600312&subject=dotNet自来水&_input_charset=utf-8&service=alipay.wap.create.direct.pay.by.user&total_fee=0.01&sign=045d7ede0af92f78fd334b726f171465&return_url=http://localhost:50003/return_ali_url.aspx&notify_url=http://payservice.beecloud.cn/bcpay/aliPayDynamic/c37d661d-7e61-49ea-96a5-68c34e83db3b_d136a0ca-2be9-4ba7-b5e4-d8293e53bea1.php&sign_type=MD5&seller_id=2088711322600312\"}";
     BCBill actual = BCPay.handlePayResult(respString, bill);
     Assert.IsNotNull(actual.id);
     Assert.IsNotNull(actual.url);
     Assert.IsNotNull(actual.html);
 }
Esempio n. 2
0
 public void handleAliQrcodePayResultTest()
 {
     BCBill bill = new BCBill(BCPay.PayChannel.ALI_QRCODE.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
     bill.qrPayMode = "0";
     bill.returnUrl = "http://*****:*****@beecloud.cn\\\"/><input type=\\\"hidden\\\" name=\\\"subject\\\" value=\\\"dotNet自来水\\\"/><input type=\\\"hidden\\\" name=\\\"_input_charset\\\" value=\\\"utf-8\\\"/><input type=\\\"hidden\\\" name=\\\"sign\\\" value=\\\"8216a45e51f576cfd6a38f8c8576663a\\\"/><input type=\\\"hidden\\\" name=\\\"notify_url\\\" value=\\\"http://payservice.beecloud.cn/bcpay/aliPayDynamic/c37d661d-7e61-49ea-96a5-68c34e83db3b_c4dee3ef-69a1-4cfc-8faa-32c0b0b7c4fc.php\\\"/><input type=\\\"hidden\\\" name=\\\"qr_pay_mode\\\" value=\\\"0\\\"/><input type=\\\"hidden\\\" name=\\\"payment_type\\\" value=\\\"1\\\"/><input type=\\\"hidden\\\" name=\\\"out_trade_no\\\" value=\\\"0548650a2b8e4a5bb2ee4bba56c6fb0c\\\"/><input type=\\\"hidden\\\" name=\\\"partner\\\" value=\\\"2088711322600312\\\"/><input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"create_direct_pay_by_user\\\"/><input type=\\\"hidden\\\" name=\\\"total_fee\\\" value=\\\"0.01\\\"/><input type=\\\"hidden\\\" name=\\\"return_url\\\" value=\\\"http://*****:*****@beecloud.cn&subject=dotNet自来水&_input_charset=utf-8&sign=8216a45e51f576cfd6a38f8c8576663a&notify_url=http://payservice.beecloud.cn/bcpay/aliPayDynamic/c37d661d-7e61-49ea-96a5-68c34e83db3b_c4dee3ef-69a1-4cfc-8faa-32c0b0b7c4fc.php&qr_pay_mode=0&payment_type=1&out_trade_no=0548650a2b8e4a5bb2ee4bba56c6fb0c&partner=2088711322600312&service=create_direct_pay_by_user&total_fee=0.01&return_url=http://localhost:50003/return_ali_url.aspx&exter_invoke_ip=112.86.54.108&sign_type=MD5\"}";
     BCBill actual = BCPay.handlePayResult(respString, bill);
     Assert.IsNotNull(actual.id);
     Assert.IsNotNull(actual.url);
     Assert.IsNotNull(actual.html);
 }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            if (!IsPostBack)
            {
                JsApiPay jsApiPay = new JsApiPay(this);
                try
                {
                    //调用【网页授权获取用户信息】接口获取用户的openid和access_token
                    jsApiPay.appid = appid;
                    jsApiPay.appsecret = "53e3943476118a3dff21fb95848de6d7";
                    jsApiPay.GetOpenidAndAccessToken();

                    //ViewState["openid"] = jsApiPay.openid;
                    Response.Write(jsApiPay.openid);

                    BCBill bill = new BCBill(BCPay.PayChannel.WX_JSAPI.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
                    bill.openId = jsApiPay.openid;
                    try
                    {
                        BCBill resultBill = BCPay.BCPayByChannel(bill);
                        timeStamp = resultBill.timestamp;
                        noncestr = resultBill.noncestr;
                        package = resultBill.package;
                        paySign = resultBill.paySign;
                        signType = resultBill.signType;
                    }
                    catch (Exception excption)
                    {
                        Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>");
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex.Message + "</span>");
                }
            }
        }
Esempio n. 4
0
        /// <summary>
        /// 支付
        /// </summary>
        /// <param name="channel">渠道类型
        ///     根据不同场景选择不同的支付方式
        ///     必填
        ///     可以通过enum BCPay.PayChannel获取
        ///     channel的参数值含义:
        ///     WX_APP:       微信手机APP支付
        ///     WX_NATIVE:    微信公众号二维码支付
        ///     WX_JSAPI:     微信公众号支付
        ///     ALI_APP:      支付宝APP支付
        ///     ALI_WEB:      支付宝网页支付 
        ///     ALI_QRCODE:   支付宝内嵌二维码支付
        ///     UN_APP:       银联APP支付
        ///     UN_WEB:       银联网页支付
        ///     UN_WAP:       银联wap支付
        ///     JD_WAP:       京东wap支付
        ///     JD_WEB:       京东web支付
        ///     YEE_WAP:      易宝wap支付 
        ///     YEE_WEB:      易宝web支付
        ///     KUAIQIAN_WAP: 快钱wap支付
        ///     KUAIQIAN_WEB: 快钱web支付
        ///     BD_WEB:       百度web支付
        ///     BD_WAP:       百度wap支付
        ///     BC_GATEWAY    比可网关支付
        ///     BC_EXPRESS    比可快捷支付(收款最低金额1元)
        /// </param>
        /// <param name="totalFee">订单总金额
        ///     只能为整数,单位为分
        ///     必填
        /// </param>
        /// <param name="billNo">商户订单号
        ///     32个字符内,数字和/或字母组合,确保在商户系统中唯一(即所有渠道所有订单号不同)
        ///     必填
        /// </param>
        /// <param name="title">订单标题
        ///     32个字节内,最长支持16个汉字
        ///     必填
        /// </param>
        /// <param name="optional">附加数据
        ///     用户自定义的参数,将会在webhook通知中原样返回,该字段主要用于商户携带订单的自定义数据
        ///     {"key1":"value1","key2":"value2",...}
        ///     可空
        /// </param>
        /// <param name="returnUrl">同步返回页面
        ///     支付渠道处理完请求后,当前页面自动跳转到商户网站里指定页面的http路径。
        ///     当channel 参数为 ALI_WEB 或 ALI_QRCODE 或 UN_WEB时为必填
        /// </param>
        /// <param name="billTimeout">订单失效时间
        ///     必须为非零正整数,单位为秒,建议最短失效时间间隔必须大于300秒
        ///     可空
        ///     京东系列支付不支持该参数,填空
        /// </param>
        /// <param name="openId">用户相对于微信公众号的唯一id
        ///     例如'0950c062-5e41-44e3-8f52-f89d8cf2b6eb'
        ///     微信公众号支付(WX_JSAPI)的必填参数
        /// </param>
        /// <param name="showURL">商品展示地址
        ///     以http://开头,例如'http://beecloud.cn'
        ///     支付宝网页支付(ALI_WEB)的选填参数
        /// </param>
        /// <param name="qrPayMode">二维码类型
        ///     支付宝内嵌二维码支付(ALI_QRCODE)的选填参数
        ///     二维码类型含义
        ///     0: 订单码-简约前置模式,对应 iframe 宽度不能小于 600px, 高度不能小于 300px
        ///     1: 订单码-前置模式,对应 iframe 宽度不能小于 300px, 高度不能小于 600px
        ///     3: 订单码-迷你前置模式,对应 iframe 宽度不能小于 75px, 高度不能小于 75px
        /// </param>
        /// <returns>
        /// </returns>
        public static BCBill BCPayByChannel(BCBill bill)
        {
            string payUrl = "";
            if (!BCCache.Instance.testMode)
            {
                payUrl = BCPrivateUtil.getHost() + BCConstants.version + BCConstants.billURL;
            }
            else
            {
                payUrl = BCPrivateUtil.getHost() + BCConstants.version + BCConstants.billTestURL;
            }

            string paraString = preparePayParameters(bill);

            try
            {
                HttpWebResponse response = BCPrivateUtil.CreatePostHttpResponse(payUrl, paraString, BCCache.Instance.networkTimeout);

                string respString = BCPrivateUtil.GetResponseString(response);

                return handlePayResult(respString, bill);
            }
            catch (Exception e)
            {
                var ex = new BCException(e.Message);
                throw ex;
            }
        }
Esempio n. 5
0
        /// <summary>
        ///  微信支付宝扫码/被扫支付
        /// </summary>
        /// <param name="bill"></param>
        /// <returns></returns>
        public static BCBill BCOfflinePayByChannel(BCBill bill)
        {
            string payUrl = "";

            if (bill.channel.ToString().Contains("SCAN"))
            {
                payUrl = BCPrivateUtil.getHost() + BCConstants.version + BCConstants.offlineBillURL;
            }
            else
            {
                payUrl = BCPrivateUtil.getHost() + BCConstants.version + BCConstants.billURL;
            }

            long timestamp = BCUtil.GetTimeStamp(DateTime.Now);

            JsonData data = new JsonData();

            data["app_id"] = BCCache.Instance.appId;
            data["app_sign"] = BCPrivateUtil.getAppSignature(BCCache.Instance.appId, BCCache.Instance.appSecret, timestamp.ToString());
            data["timestamp"] = timestamp;
            data["channel"] = bill.channel;
            data["total_fee"] = bill.totalFee;
            data["bill_no"] = bill.billNo;
            data["title"] = bill.title;

            if (bill.authCode != null)
            {
                data["auth_code"] = bill.authCode;
            }

            if (bill.optional != null && bill.optional.Count > 0)
            {
                data["optional"] = new JsonData();
                foreach (string key in bill.optional.Keys)
                {
                    data["optional"][key] = bill.optional[key];
                }
            }

            string paraString = data.ToJson();

            try
            {
                HttpWebResponse response = BCPrivateUtil.CreatePostHttpResponse(payUrl, paraString, BCCache.Instance.networkTimeout);

                string respString = BCPrivateUtil.GetResponseString(response);

                JsonData responseData = JsonMapper.ToObject(respString);

                if (bill.channel == "BC_ALI_QRCODE")
                {
                    if (responseData["result_code"].ToString() == "0")
                    {
                        bill.id = responseData["id"].ToString();
                        bill.codeURL = responseData["code_url"].ToString();
                        return bill;
                    }
                    else
                    {
                        var ex = new BCException(responseData["err_detail"].ToString());
                        throw ex;
                    }
                }
                if (bill.channel == "BC_ALI_SCAN" || bill.channel == "BC_WX_SCAN")
                {
                    if (responseData["result_code"].ToString() == "0")
                    {
                        bill.id = responseData["id"].ToString();
                        bill.result = (bool)responseData["pay_result"];
                        return bill;
                    }
                    else
                    {
                        var ex = new BCException(responseData["err_detail"].ToString());
                        throw ex;
                    }
                }
                return bill;
            }
            catch (Exception e)
            {
                var ex = new BCException(e.Message);
                throw ex;
            }
        }
Esempio n. 6
0
        //准备支付数据
        public static string preparePayParameters(BCBill bill)
        {
            long timestamp = BCUtil.GetTimeStamp(DateTime.Now);

            JsonData data = new JsonData();
            data["app_id"] = BCCache.Instance.appId;
            if (!BCCache.Instance.testMode)
            {
                data["app_sign"] = BCPrivateUtil.getAppSignature(BCCache.Instance.appId, BCCache.Instance.appSecret, timestamp.ToString());
            }
            else
            {
                data["app_sign"] = BCPrivateUtil.getAppSignatureByTestSecret(timestamp.ToString());
            }
            data["timestamp"] = timestamp;
            data["channel"] = bill.channel;
            data["total_fee"] = bill.totalFee;
            data["bill_no"] = bill.billNo;
            data["title"] = bill.title;
            data["return_url"] = bill.returnUrl;

            data["bill_timeout"] = bill.billTimeout;

            data["openid"] = bill.openId;
            data["show_url"] = bill.showURL;
            data["qr_pay_mode"] = bill.qrPayMode;

            data["identity_id"] = bill.yeeID;

            if (bill.useApp.HasValue)
            {
                data["use_app"] = bill.useApp.Value;
            }

            if (bill.bank != null)
            {
                data["bank"] = bill.bank;
            }

            if (bill.cardNo != null)
            {
                data["card_no"] = bill.cardNo;
            }
            if (bill.notifyURL != null)
            {
                data["notify_url"] = bill.notifyURL;
            }
            if (bill.optional != null && bill.optional.Count > 0)
            {
                data["optional"] = new JsonData();
                foreach (string key in bill.optional.Keys)
                {
                    data["optional"][key] = bill.optional[key];
                }
            }

            string paraString = data.ToJson();
            return paraString;
        }
Esempio n. 7
0
        //处理支付回调
        public static BCBill handlePayResult(string respString, BCBill bill)
        {
            JsonData responseData = JsonMapper.ToObject(respString);

            if (bill.channel == "WX_NATIVE")
            {
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    if (BCCache.Instance.testMode)
                    {
                        bill.codeURL = responseData["url"].ToString();
                    }
                    else
                    {
                        bill.codeURL = responseData["code_url"].ToString();
                    }
                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }

            }
            if (bill.channel == "WX_JSAPI")
            {
                if (BCCache.Instance.testMode)
                {
                    throw new BCException("微信公众号内支付不支持测试模式");
                }
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    bill.appId = responseData["app_id"].ToString();
                    bill.package = responseData["package"].ToString();
                    bill.noncestr = responseData["nonce_str"].ToString();
                    bill.timestamp = responseData["timestamp"].ToString();
                    bill.paySign = responseData["pay_sign"].ToString();
                    bill.signType = responseData["sign_type"].ToString();

                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            if (bill.channel == "ALI_WEB" || bill.channel == "ALI_WAP")
            {
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    if (BCCache.Instance.testMode)
                    {
                        bill.html = string.Format("<html><head></head><body><script>location.href='{0}'</script></body></html>", responseData["url"].ToString());
                    }
                    else
                    {
                        bill.html = responseData["html"].ToString();
                    }
                    bill.url = responseData["url"].ToString();

                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            if (bill.channel == "ALI_QRCODE")
            {
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    bill.url = responseData["url"].ToString();
                    if (BCCache.Instance.testMode)
                    {
                        bill.html = string.Format("<html><head></head><body><script>location.href='{0}'</script></body></html>", responseData["url"].ToString());
                    }
                    else
                    {
                        bill.html = responseData["html"].ToString();
                    }
                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            if (bill.channel == "JD_WAP" || bill.channel == "JD_WEB" || bill.channel == "KUAIQIAN_WAP" || bill.channel == "KUAIQIAN_WEB" || bill.channel == "UN_WEB" || bill.channel == "UN_WAP")
            {
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    if (BCCache.Instance.testMode)
                    {
                        bill.html = string.Format("<html><head></head><body><script>location.href='{0}'</script></body></html>", responseData["url"].ToString());
                    }
                    else
                    {
                        bill.html = responseData["html"].ToString();
                    }
                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            if (bill.channel == "BD_WEB" || bill.channel == "BD_WAP" || bill.channel == "YEE_WEB" || bill.channel == "YEE_WAP")
            {
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    if (BCCache.Instance.testMode)
                    {
                        bill.html = string.Format("<html><head></head><body><script>location.href='{0}'</script></body></html>", responseData["url"].ToString());
                    }
                    else
                    {
                        bill.url = responseData["url"].ToString();
                    }

                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            if (bill.channel == "BC_GATEWAY")
            {
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    if (BCCache.Instance.testMode)
                    {
                        bill.html = string.Format("<html><head></head><body><script>location.href='{0}'</script></body></html>", responseData["url"].ToString());
                    }
                    else
                    {
                        bill.html = responseData["html"].ToString();
                    }
                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            if (bill.channel == "BC_EXPRESS")
            {
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    if (BCCache.Instance.testMode)
                    {
                        bill.html = string.Format("<html><head></head><body><script>location.href='{0}'</script></body></html>", responseData["url"].ToString());
                    }
                    else
                    {
                        bill.html = responseData["html"].ToString();
                        bill.url = responseData["url"].ToString();
                    }
                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }
            }
            if (bill.channel == "BC_NATIVE")
            {
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    if (BCCache.Instance.testMode)
                    {
                        //bill.codeURL = responseData["url"].ToString();
                    }
                    else
                    {
                        bill.codeURL = responseData["code_url"].ToString();
                    }
                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }

            }
            if (bill.channel == "BC_WX_WAP")
            {
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    if (BCCache.Instance.testMode)
                    {
                        //bill.codeURL = responseData["url"].ToString();
                    }
                    else
                    {
                        bill.url = responseData["url"].ToString();
                    }
                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }

            }
            if (bill.channel == "BC_WX_JSAPI")
            {
                if (BCCache.Instance.testMode)
                {
                    throw new BCException("微信公众号内支付不支持测试模式");
                }
                if (responseData["result_code"].ToString() == "0")
                {
                    bill.id = responseData["id"].ToString();
                    bill.appId = responseData["app_id"].ToString();
                    bill.package = responseData["package"].ToString();
                    bill.noncestr = responseData["nonce_str"].ToString();
                    bill.timestamp = responseData["timestamp"].ToString();
                    bill.paySign = responseData["pay_sign"].ToString();
                    bill.signType = responseData["sign_type"].ToString();

                    return bill;
                }
                else
                {
                    var ex = new BCException(responseData["err_detail"].ToString());
                    throw ex;
                }

            }
            return bill;
        }
Esempio n. 8
0
        //处理订单Id查询回调
        public static BCBill handlePayQueryByIdResult(string respString)
        {
            JsonData responseData = JsonMapper.ToObject(respString);
            BCBill bill = new BCBill();
            if (responseData["result_code"].ToString() == "0")
            {
                JsonData billData = responseData["pay"];
                bill.id = billData["id"].ToString();
                bill.title = billData["title"].ToString();
                bill.totalFee = int.Parse(billData["total_fee"].ToString());
                bill.createdTime = BCUtil.GetDateTime((long)billData["create_time"]);
                bill.billNo = billData["bill_no"].ToString();
                bill.result = (bool)billData["spay_result"];
                bill.channel = billData["sub_channel"].ToString();
                bill.tradeNo = billData["trade_no"].ToString();
                bill.optional = JsonMapper.ToObject<Dictionary<string, string>>(billData["optional"].ToString());
                bill.messageDetail = billData["message_detail"].ToString();
                bill.revertResult = (bool)billData["revert_result"];
                bill.refundResult = (bool)billData["refund_result"];
            }
            else
            {
                var ex = new BCException(responseData["err_detail"].ToString());
                throw ex;
            }

            return bill;
        }
Esempio n. 9
0
        //处理订单条件查询回调
        public static List<BCBill> handlePayQueryByConditionResult(string respString, bool? needDetail)
        {
            JsonData responseData = JsonMapper.ToObject(respString);
            List<BCBill> bills = new List<BCBill>();
            if (responseData["result_code"].ToString() == "0")
            {
                if (responseData["bills"].IsArray)
                {
                    foreach (JsonData billData in responseData["bills"])
                    {
                        BCBill bill = new BCBill();
                        bill.id = billData["id"].ToString();
                        bill.title = billData["title"].ToString();
                        bill.totalFee = int.Parse(billData["total_fee"].ToString());
                        bill.createdTime = BCUtil.GetDateTime((long)billData["create_time"]);
                        bill.billNo = billData["bill_no"].ToString();
                        bill.result = (bool)billData["spay_result"];
                        bill.channel = billData["sub_channel"].ToString();
                        bill.tradeNo = billData["trade_no"].ToString();
                        bill.optional = JsonMapper.ToObject<Dictionary<string, string>>(billData["optional"].ToString());
                        if (needDetail == true)
                        {
                            bill.messageDetail = billData["message_detail"].ToString();
                        }
                        bill.revertResult = (bool)billData["revert_result"];
                        bill.refundResult = (bool)billData["refund_result"];
                        bills.Add(bill);
                    }
                }
            }
            else
            {
                var ex = new BCException(responseData["err_detail"].ToString());
                throw ex;
            }

            return bills;
        }
Esempio n. 10
0
 public void handleJSAPIPayResultTest()
 {
     BCBill bill = new BCBill(BCPay.PayChannel.WX_JSAPI.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
     string respString = "{\"result_msg\":\"OK\",\"resultCode\":0,\"errMsg\":\"OK:\",\"err_detail\":\"\",\"result_code\":0,\"id\":\"41695744-f7f7-4926-8eee-2d5dfb745af0\",\"app_id\": \"wxa4ca6ed13385\",\"timestamp\": \"1450771041\", \"nonce_str\": \"znjsj7mw98q1drn251arrr30gq5gz0b1\", \"package\": \"prepay_id=wx20151222155721c70baa1e680187231678\", \"sign_type\": \"MD5\", \"pay_sign\": \"1E58DA3043C3D80AEC7A51B99E32\"}";
     BCBill actual = BCPay.handlePayResult(respString, bill);
     Assert.IsNotNull(actual.id);
     Assert.IsNotNull(actual.timestamp);
     Assert.IsNotNull(actual.noncestr);
     Assert.IsNotNull(actual.package);
     Assert.IsNotNull(actual.paySign);
     Assert.IsNotNull(actual.signType);
 }
Esempio n. 11
0
        public void preparePayParametersTest()
        {
            BeeCloud.registerApp("c5d1cba1-5e3f-4ba0-941d-9b0a371fe719", "39a7a518-9ac8-4a9e-87bc-7885f33cf18c", "e14ae2db-608c-4f8b-b863-c8c18953eef2", null);
            BCBill bill = new BCBill("ALI", 100, "10000000", "UT");
            bill.optional = new Dictionary<string, string> { { "key1", "value1" }, { "key2", "value2" } };
            bill.returnUrl = "http://www.test.com";
            bill.billTimeout = 360;

            string paraString = "\"channel\":\"ALI\",\"total_fee\":100,\"bill_no\":\"10000000\",\"title\":\"UT\",\"return_url\":\"http://www.test.com\",\"bill_timeout\":360,\"openid\":null,\"show_url\":null,\"qr_pay_mode\":null,\"identity_id\":null,\"optional\":{\"key1\":\"value1\",\"key2\":\"value2\"}}";
            string actual = BCPay.preparePayParameters(bill);
            Assert.IsTrue(actual.Contains(paraString));
        }
Esempio n. 12
0
 public void handleYeePayResultTest()
 {
     BCBill bill = new BCBill(BCPay.PayChannel.YEE_WEB.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
     bill.returnUrl = "http://localhost:50003/return_yee_url.aspx";
     string respString = "{\"result_msg\":\"OK\",\"resultCode\":0,\"errMsg\":\"OK:\",\"err_detail\":\"\",\"result_code\":0,\"html\":\"<form name=\\\"yeepay\\\" action=\\\"https://www.yeepay.com/app-merchant-proxy/node\\\" method=\\\"POST\\\"><input type=\\\"hidden\\\" name=\\\"p4_Cur\\\" value=\\\"CNY\\\"/><input type=\\\"hidden\\\" name=\\\"p0_Cmd\\\" value=\\\"Buy\\\"/><input type=\\\"hidden\\\" name=\\\"p3_Amt\\\" value=\\\"0.01\\\"/><input type=\\\"hidden\\\" name=\\\"pa_MP\\\" value=\\\"c37d661d-7e61-49ea-96a5-68c34e83db3b%3A41695744-f7f7-4926-8eee-2d5dfb745af0\\\"/><input type=\\\"hidden\\\" name=\\\"p2_Order\\\" value=\\\"9572742753bf43298eef21a1579dc9c1\\\"/><input type=\\\"hidden\\\" name=\\\"p5_Pid\\\" value=\\\"dotNet%D7%D4%C0%B4%CB%AE\\\"/><input type=\\\"hidden\\\" name=\\\"hmac\\\" value=\\\"972dd9930d6e34d959886339b6a7f349\\\"/><input type=\\\"hidden\\\" name=\\\"p8_Url\\\" value=\\\"http%3A%2F%2Flocalhost%3A50003%2Freturn_yee_url.aspx\\\"/><input type=\\\"hidden\\\" name=\\\"p1_MerId\\\" value=\\\"10012506312\\\"/></form><script>document.yeepay.submit();</script>\",\"id\":\"41695744-f7f7-4926-8eee-2d5dfb745af0\",\"url\":\"https://www.yeepay.com/app-merchant-proxy/node?p4_Cur=CNY&p0_Cmd=Buy&p3_Amt=0.01&pa_MP=c37d661d-7e61-49ea-96a5-68c34e83db3b%3A41695744-f7f7-4926-8eee-2d5dfb745af0&p2_Order=9572742753bf43298eef21a1579dc9c1&p5_Pid=dotNet%D7%D4%C0%B4%CB%AE&hmac=972dd9930d6e34d959886339b6a7f349&p8_Url=http%3A%2F%2Flocalhost%3A50003%2Freturn_yee_url.aspx&p1_MerId=10012506312\"}";
     BCBill actual = BCPay.handlePayResult(respString, bill);
     Assert.IsNotNull(actual.id);
     Assert.IsNotNull(actual.url);
 }
Esempio n. 13
0
 public void handleWXQrcodePayResultTest()
 {
     BCBill bill = new BCBill(BCPay.PayChannel.WX_NATIVE.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
     string respString = "{\"result_msg\":\"OK\",\"code_url\":\"weixin://wxpay/bizpayurl?pr=TtAYx12\",\"resultCode\":0,\"errMsg\":\"OK:\",\"err_detail\":\"\",\"result_code\":0,\"id\":\"99f2c898-56e7-451a-8984-f077e0688033\"}";
     BCBill actual = BCPay.handlePayResult(respString, bill);
     Assert.IsNotNull(actual.id);
     Assert.IsNotNull(actual.codeURL);
 }
Esempio n. 14
0
 public void handleUNWebPayResultTest()
 {
     BCBill bill = new BCBill(BCPay.PayChannel.UN_WEB.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
     bill.returnUrl = "http://localhost:50003/return_un_url.aspx";
     string respString = "{\"result_msg\":\"OK\",\"resultCode\":0,\"errMsg\":\"OK:\",\"err_detail\":\"\",\"result_code\":0,\"html\":\"<html><head><meta http-equiv=\\\"Content-Type\\\" content=\\\"text/html; charset=UTF-8\\\"/></head><body><form id = \\\"pay_form\\\" action=\\\"https://gateway.95516.com/gateway/api/frontTransReq.do\\\" method=\\\"post\\\"><input type=\\\"hidden\\\" name=\\\"bizType\\\" id=\\\"bizType\\\" value=\\\"000201\\\"/><input type=\\\"hidden\\\" name=\\\"orderId\\\" id=\\\"orderId\\\" value=\\\"4c8ae26558b0415491fbf97e6023671c\\\"/><input type=\\\"hidden\\\" name=\\\"backUrl\\\" id=\\\"backUrl\\\" value=\\\"http://123.57.71.81:8080/1/pay/callback/UNWeb/c37d661d-7e61-49ea-96a5-68c34e83db3b/d020f6b8-b35f-41a3-b4a8-780846c03725\\\"/><input type=\\\"hidden\\\" name=\\\"txnSubType\\\" id=\\\"txnSubType\\\" value=\\\"01\\\"/><input type=\\\"hidden\\\" name=\\\"signature\\\" id=\\\"signature\\\" value=\\\"Qtc3jybIFV+SYRN2cXPvMx2qZN5hMP+5xr+6IafLID7PNUQamCRrpQ3quygRrm8kiRmpF5/ddwdiNmoLuCb91zkCs24pYZfAUB2TDPnWlgI8QQTyUfa0W8USybwSj1WTfvLpeOL4A2Eawgl35xPaxB4MslQGl2dilOc/MnT8RCn7+bo84XGeCcj+n4OXJvvZK+M7k5sBn1slEm+WqAuy95C8esrjnIRSjq0vc62z/zzhjrPXXE0MXVrUHBQTiKRUn9RwnAq24PzFVaalNQgFCJetXw2MZPQCIWedzQ6TwlyPE34aCOBf0ivtHGxhRhC7b2AG00xoFyHzkB5ArHlMVw==\\\"/><input type=\\\"hidden\\\" name=\\\"frontUrl\\\" id=\\\"frontUrl\\\" value=\\\"http://localhost:50003/return_un_url.aspx\\\"/><input type=\\\"hidden\\\" name=\\\"txnType\\\" id=\\\"txnType\\\" value=\\\"01\\\"/><input type=\\\"hidden\\\" name=\\\"channelType\\\" id=\\\"channelType\\\" value=\\\"08\\\"/><input type=\\\"hidden\\\" name=\\\"certId\\\" id=\\\"certId\\\" value=\\\"69363599447\\\"/><input type=\\\"hidden\\\" name=\\\"encoding\\\" id=\\\"encoding\\\" value=\\\"UTF-8\\\"/><input type=\\\"hidden\\\" name=\\\"version\\\" id=\\\"version\\\" value=\\\"5.0.0\\\"/><input type=\\\"hidden\\\" name=\\\"accessType\\\" id=\\\"accessType\\\" value=\\\"0\\\"/><input type=\\\"hidden\\\" name=\\\"txnTime\\\" id=\\\"txnTime\\\" value=\\\"20151222155314\\\"/><input type=\\\"hidden\\\" name=\\\"merId\\\" id=\\\"merId\\\" value=\\\"898320548160217\\\"/><input type=\\\"hidden\\\" name=\\\"currencyCode\\\" id=\\\"currencyCode\\\" value=\\\"156\\\"/><input type=\\\"hidden\\\" name=\\\"orderDesc\\\" id=\\\"orderDesc\\\" value=\\\"dotNet自来水\\\"/><input type=\\\"hidden\\\" name=\\\"txnAmt\\\" id=\\\"txnAmt\\\" value=\\\"1\\\"/><input type=\\\"hidden\\\" name=\\\"signMethod\\\" id=\\\"signMethod\\\" value=\\\"01\\\"/></form></body><script type=\\\"text/javascript\\\">document.all.pay_form.submit();</script></html>\",\"id\":\"d020f6b8-b35f-41a3-b4a8-780846c03725\"}";
     BCBill actual = BCPay.handlePayResult(respString, bill);
     Assert.IsNotNull(actual.id);
     Assert.IsNotNull(actual.html);
 }
Esempio n. 15
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string type = Request.Form["paytype"];
            if (type == "alipay")
            {
                BCBill bill = new BCBill(BCPay.PayChannel.ALI_WEB.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
                bill.returnUrl = "http://*****:*****@xx.com";
                data.receiverName = "某某某";
                data.transferFee = 100;
                data.transferNote = "note";
                BCTransferData data2 = new BCTransferData();
                data2.transferId = BCUtil.GetUUID();
                data2.receiverAccount = "*****@*****.**";
                data2.receiverName = "某某";
                data2.transferFee = 100;
                data2.transferNote = "note";
                List<BCTransferData> list = new List<BCTransferData>();
                list.Add(data);
                list.Add(data2);

                try
                {
                    BCTransfersParameter para = new BCTransfersParameter();
                    para.channel = BCPay.TransferChannel.ALI.ToString();
                    para.batchNo = BCUtil.GetUUID();
                    para.accountName = "毛毛";
                    para.transfersData = list;
                    string transfersURL = BCPay.BCTransfers(para);
                    Response.Write("<a href=" + transfersURL + ">付款地址</a><br/>");
                }
                catch (Exception excption)
                {
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>");
                }
            }
            else if (type == "alitransfer")
            {
                try
                {
                    BCTransferParameter para = new BCTransferParameter();
                    para.channel = BCPay.TransferChannel.ALI_TRANSFER.ToString();
                    para.transferNo = BCUtil.GetUUID();
                    para.totalFee = 100;
                    para.desc = "C# 单笔打款";
                    para.channelUserId = "*****@*****.**";
                    para.channelUserName = "******";
                    para.accountName = "XXX有限公司";
                    string aliURL = BCPay.BCTransfer(para);
                    Response.Write("<a href=" + aliURL + ">付款地址</a><br/>");
                }
                catch (Exception excption)
                {
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>");
                }
            }
            else if (type == "wxtransfer")
            {
                try
                {
                    BCTransferParameter para = new BCTransferParameter();
                    para.channel = BCPay.TransferChannel.WX_TRANSFER.ToString();
                    para.transferNo = "1000000000";
                    para.totalFee = 100;
                    para.desc = "C# 单笔打款";
                    para.channelUserId = "XXXXXXXXXXXXXXXXXX";
                    BCPay.BCTransfer(para);
                    Response.Write("完成");
                }
                catch (Exception excption)
                {
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>");
                }
            }
            else if (type == "wxredpack")
            {
                BCRedPackInfo info = new BCRedPackInfo();
                info.actName = "C# 红包";
                info.sendName = "BeeCloud";
                info.wishing = "啦啦啦";

                try
                {
                    BCTransferParameter para = new BCTransferParameter();
                    para.channel = BCPay.TransferChannel.WX_REDPACK.ToString();
                    para.transferNo = "1000000001";
                    para.totalFee = 100;
                    para.desc = "C# 红包";
                    para.channelUserId = "XXXXXXXXXXXXXXXX";
                    para.info = info;
                    BCPay.BCTransfer(para);
                    Response.Write("完成");
                }
                catch (Exception excption)
                {
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>");
                }
            }
            else if (type == "bctransfer")
            {
                //getBankFullNames方法可以获取所有支持的银行全称,将全称填写到BCTransferWithBackCard里的bank_fullname字段
                BankList banks = BCPay.getBankFullNames("P_CR");
                foreach (var bank in banks.bankList)
                {
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + bank.ToString() + "</span><br/>");
                }

                BCTransferWithBackCard transfer = new BCTransferWithBackCard(1, BCUtil.GetUUID(), ".net测试代付", "OUT_PC", "中国银行", "DE", "P", "xxxxxxxxxxxx", "xxx");
                transfer.mobile = "xxxxxxxxxxxxxx";
                try
                {
                    transfer = BCPay.BCBankCardTransfer(transfer);
                    Response.Write("<span style='color:#00CD00;font-size:20px'>已代付</span><br/>");
                }
                catch (Exception excption)
                {
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>");
                }
            }
            else if (type == "bccjtransfer")
            {
                BCCJTransferWithBackCard transfer = new BCCJTransferWithBackCard(BCUtil.GetUUID(), ".net测试代付", 100, "姓名", "银行名", "卡号", "支行名", "省", "市", "DEBIT", "C");
                try
                {
                    transfer = BCPay.BCCJBankCardTransfer(transfer);
                    Response.Write("<span style='color:#00CD00;font-size:20px'>已代付</span><br/>");
                }
                catch (Exception excption)
                {
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + excption.Message + "</span><br/>");
                }
            }
            Response.Write("<span style='color:#00CD00;font-size:20px'>" + type + "</span>");
        }
Esempio n. 16
0
 public void handleAliWebPayResultTest()
 {
     BCBill bill = new BCBill(BCPay.PayChannel.ALI_WEB.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水");
     bill.returnUrl = "http://*****:*****@beecloud.cn\\\"/><input type=\\\"hidden\\\" name=\\\"subject\\\" value=\\\"dotNet自来水\\\"/><input type=\\\"hidden\\\" name=\\\"_input_charset\\\" value=\\\"utf-8\\\"/><input type=\\\"hidden\\\" name=\\\"sign\\\" value=\\\"6b69e7e8b890b0f2e5ba282028d583a3\\\"/><input type=\\\"hidden\\\" name=\\\"notify_url\\\" value=\\\"http://payservice.beecloud.cn/bcpay/aliPayDynamic/c37d661d-7e61-49ea-96a5-68c34e83db3b_06e5647b-f5f2-4697-aba9-e2bb05608aa8.php\\\"/><input type=\\\"hidden\\\" name=\\\"payment_type\\\" value=\\\"1\\\"/><input type=\\\"hidden\\\" name=\\\"out_trade_no\\\" value=\\\"64a054f5ae0841188f077172b54dedf9\\\"/><input type=\\\"hidden\\\" name=\\\"partner\\\" value=\\\"2088711322600312\\\"/><input type=\\\"hidden\\\" name=\\\"service\\\" value=\\\"create_direct_pay_by_user\\\"/><input type=\\\"hidden\\\" name=\\\"total_fee\\\" value=\\\"0.01\\\"/><input type=\\\"hidden\\\" name=\\\"return_url\\\" value=\\\"http://*****:*****@beecloud.cn&subject=dotNet自来水&_input_charset=utf-8&sign=6b69e7e8b890b0f2e5ba282028d583a3&notify_url=http://payservice.beecloud.cn/bcpay/aliPayDynamic/c37d661d-7e61-49ea-96a5-68c34e83db3b_06e5647b-f5f2-4697-aba9-e2bb05608aa8.php&payment_type=1&out_trade_no=64a054f5ae0841188f077172b54dedf9&partner=2088711322600312&service=create_direct_pay_by_user&total_fee=0.01&return_url=http://localhost:50003/return_ali_url.aspx&exter_invoke_ip=112.86.54.108&sign_type=MD5\"}";
     BCBill actual = BCPay.handlePayResult(respString, bill);
     Assert.IsNotNull(actual.id);
     Assert.IsNotNull(actual.url);
     Assert.IsNotNull(actual.html);
 }
Esempio n. 17
0
        /// <summary>
        /// 支付订单查询
        /// </summary>
        /// <param name="channel">渠道类型
        ///     选填
        ///     可以通过enum BCPay.QueryChannel获取
        ///     channel的参数值含义:
        ///     WX_APP:       微信手机APP支付
        ///     WX_NATIVE:    微信公众号二维码支付
        ///     WX_JSAPI:     微信公众号支付
        ///     ALI_APP:      支付宝APP支付
        ///     ALI_WEB:      支付宝网页支付 
        ///     ALI_QRCODE:   支付宝内嵌二维码支付
        ///     UN_APP:       银联APP支付
        ///     UN_WEB:       银联网页支付
        ///     JD_WAP:       京东wap支付
        ///     JD_WEB:       京东web支付
        ///     YEE_WAP:      易宝wap支付 
        ///     YEE_WEB:      易宝web支付
        ///     KUAIQIAN_WAP: 快钱wap支付
        ///     KUAIQIAN_WEB: 快钱web支付
        ///     注意:不传channel也能查询的前提是保证所有渠道所有订单号不同,如果出现两个订单号重复,会报错提示传入channel进行区分
        /// </param>
        /// <param name="billNo">商户订单号
        /// </param>
        /// <param name="startTime">起始时间
        ///     毫秒时间戳, 13位, 可以使用BCUtil.GetTimeStamp()方法获取
        ///     选填
        /// </param>
        /// <param name="endTime">结束时间
        ///     毫秒时间戳, 13位, 可以使用BCUtil.GetTimeStamp()方法获取
        ///     选填
        /// </param>
        /// <param name="skip">查询起始位置
        ///     默认为0。设置为10表示忽略满足条件的前10条数据
        ///     选填
        /// </param>
        /// <param name="limit">查询的条数
        ///     默认为10,最大为50。设置为10表示只返回满足条件的10条数据
        ///     选填
        /// </param>
        /// <returns></returns>
        public static BCPayQueryResult BCPayQueryByCondition(string channel, string billNo, long? startTime, long? endTime, int? skip, int? limit)
        {
            Random random = new Random();
            string payQueryUrl = BCPrivateUtil.mLocalDefaultHosts[random.Next(0, 4)] + BCConstants.version + BCConstants.billsURL;

            long timestamp = BCUtil.GetTimeStamp(DateTime.Now);

            JsonData data = new JsonData();
            data["app_id"] = BCCache.Instance.appId;
            data["app_sign"] = BCPrivateUtil.getAppSignature(BCCache.Instance.appId, BCCache.Instance.appSecret, timestamp.ToString());
            data["timestamp"] = timestamp;
            data["channel"] = channel;
            data["bill_no"] = billNo;
            data["start_time"] = startTime;
            data["end_time"] = endTime;
            data["skip"] = skip;
            data["limit"] = limit;

            string paraString = data.ToJson();

            try
            {
                string url = payQueryUrl + "?para=" + HttpUtility.UrlEncode(paraString, Encoding.UTF8);
                HttpWebResponse response = BCPrivateUtil.CreateGetHttpResponse(url, BCCache.Instance.networkTimeout, null, null);
                string respString = BCPrivateUtil.GetResponseString(response);
                JsonData responseData = JsonMapper.ToObject(respString);

                BCPayQueryResult result = new BCPayQueryResult();

                result.resultCode = int.Parse(responseData["result_code"].ToString());
                result.resultMsg = responseData["result_msg"].ToString();
                if (result.resultCode == 0)
                {
                    result.count = int.Parse(responseData["count"].ToString());
                    if (responseData["bills"].IsArray)
                    {
                        List<BCBill> bills = new List<BCBill>();
                        foreach (JsonData billData in responseData["bills"])
                        {
                            BCBill bill = new BCBill();
                            bill.title = billData["title"].ToString();
                            bill.totalFee = int.Parse(billData["total_fee"].ToString());
                            bill.createdTime = BCUtil.GetDateTime((long)billData["created_time"]);
                            bill.billNo = billData["bill_no"].ToString();
                            bill.result = (bool)billData["spay_result"];
                            bill.channel = billData["channel"].ToString();
                            bills.Add(bill);
                        }
                        result.bills = bills;
                    }
                }
                else
                {
                    result.errDetail = responseData["err_detail"].ToString();
                }

                return result;
            }
            catch(Exception e)
            {
                BCPayQueryResult result = new BCPayQueryResult();
                result.resultCode = 99;
                result.resultMsg = e.Message;
                return result;
            }
        }