Beispiel #1
0
        /**
        * 生成扫描支付模式一URL
        * @param productId 商品ID
        * @return 模式一URL
        */
        public string GetPrePayUrl(string productId)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 1 url is producing...");

            WxPayData data = new WxPayData();
            data.SetValue("appid", WxPayConfig.APPID);//公众帐号id
            data.SetValue("mch_id", WxPayConfig.MCHID);//商户号
            data.SetValue("time_stamp", WxPayApi.GenerateTimeStamp());//时间戳
            data.SetValue("nonce_str", WxPayApi.GenerateNonceStr());//随机字符串
            data.SetValue("product_id", productId);//商品ID
            data.SetValue("sign", data.MakeSign());//签名
            string str = ToUrlParams(data.GetValues());//转换为URL串
            string url = "weixin://wxpay/bizpayurl?" + str;

            Log.Info(this.GetType().ToString(), "Get native pay mode 1 url : " + url);
            return url;
        }
Beispiel #2
0
        /**
         * 生成扫描支付模式一URL
         * @param productId 商品ID
         * @return 模式一URL
         */
        public string GetPrePayUrl(string productId)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 1 url is producing...");

            WxPayData data = new WxPayData();

            data.SetValue("appid", WxPayConfig.APPID);                 //公众帐号id
            data.SetValue("mch_id", WxPayConfig.MCHID);                //商户号
            data.SetValue("time_stamp", WxPayApi.GenerateTimeStamp()); //时间戳
            data.SetValue("nonce_str", WxPayApi.GenerateNonceStr());   //随机字符串
            data.SetValue("product_id", productId);                    //商品ID
            data.SetValue("sign", data.MakeSign());                    //签名
            string str = ToUrlParams(data.GetValues());                //转换为URL串
            string url = "weixin://wxpay/bizpayurl?" + str;

            Log.Info(this.GetType().ToString(), "Get native pay mode 1 url : " + url);
            return(url);
        }
Beispiel #3
0
        /**
         *
         * 从统一下单成功返回的数据中获取微信浏览器调起jsapi支付所需的参数,
         * 微信浏览器调起JSAPI时的输入参数格式如下:
         * {
         *   "appId" : "wx2421b1c4370ec43b",     //公众号名称,由商户传入
         *   "timeStamp":" 1395712654",         //时间戳,自1970年以来的秒数
         *   "nonceStr" : "e61463f8efa94090b1f366cccfbbb444", //随机串
         *   "package" : "prepay_id=u802345jgfjsdfgsdg888",
         *   "signType" : "MD5",         //微信签名方式:
         *   "paySign" : "70EA570631E4BB79628FBCA90534C63FF7FADD89" //微信签名
         * }
         * @return string 微信浏览器调起JSAPI时的输入参数,json格式可以直接做参数用
         * 更详细的说明请参考网页端调起支付API:http://pay.weixin.qq.com/wiki/doc/api/jsapi.php?chapter=7_7
         *
         */
        public SortedDictionary <string, object> GetJsApiParameters(WxPayData unifiedOrderResult)
        {
            Log.Debug(this.GetType().ToString(), "JsApiPay::GetJsApiParam is processing...");

            WxPayData jsApiParam = new WxPayData();

            jsApiParam.SetValue("appId", unifiedOrderResult.GetValue("appid"));
            jsApiParam.SetValue("timeStamp", WxPayApi.GenerateTimeStamp());
            jsApiParam.SetValue("nonceStr", WxPayApi.GenerateNonceStr());
            jsApiParam.SetValue("package", "prepay_id=" + unifiedOrderResult.GetValue("prepay_id"));
            jsApiParam.SetValue("signType", "MD5");
            jsApiParam.SetValue("paySign", jsApiParam.MakeSign());

            string parameters = jsApiParam.ToJson();

            Log.Debug(this.GetType().ToString(), "Get jsApiParam : " + parameters);
            return(jsApiParam.GetValues());
        }
        /**
         * 生成直接支付url,支付url有效期为2小时,模式二
         * @param productId 商品ID
         * @return 模式二URL
         */
        public string GetPayUrl(string orderNo, string productName, string price)
        {
            Log.Info(this.GetType().ToString(), "Native pay mode 2 url is producing...");

            WxPayData data = new WxPayData();

            data.SetValue("body", productName);                                                   //商品描述
            data.SetValue("attach", "");                                                          //附加数据
            data.SetValue("out_trade_no", orderNo);                                               //订单号
            data.SetValue("total_fee", price);                                                    //总金额
            data.SetValue("time_start", DateTime.Now.ToString("yyyyMMddHHmmss"));                 //交易起始时间
            data.SetValue("time_expire", DateTime.Now.AddMinutes(10).ToString("yyyyMMddHHmmss")); //交易结束时间
            data.SetValue("goods_tag", "");                                                       //商品标记
            data.SetValue("trade_type", "NATIVE");                                                //交易类型
            data.SetValue("product_id", orderNo);                                                 //商品ID

            WxPayData result = WxPayApi.UnifiedOrder(data);                                       //调用统一下单接口
            string    url    = result.GetValues()["code_url"].ToString();                         //获得统一下单接口返回的二维码链接

            Log.Info(this.GetType().ToString(), "Get native pay mode 2 url : " + url);
            return(url);
        }
Beispiel #5
0
        /// <summary>
        ///  微信支付专用逻辑
        /// </summary>
        /// <returns></returns>
        public ActionResult WxPay()
        {
            string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            ViewBag.OrderNo    = Request.QueryString["orderNo"].ToString();
            ViewBag.TotalPrice = double.Parse(Request.QueryString["totalprice"].ToString());

            OrderResultModel orm = new OrderResultModel();

            orm.openid           = System.Web.HttpContext.Current.Session["member"].ToString();
            orm.total_fee        = double.Parse(Request.QueryString["totalprice"].ToString()) * 100;
            orm.trade_type       = "JSAPI";
            orm.spbill_create_ip = Request.QueryString["ip"].ToString();
            orm.out_trade_no     = Request.QueryString["orderNo"].ToString();
            orm.appid            = WxPayAPI.WxPayConfig.APPID;
            orm.body             = "捷诚宝商城";
            orm.mch_id           = WxPayAPI.WxPayConfig.MCHID;
            orm.nonce_str        = WxPayAPI.WxPayApi.GenerateNonceStr();
            orm.notify_url       = HttpContext.Request.Url.Scheme + "://" + HttpContext.Request.Url.Host + ":" + HttpContext.Request.Url.Port + "/Pay/WxPayResult";

            WxPayAPI.WxPayData data = new WxPayAPI.WxPayData();
            data.SetValue("openid", orm.openid);
            data.SetValue("total_fee", orm.total_fee);
            data.SetValue("trade_type", orm.trade_type);
            data.SetValue("spbill_create_ip", orm.spbill_create_ip);
            data.SetValue("out_trade_no", orm.out_trade_no);
            data.SetValue("appid", orm.appid);
            data.SetValue("body", orm.body);
            data.SetValue("mch_id", orm.mch_id);
            data.SetValue("nonce_str", orm.nonce_str);
            data.SetValue("notify_url", orm.notify_url);



            orm.sign = data.MakeSign();


            data.SetValue("sign", orm.sign);

            foreach (var item in data.GetValues())
            {
                LogHelper.Log.Write(item.Key + ":" + item.Value);
            }

            string xml      = data.ToXml();
            string response = WxPayAPI.HttpService.Post(xml, url, false, 5);

            WxPayAPI.WxPayData result = new WxPayAPI.WxPayData();
            result.FromXml(response);

            WxPayAPI.WxPayData jsApiParam = new WxPayAPI.WxPayData();
            jsApiParam.SetValue("appId", result.GetValue("appid"));
            jsApiParam.SetValue("timeStamp", WxPayAPI.WxPayApi.GenerateTimeStamp());
            jsApiParam.SetValue("nonceStr", WxPayAPI.WxPayApi.GenerateNonceStr());
            jsApiParam.SetValue("package", "prepay_id=" + result.GetValue("prepay_id"));
            jsApiParam.SetValue("signType", "MD5");
            jsApiParam.SetValue("paySign", jsApiParam.MakeSign());

            string jsonParam = jsApiParam.ToJson();

            ViewData["Result"]     = result;
            ViewData["JsonResult"] = jsonParam;

            return(View());
        }