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