예제 #1
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            //string forms = "discount=0.00&payment_type=1&subject=%u9ed1%u7c73%u58f3&trade_no=2016111521001004630270573220&buyer_email=15670179992&gmt_create=2016-11-15+09%3a29%3a16&notify_type=trade_status_sync&quantity=1&out_trade_no=1115092904-1643&seller_id=2088421544580296&notify_time=2016-11-15+10%3a55%3a09&body=%u8bdd%u8d39%u5957%u9910&trade_status=TRADE_SUCCESS&is_total_fee_adjust=N&total_fee=0.01&gmt_payment=2016-11-15+09%3a29%3a17&seller_email=cbaohai%40126.com&price=0.01&buyer_id=2088012967203633&notify_id=53526949d59c9297c6641bd8e450a03kv2&use_coupon=N&sign_type=RSA&sign=WDJhrGG2kEgGvKtfPG3WoMn8mwleWbyDTR0scZ6HmSK39OZnlHKS8lSTkYM09ZY4y7%2bxTM1IeNmFsVcbK%2bVJK2jHYX43RyEIyBkCgJVuo0IpUDPYZidyrgEeGKoeV0FPutykbLIueQNSoAENkPsAmFWd1J1FQMYvF8akJL1R%2b5k%3d";
            //forms = HttpUtility.UrlDecode(forms, Encoding.UTF8);
            SortedDictionary <string, string> sPara = AlipayCore.GetRequestPost();

            //Dictionary<string, string> dic = CommonHelper.ParmsToDic(forms);
            //foreach (KeyValuePair<string, string> kv in dic)
            //{
            //    sPara[kv.Key] = kv.Value;
            //}
            //BSPLog.Instance.Write(Request.Form.ToString());
            if (sPara.Count > 0)//判断是否有带返回参数
            {
                bool verifyResult = AlipayNotify.AppVerify(sPara, sPara["notify_id"], sPara["sign"], AlipayConfig.AppSignType, AlipayConfig.PublicKey, AlipayConfig.AppInputCharset, AlipayConfig.AppVeryfyUrl, AlipayConfig.Partner);
                if (verifyResult && (sPara["trade_status"] == "TRADE_FINISHED" || sPara["trade_status"] == "TRADE_SUCCESS")) //验证成功
                {
                    string   out_trade_no = sPara["out_trade_no"];                                                           //商户订单号
                    string   tradeSN      = sPara["trade_no"];                                                               //支付宝交易号
                    decimal  tradeMoney   = TypeHelper.StringToDecimal(sPara["total_fee"]);                                  //交易金额
                    DateTime tradeTime    = TypeHelper.StringToDateTime(sPara["gmt_payment"]);                               //交易时间

                    return(Content(Recharge.UpdateRecharge(tradeMoney.ToString(), out_trade_no, sPara["gmt_payment"], tradeSN)));
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }
예제 #2
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            SortedDictionary <string, string> sPara = AlipayCore.GetRequestPost();

            if (sPara.Count > 0)//判断是否有带返回参数
            {
                bool verifyResult = AlipayNotify.AppVerify(sPara, Request.Form["notify_id"], Request.Form["sign"], AlipayConfig.AppSignType, AlipayConfig.PublicKey, AlipayConfig.AppInputCharset, AlipayConfig.AppVeryfyUrl, AlipayConfig.Partner);
                if (verifyResult && (Request.Form["trade_status"] == "TRADE_FINISHED" || Request.Form["trade_status"] == "TRADE_SUCCESS")) //验证成功
                {
                    string   out_trade_no = Request.Form["out_trade_no"];                                                                  //商户订单号
                    string   tradeSN      = Request.Form["trade_no"];                                                                      //支付宝交易号
                    decimal  tradeMoney   = TypeHelper.StringToDecimal(Request.Form["total_amount"]);                                      //交易金额
                    DateTime tradeTime    = TypeHelper.StringToDateTime(Request.Form["gmt_payment"]);                                      //交易时间

                    return(Content(Recharge.UpdateRecharge(tradeMoney.ToString(), out_trade_no, Request.Form["gmt_payment"], tradeSN)));
                }
                else//验证失败
                {
                    return(Content("fail"));
                }
            }
            else
            {
                return(Content("无通知参数"));
            }
        }
예제 #3
0
        /// <summary>
        /// 通知调用
        /// </summary>
        public ActionResult Notify()
        {
            //创建ResponseHandler实例
            ResponseHandler resHandler = new ResponseHandler(System.Web.HttpContext.Current);

            resHandler.setKey(PayConfig.AppKey);

            //判断签名
            try
            {
                string error = "";
                if (resHandler.isWXsign(out error))
                {
                    #region 协议参数=====================================
                    //--------------协议参数--------------------------------------------------------
                    //SUCCESS/FAIL此字段是通信标识,非交易标识,交易是否成功需要查
                    string return_code = resHandler.getParameter("return_code");
                    //返回信息,如非空,为错误原因签名失败参数格式校验错误
                    string return_msg = resHandler.getParameter("return_msg");
                    //微信分配的公众账号 ID
                    string appid = resHandler.getParameter("appid");

                    //以下字段在 return_code 为 SUCCESS 的时候有返回--------------------------------
                    //微信支付分配的商户号
                    string mch_id = resHandler.getParameter("mch_id");
                    //微信支付分配的终端设备号
                    string device_info = resHandler.getParameter("device_info");
                    //微信分配的公众账号 ID
                    string nonce_str = resHandler.getParameter("nonce_str");
                    //业务结果 SUCCESS/FAIL
                    string result_code = resHandler.getParameter("result_code");
                    //错误代码
                    string err_code = resHandler.getParameter("err_code");
                    //结果信息描述
                    string err_code_des = resHandler.getParameter("err_code_des");

                    //以下字段在 return_code 和 result_code 都为 SUCCESS 的时候有返回---------------
                    //-------------业务参数---------------------------------------------------------
                    //用户在商户 appid 下的唯一标识
                    string openid = resHandler.getParameter("openid");
                    //用户是否关注公众账号,Y-关注,N-未关注,仅在公众账号类型支付有效
                    string is_subscribe = resHandler.getParameter("is_subscribe");
                    //JSAPI、NATIVE、MICROPAY、APP
                    string trade_type = resHandler.getParameter("trade_type");
                    //银行类型,采用字符串类型的银行标识
                    string bank_type = resHandler.getParameter("bank_type");
                    //订单总金额,单位为分
                    string total_fee = resHandler.getParameter("total_fee");
                    //货币类型,符合 ISO 4217 标准的三位字母代码,默认人民币:CNY
                    string fee_type = resHandler.getParameter("fee_type");
                    //微信支付订单号
                    string transaction_id = resHandler.getParameter("transaction_id");
                    //商户系统的订单号,与请求一致。
                    string out_trade_no = resHandler.getParameter("out_trade_no");
                    //商家数据包,原样返回
                    string attach = resHandler.getParameter("attach");
                    //支 付 完 成 时 间 , 格 式 为yyyyMMddhhmmss,如 2009 年12 月27日 9点 10分 10 秒表示为 20091227091010。时区为 GMT+8 beijing。该时间取自微信支付服务器
                    string time_end = resHandler.getParameter("time_end");

                    #endregion
                    //支付成功
                    if (!out_trade_no.Equals("") && return_code.Equals("SUCCESS") && result_code.Equals("SUCCESS"))
                    {
                        //LogUtil.WriteLog("Notify 页面  支付成功,支付信息:商家订单号:" + out_trade_no + "、支付金额(分):" + total_fee + "、自定义参数:" + attach);

                        /**
                         *  这里输入用户逻辑操作,比如更新订单的支付状态
                         *
                         * **/
                        return(Content(Recharge.UpdateRecharge((double.Parse(total_fee) / 100).ToString(), out_trade_no, time_end, "")));
                    }
                    else
                    {
                        LogUtil.WriteLog("Notify 页面  支付失败,支付信息   total_fee= " + total_fee + "、err_code_des=" + err_code_des + "、result_code=" + result_code);
                        return(new EmptyResult());
                    }
                }
                else
                {
                    LogUtil.WriteLog("Notify 页面  isWXsign= false ,错误信息:" + error);
                    return(new EmptyResult());
                }
            }
            catch (Exception ee)
            {
                LogUtil.WriteLog("Notify 页面  发送异常错误:" + ee.Message);
                return(new EmptyResult());
            }
        }