示例#1
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);

                    BCWxJSAPIPayResult result = BCPay.BCPayByChannel(BCPay.PayChannel.WX_JSAPI.ToString(), 1, BCUtil.GetUUID(), "dotnet", null, null, jsApiPay.openid, null, null) as BCWxJSAPIPayResult;
                    //Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultCode + "</span><br/>");
                    //Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultMsg + "</span><br/>");
                    if (result.resultCode == 0)
                    {
                        timeStamp = result.timestamp;
                        noncestr  = result.noncestr;
                        package   = result.package;
                        paySign   = result.paySign;
                        signType  = result.signType;
                    }
                    else
                    {
                        Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.errDetail + "</span><br/>");
                    }
                }
                catch (Exception ex)
                {
                    Response.Write("<span style='color:#FF0000;font-size:20px'>" + "页面加载出错,请重试" + ex.Message + "</span>");
                }
            }
        }
示例#2
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: 银联网页支付
        /// </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="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>
        ///     BCPayResult, 根据不同的支付渠道有各自对应的result类型
        /// </returns>
        public static BCPayResult BCPayByChannel(string channel, int totalFee, string billNo, string title, Dictionary <string, string> optional, string returnUrl, string openId, string showURL, string qrPayMode)
        {
            Random random = new Random();
            string payUrl = BCPrivateUtil.mLocalDefaultHosts[random.Next(0, 4)] + 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"]    = channel;
            data["total_fee"]  = totalFee;
            data["bill_no"]    = billNo;
            data["title"]      = title;
            data["return_url"] = returnUrl;

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


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

            string paraString = data.ToJson();

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

                string respString = BCPrivateUtil.GetResponseString(response);

                JsonData responseData = JsonMapper.ToObject(respString);

                if (channel == "WX_NATIVE")
                {
                    BCWxNativePayResult result = new BCWxNativePayResult();
                    result.resultCode = int.Parse(responseData["result_code"].ToString());
                    result.resultMsg  = responseData["result_msg"].ToString();
                    if (responseData["result_code"].ToString() == "0")
                    {
                        result.codeURL = responseData["code_url"].ToString();
                    }
                    else
                    {
                        result.errDetail = responseData["err_detail"].ToString();
                    }
                    return(result);
                }
                if (channel == "WX_JSAPI")
                {
                    BCWxJSAPIPayResult result = new BCWxJSAPIPayResult();
                    result.resultCode = int.Parse(responseData["result_code"].ToString());
                    result.resultMsg  = responseData["result_msg"].ToString();
                    if (responseData["result_code"].ToString() == "0")
                    {
                        result.appId     = responseData["app_id"].ToString();
                        result.package   = responseData["package"].ToString();
                        result.noncestr  = responseData["nonce_str"].ToString();
                        result.timestamp = responseData["timestamp"].ToString();
                        result.paySign   = responseData["pay_sign"].ToString();
                        result.signType  = responseData["sign_type"].ToString();
                    }
                    else
                    {
                        result.errDetail = responseData["err_detail"].ToString();
                    }
                    return(result);
                }
                if (channel == "ALI_WEB" || channel == "ALI_WAP")
                {
                    BCAliWebPayResult result = new BCAliWebPayResult();
                    result.resultCode = int.Parse(responseData["result_code"].ToString());
                    result.resultMsg  = responseData["result_msg"].ToString();
                    if (responseData["result_code"].ToString() == "0")
                    {
                        result.html = responseData["html"].ToString();
                        result.url  = responseData["url"].ToString();
                    }
                    else
                    {
                        result.errDetail = responseData["err_detail"].ToString();
                    }
                    return(result);
                }
                if (channel == "ALI_QRCODE")
                {
                    BCAliQrcodePayResult result = new BCAliQrcodePayResult();
                    result.resultCode = int.Parse(responseData["result_code"].ToString());
                    result.resultMsg  = responseData["result_msg"].ToString();
                    if (responseData["result_code"].ToString() == "0")
                    {
                        result.url = responseData["url"].ToString();
                    }
                    else
                    {
                        result.errDetail = responseData["err_detail"].ToString();
                    }
                    return(result);
                }
                if (channel == "UN_WEB")
                {
                    BCUnWebPayResult result = new BCUnWebPayResult();
                    result.resultCode = int.Parse(responseData["result_code"].ToString());
                    result.resultMsg  = responseData["result_msg"].ToString();
                    if (responseData["result_code"].ToString() == "0")
                    {
                        result.html = responseData["html"].ToString();
                    }
                    else
                    {
                        result.errDetail = responseData["err_detail"].ToString();
                    }
                    return(result);
                }
                return(new BCPayResult());
            }
            catch (Exception e)
            {
                BCPayResult result = new BCPayResult();
                result.resultCode = 99;
                result.resultMsg  = e.Message;
                return(result);
            }
        }
示例#3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string type = Request.Form["paytype"];

            if (type == "alipay")
            {
                BCPayResult result = BCPay.BCPayByChannel(BCPay.PayChannel.ALI_WEB.ToString(), 1, BCUtil.GetUUID(), "dotNet自来水", null, "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);
                BCTransferResult result = BCPay.BCTransfer(BCPay.TransferChannel.ALI.ToString(), BCUtil.GetUUID(), "毛毛", list);
                Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultCode + "</span><br/>");
                Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultMsg + "</span><br/>");
                if (result.resultCode == 0)
                {
                    Response.Write("<a href=" + result.url + ">付款地址</a><br/>");
                }
            }
            else if (type == "wxtransfer")
            {
                Response.Write("<span style='color:#00CD00;font-size:20px'>即将支持</span><br/>");
            }
            else
            {
                BCWxJSAPIPayResult result = BCPay.BCPayByChannel(BCPay.PayChannel.WX_JSAPI.ToString(), 1, BCUtil.GetUUID(), "dotNet自制自来水", null, null, "o3kKrjlUsMnv__cK5DYZMl0JoAkY", null, null) as BCWxJSAPIPayResult;
                Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultCode + "</span><br/>");
                Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.resultMsg + "</span><br/>");
                if (result.resultCode == 0)
                {
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.appId + "</span><br/>");
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.noncestr + "</span><br/>");
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.package + "</span><br/>");
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.paySign + "</span><br/>");
                    Response.Write("<span style='color:#00CD00;font-size:20px'>" + result.signType + "</span><br/>");
                }
            }
            Response.Write("<span style='color:#00CD00;font-size:20px'>" + type + "</span>");
        }