Esempio n. 1
0
        public async Task <ActionResult> YeePayNotifyUrl()
        {
            try
            {
                if (Request["data"] == null)
                {
                    return(Content("参数不正确"));
                }
                //商户注意:接收到易宝的回调信息后一定要回写success用以保证握手成功!
                string data = Request["data"].ToString(); //回调中的参数data
                data = AESUtil.Decrypt(data, YeePayConfig.merchantKey);
                PayResultJson result = Newtonsoft.Json.JsonConvert.DeserializeObject <PayResultJson>(data);

                ///支付结果回调验签
                bool r = Digest.PayResultVerifyHMAC(result.customernumber, result.requestid, result.code, result.notifytype, result.externalid, result.amount, result.cardno, YeePayConfig.merchantKey, result.hmac);
                if (r && result.code == 1)
                {
                    //var opResult = await OrderContract.PayOrder(result.requestid, PayType.易宝);
                    //if (opResult.ResultType == OperationResultType.Success)
                    //{
                    //    return Content("SUCCESS");
                    //}
                }
                return(Content("FAIL"));
            }
            catch
            {
                return(Content("支付失败!"));
            }
        }
Esempio n. 2
0
    void Decry()
    {
        Stopwatch sw = new Stopwatch();

        sw.Start();
        var text = AESUtil.Decrypt(toDecry, AESKey.DefaultKey, AESKey.DefaultIV);

        sw.Stop();
        Debug.Log(sw.ElapsedMilliseconds);

        Debug.Log(text);

        JObject.Parse(text);
    }
Esempio n. 3
0
        protected void Page_Load(object sender, EventArgs e)
        {
            string   error = string.Empty, apikey = string.Empty;
            decimal  tranAmt  = decimal.Zero;
            UserInfo userInfo = null;
            int      userId   = 1080;
            //请求的集合
            NameValueCollection nvcSource = Request.Form == null && Request.Form.Count > 0 ? Request.Form : Request.QueryString;
            string data      = nvcSource["data"];
            string aeskey    = "1234567890123456";
            string preEncode = AESUtil.Decrypt(data, aeskey);
            Dictionary <string, string> dic = new Dictionary <string, string>();

            dic = Newtonsoft.Json.JsonConvert.DeserializeObject <Dictionary <string, string> >(preEncode);
            NameValueCollection nvc = new NameValueCollection();

            foreach (var item in dic)
            {
                nvc.Add(item.Key, item.Value);
            }
            //数据验证
            string Money   = nvc["amount"];
            string Orderid = nvc["requestid"];

            Notifyurl = nvc["callbackurl"];
            #region Step4 数据验证
            if (!CheckUrlReferrer(userId))
            {
                string host = string.Empty;
                if (Request.UrlReferrer != null)
                {
                    host = Request.UrlReferrer.Host;
                }

                error = string.Format("error:1070 来路地址不合法!{0}", host);
            }
            else if (!decimal.TryParse(Money, out tranAmt))
            {
                error = "error:1060 订单金额(value)有误!";
            }
            else if (tranAmt < this.MinTranAMT)
            {
                error = "error:1061 订单金额(value)小于最小允许交易额!";
            }
            else if (tranAmt > this.MaxChargeAMT)
            {
                error = string.Format("error:1062 订单金额(value){0:f2}大于最大允许交易额{1:f2}!", tranAmt, this.MaxChargeAMT);
            }
            else
            {
                var checkResult = Factory.Instance.CheckApiParms(userId, ChannelTypeId, RequiredCheckUserOrderNo, Orderid);
                if (checkResult == null)
                {
                    error = "error:1063 系统错误";
                }
                else
                {
                    userInfo = checkResult.Obj as UserInfo;
                    if (userInfo == null)
                    {
                        error = "error:1067 系统错误";
                    }
                    else if (checkResult.ErrCode == 1)
                    {
                        error = "error:1064 商户编号不存在";
                    }
                    else if (checkResult.ErrCode == 2)
                    {
                        error = "error:1065 商户状态不正常";
                    }
                    else if (checkResult.ErrCode == 3)
                    {
                        error = "error:1069 商户订单号重复";
                    }
                    else if (!VerifyHmac(nvc, userInfo.APIKey))
                    {
                        error = "error:1066 签名错误!";
                    }
                    else
                    {
                        apikey = userInfo.APIKey;
                        //riskWarning = userInfo.RiskWarning == 1 ? true : false;
                    }
                }
            }

            if (!string.IsNullOrEmpty(error))
            {
                WebUtility.ShowErrorMsg(error);
                return;
            }
            #endregion

            int typeId = 0; int supplierId = 0;
            var channelInfo = viviapi.BLL.Channel.Factory.GetModel(ChannelTypeId, Bankid, userId, true);

            if (channelInfo == null)
            {
                error = "error:1067:银行编号不存在!";
            }
            else if (channelInfo.isOpen != null && channelInfo.isOpen.Value != 1)
            {
                error = "error:1068:通道维护中!";
            }
            if (!string.IsNullOrEmpty(error))
            {
                if (DebuglogOpen)
                {
                    if (userInfo != null && userInfo.isdebug == 1)
                    {
                        var debugInfo = new viviapi.Model.Sys.debuginfo
                        {
                            addtime   = DateTime.Now,
                            bugtype   = viviapi.Model.Sys.debugtypeenum.网银订单,
                            detail    = string.Empty,
                            errorcode = error,
                            errorinfo = error,
                            userid    = userInfo.ID,
                            url       = Request.RawUrl.ToString(CultureInfo.InvariantCulture)
                        };

                        viviapi.BLL.Sys.Debuglog.Insert(debugInfo);
                    }
                }

                WebUtility.ShowErrorMsg(error);
                return;
            }

            if (channelInfo != null)
            {
                typeId = channelInfo.typeId;
                if (channelInfo.supplier != null)
                {
                    supplierId = channelInfo.supplier.Value;
                }
            }

            var order = new OrderBankInfo
            {
                orderid                                = Factory.Instance.GenerateOrderId(OrderPrefix),
                addtime                                = DateTime.Now,
                attach                                 = Attach,
                notifycontext                          = string.Empty,
                notifycount                            = 0,
                notifystat                             = 0,
                notifyurl                              = this.Notifyurl,
                clientip                               = ServerVariables.TrueIP,
                completetime                           = DateTime.Now,
                returnurl                              = "",
                ordertype                              = 1,
                typeId                                 = typeId,
                paymodeId                              = Bankid,
                supplierId                             = supplierId,
                supplierOrder                          = string.Empty,
                userid                                 = userId,
                userorder                              = Orderid,
                refervalue                             = tranAmt,
                referUrl                               = Request.UrlReferrer != null?Request.UrlReferrer.ToString() : string.Empty,
                                              server   = RuntimeSetting.ServerId,
                                              manageId = 0,
                                              version  = version
            };

            if (userInfo != null)
            {
                order.manageId = userInfo.manageId;                   //业务
            }
            if (!order.manageId.HasValue || order.manageId.Value <= 0)
            {
                order.agentId = viviapi.BLL.User.Factory.GetPromID(userId);
            }
            viviapi.Cache.WebCache.GetCacheService().AddObject(order.orderid, order, ExpiresTime);
            //
            NewOrder.Insert(order);

            //viviapi.ETAPI.ebao.EBaoApi api = new viviapi.ETAPI.ebao.EBaoApi();
            //string ret = string.Empty;
            ////if (nvc.AllKeys.Contains("p8_FrpId") && !string.IsNullOrEmpty(nvc.Get("p8_FrpId")))
            ////{
            ////    ret = api.Pay(nvc, "2");
            ////    Response.Write(ret);
            ////}
            ////else
            ////{
            ////    ret = api.Pay(nvc, "1");
            ////    Response.Redirect(ret);
            ////}
            //ret = api.Pay(nvc, "1");

            viviapi.ETAPI.ebao2.EBaoNewApi api = new EBaoNewApi();
            string ret = api.Pay(nvc, HttpContext.Current);
            return;
        }
Esempio n. 4
0
 public static string DecryptAES(this string str)
 {
     return(AESUtil.Decrypt(str));
 }
Esempio n. 5
0
        public ActionResult YeePay(string orderNo)
        {
            //var order = OrderContract.OrderInfos.Where(p => p.OrderNo == orderNo).SingleOrDefault();
            //if (order == null) return Content("订单不存在");

            string serverHost = ConfigurationManager.AppSettings["ServerHost"];

            //一键支付URL前缀
            string apiprefix = APIURLConfig.mobilePrefix;

            //网页支付地址
            string mobilepayURI = APIURLConfig.webpayURI;

            //商户账户编号
            string customernumber = YeePayConfig.merchantAccount;
            string hmacKey        = YeePayConfig.merchantKey;
            string AesKey         = YeePayConfig.AescKey;

            //日志字符串
            StringBuilder logsb = new StringBuilder();

            logsb.Append(DateTime.Now.ToString() + "\n");

            Random ra             = new Random();
            string payproducttype = "ONEKEY";                   // "支付方式";
            string amount         = /*order.TotalPrice + */ ""; //支付金额为单位元
            string requestid      = orderNo;                    //订单号
            string productcat     = "";                         //商品类别码,商户支持的商品类别码由易宝支付运营人员根据商务协议配置
            string productdesc    = "订单商品";                     //商品描述
            string productname    = "订单商品";                     //商品名称
            string assure         = "0";                        //是否需要担保,1是,0否
            string divideinfo     = "";                         //分账信息,格式”ledgerNo:分账比
            string bankid         = "";                         //银行编码
            string period         = "";                         //担保有效期,单位 :天;当assure=1 时必填,最大值:30
            string memo           = "";                         //商户备注
            string userno         = /*order.UserInfo.Id +*/ ""; //用户标识
            string ip             = "";                         //IP
            string cardname       = "";                         //持卡人姓名
            string idcard         = "";                         //身份证
            string bankcardnum    = "";                         //银行卡号

            //商户提供的商户后台系统异步支付回调地址
            string callbackurl = string.Format("{0}Admin/Pay/YeePayNotifyUrl", serverHost);
            //商户提供的商户前台系统异步支付回调地址
            string webcallbackurl = "";
            string hmac           = "";


            hmac = Digest.GetHMAC(customernumber, requestid, amount, assure, productname, productcat, productdesc, divideinfo, callbackurl, webcallbackurl, bankid, period, memo, hmacKey);

            SortedDictionary <string, object> sd = new SortedDictionary <string, object>();

            sd.Add("customernumber", customernumber);
            sd.Add("amount", amount);
            sd.Add("requestid", requestid);
            sd.Add("assure", assure);
            sd.Add("productname", productname);
            sd.Add("productcat", productcat);
            sd.Add("productdesc", productdesc);
            sd.Add("divideinfo", divideinfo);
            sd.Add("callbackurl", callbackurl);
            sd.Add("webcallbackurl", webcallbackurl);
            sd.Add("bankid", bankid);
            sd.Add("period", period);
            sd.Add("memo", memo);
            sd.Add("payproducttype", payproducttype);
            sd.Add("userno", userno);
            sd.Add("ip", ip);
            sd.Add("cardname", cardname);
            sd.Add("idcard", idcard);
            sd.Add("bankcardnum", bankcardnum);
            sd.Add("hmac", hmac);

            //将网页支付对象转换为json字符串
            string wpinfo_json = Newtonsoft.Json.JsonConvert.SerializeObject(sd);

            logsb.Append("手机支付明文数据json格式为:" + wpinfo_json + "\n");

            string datastring = AESUtil.Encrypt(wpinfo_json, AesKey);

            logsb.Append("手机支付业务数据经过AES加密后的值为:" + datastring + "\n");



            //打开浏览器访问一键支付网页支付链接地址,请求方式为get
            string postParams = "data=" + HttpUtility.UrlEncode(datastring) + "&customernumber=" + customernumber;
            string url        = apiprefix + mobilepayURI + "?" + postParams;

            logsb.Append("手机支付链接地址为:" + url + "\n");

            string ybResult = YJPayUtil.payAPIRequest(apiprefix + mobilepayURI, datastring, false);

            logsb.Append("请求支付结果:" + ybResult + "\n");

            //将支付结果json字符串反序列化为对象
            RespondJson respJson = Newtonsoft.Json.JsonConvert.DeserializeObject <RespondJson>(ybResult);
            string      yb_data  = respJson.data;

            yb_data = AESUtil.Decrypt(yb_data, YeePayConfig.merchantKey);
            PayRequestJson result = Newtonsoft.Json.JsonConvert.DeserializeObject <PayRequestJson>(yb_data);

            if (result.code == 1)
            {
                bool r = Digest.PayRequestVerifyHMAC(result.customernumber, result.requestid, result.code, result.externalid, result.amount, result.payurl, hmacKey, result.hmac);
                if (r)
                {
                    //重定向跳转到易宝支付收银台
                    return(Redirect(result.payurl));
                }
                else
                {
                    return(Content("回调验签失败"));
                }
            }
            else
            {
                return(Content(result.msg));
            }
        }