예제 #1
0
        public object UnifiedOrder(SortedDictionary <string, string> dic)
        {
            string url = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            //检测必填参数
            if (!dic.ContainsKey("out_trade_no"))
            {
                throw new Exception("缺少统一支付接口必填参数out_trade_no!");
            }
            if (!dic.ContainsKey("body"))
            {
                throw new Exception("缺少统一支付接口必填参数body!");
            }
            if (!dic.ContainsKey("total_fee"))
            {
                throw new Exception("缺少统一支付接口必填参数total_fee!");
            }
            if (!dic.ContainsKey("trade_type"))
            {
                throw new Exception("缺少统一支付接口必填参数trade_type!");
            }

            //关联参数
            if (dic["trade_type"] == "JSAPI" && !dic.ContainsKey("openid"))
            {
                throw new Exception("统一支付接口中,缺少必填参数openid!trade_type为JSAPI时,openid为必填参数!");
            }
            if (dic["trade_type"] == "NATIVE" && !dic.ContainsKey("product_id"))
            {
                throw new Exception("统一支付接口中,缺少必填参数product_id!trade_type为JSAPI时,product_id为必填参数!");
            }
            if (!dic.ContainsKey("notify_url"))
            {
                throw new Exception("异步通知Url未设置");
            }

            //添加公共部分参数
            dic.Add("appid", _commonService.AppId);
            dic.Add("mch_id", Mchid);
            dic.Add("spbill_create_ip", "127.0.0.1");
            dic.Add("nonce_str", _helper.GenerateNonceStr());

            dic.Add("sign", MakeSign(dic));
            var         xml      = _helper.ConvertToXml(dic);
            var         response = _helper.SendPost(url, xml, null);
            XmlDocument xmlDoc   = new XmlDocument();

            xmlDoc.LoadXml(response);
            return(xmlDoc);
        }
예제 #2
0
        // GET: WePay
        public ActionResult Index(string orderNo, string openId)
        {
            if (string.IsNullOrEmpty(orderNo))
            {
                return(RedirectToAction("Error"));
            }
            if (_workContext.CurrentUser == null)
            {
                return(RedirectToAction("Error", new { msg = "无法获取当前用户,支付失败" }));
            }
            var order =
                _orderService.GetOrdersByCondition(new OrderSearchCondition {
                OrderNum = orderNo
            }).FirstOrDefault();

            if (order == null)
            {
                return(RedirectToAction("Error", new { msg = "无法获取订单信息,支付失败" }));
            }
            if (order.Adduser != _workContext.CurrentUser)
            {
                return(RedirectToAction("Error", new { msg = "非订单所属客户,支付失败" }));
            }
            var payParamDic = new SortedDictionary <string, string>
            {
                { "device_info", "WEB" },
                { "body", order.Details.First().Product.Name },
                { "detail", order.Details.First().Product.Name + "等商品" },
                { "attach", "" },
                { "out_trade_no", order.OrderNum },
                { "total_fee", order.TotalPrice.ToString("F") },
                { "notify_url", Request.Url.Host },
                { "trade_type", "JSAPI" },
                { "openid", openId }
            };
            var     unifiedReponse = (XmlDocument)_wePayService.UnifiedOrder(payParamDic);
            XmlNode xmlNode        = unifiedReponse.FirstChild;//获取到根节点<xml>

            if (xmlNode.Attributes["return_code"].Value != "SUCCESS" || xmlNode.Attributes["result_code"].Value != "SUCCESS")
            {
                return(RedirectToAction("Error", new { msg = xmlNode.Attributes["return_msg"].Value }));
            }
            var payModel = new PayModel
            {
                AppId     = _commonService.AppId,
                NonceStr  = _helper.GenerateNonceStr(),
                Package   = "prepay_id=" + xmlNode.Attributes["prepay_id"].Value,
                SignType  = "MD5",
                TimeStamp = _helper.GenerateTimeStamp()
            };
            var signDic = new SortedDictionary <string, string>
            {
                { "appId", payModel.AppId },
                { "timeStamp", payModel.TimeStamp },
                { "nonceStr", payModel.NonceStr },
                { "package", payModel.Package },
                { "signType", payModel.SignType },
            };

            payModel.PaySign = _wePayService.MakeSign(signDic);
            return(View(payModel));
        }
예제 #3
0
 public HttpResponseMessage GetJSConfig()
 {
     try
     {
         var model = new JsConfigModel
         {
             appId     = _wcCommonService.AppId,
             debug     = true,
             jsApiList = new[] { "onMenuShareTimeline",
                                 "onMenuShareAppMessage",
                                 "onMenuShareQQ",
                                 "onMenuShareWeibo",
                                 "startRecord",
                                 "stopRecord",
                                 "onVoiceRecordEnd",
                                 "playVoice",
                                 "pauseVoice",
                                 "stopVoice",
                                 "onVoicePlayEnd",
                                 "uploadVoice",
                                 "downloadVoice",
                                 "chooseImage",
                                 "previewImage",
                                 "uploadImage",
                                 "downloadImage",
                                 "translateVoice",
                                 "getNetworkType",
                                 "openLocation",
                                 "getLocation",
                                 "hideOptionMenu",
                                 "showOptionMenu",
                                 "hideMenuItems",
                                 "showMenuItems",
                                 "hideAllNonBaseMenuItem",
                                 "showAllNonBaseMenuItem",
                                 "closeWindow",
                                 "scanQRCode",
                                 "chooseWXPay",
                                 "openProductSpecificView",
                                 "addCard",
                                 "chooseCard",
                                 "openCard" },
             nonceStr  = _helper.GenerateNonceStr(),
             timestamp = _helper.GenerateTimeStamp()
         };
         var dic = new SortedDictionary <string, string>
         {
             { "timestamp", model.timestamp },
             { "nonceStr", model.nonceStr },
             { "jsapi_ticket", _wcCommonService.JsAPITicket },
             { "url", Request.RequestUri.AbsoluteUri }
         };
         model.signature = _wcCommonService.MakeSign(dic);
         return(PageHelper.toJson(new ResultModel()
         {
             Msg = "获取配置文件成功", Object = model, Status = true
         }));
     }
     catch (Exception e)
     {
         return(PageHelper.toJson(new ResultModel()
         {
             Msg = "获取配置文件失败", Status = false
         }));
     }
 }