public bool Pay(QueryAccountResult accountResult, RevOrderResult revOrderResult, dynamic obj, out string msg)
        {
            logger.Info(accountResult.Appid + "," + accountResult.Mchid + "," + accountResult.Pubkey + "," + accountResult.Prikey + "," + obj.userip + "," + revOrderResult.OrderNo + "," + obj.prodname + "," + revOrderResult.PayFee + "," + revOrderResult.AsyncUrl + "," + revOrderResult.SyncUrl + "," + revOrderResult.AccountType);
            Message message = PayRequest.Instance.bookOrder(new TenPayConfig()
            {
                appid = accountResult.Appid, mch_id = accountResult.Mchid, key = accountResult.Pubkey, merchant_private_key = accountResult.Prikey
            }, obj.userip, revOrderResult.OrderNo, obj.prodname, revOrderResult.PayFee, revOrderResult.AsyncUrl, revOrderResult.AccountType == 1 ? revOrderResult.SyncUrl : null, revOrderResult.AccountType);

            if (message.state)
            {
                msg = message.data;
                return(true);
            }
            msg = message.error;
            return(false);
        }
        public void ProcessRequest(HttpContext context)
        {
            context.Response.ContentType = "text/json";

            string  post_content = string.Empty;
            dynamic obj          = null;

            try
            {
                using (StreamReader sr = new StreamReader(context.Request.InputStream, Encoding.UTF8))
                {
                    post_content = sr.ReadToEnd();
                }
                logger.Info("----------------收单开始---------------------");
                logger.Info("请求原串:" + post_content);


                try
                {
                    obj = DynamicJson.Parse(post_content);
                }
                catch
                {
                    logger.Info("解析数据失败");
                    Write(DynamicJson.Serialize(new { code = "9999", msg = "parse_fail", detailurl = "" }));
                    return;
                }

                if (!ApiHelper.CheckOrderParams(obj))
                {
                    logger.Info("参数错误");
                    Write(DynamicJson.Serialize(new { code = "9999", msg = "params_fail", detailurl = obj.detailurl }));
                    return;
                }

                if (!ApiHelper.CheckOrderSign(obj, logger))
                {
                    logger.Info("签名错误");
                    Write(DynamicJson.Serialize(new { code = "9999", msg = "sign_fail", detailurl = obj.detailurl }));
                    return;
                }

                RevOrderResult revOrderResult = ApiHelper.SaveOrder(obj, logger);
                logger.Info(string.Format("订单保存状态:{0},消息:{1}", revOrderResult.Status, revOrderResult.ResultMsg));
                if (revOrderResult.Status)
                {
                    logger.Info("订单保存成功");
                    QueryAccountResult accountResult = ApiHelper.QueryPayAccount(revOrderResult.AppId, revOrderResult.AccountType, logger);
                    if (!accountResult.Status)
                    {
                        logger.Info("获取支付信息失败");
                        Write(DynamicJson.Serialize(new { code = "9999", msg = "pay_fail", detailurl = obj.detailur }));
                        return;
                    }
                    string msg;
                    bool   status = Pay(accountResult, revOrderResult, obj, out msg);
                    if (status)
                    {
                        logger.Info("收单成功");
                        string result = DynamicJson.Serialize(new { code = "0000", msg = "success", detailurl = obj.detailurl, orderid = revOrderResult.OrderNo, form = HttpUtility.UrlEncode(msg, Encoding.UTF8) });
                        Write(result);
                    }
                    else
                    {
                        logger.Info("生成支付信息失败");
                        Write(DynamicJson.Serialize(new { code = "9999", msg = msg, detailurl = obj.detailurl }));
                        ApiHelper.SetFail(revOrderResult.OrderNo, "支付失败" + msg, logger);
                    }
                }
                else
                {
                    logger.Info("订单保存失败");
                    Write(DynamicJson.Serialize(new { code = "9999", msg = revOrderResult.ResultMsg, detailurl = obj.detailurl }));
                    ApiHelper.SetFail(revOrderResult.OrderNo, revOrderResult.ResultMsg, logger);
                }
            }
            catch (Exception ex)
            {
                logger.Fatal(ex.Message, ex);
                Write(DynamicJson.Serialize(new { code = "9999", msg = "收单失败", detailurl = obj.detailurl }));
            }
        }
Exemple #3
0
        public static QueryAccountResult QueryPayAccount(string appid, int account_type, ILogger log)
        {
            OracleParameter[] pars =
            {
                new OracleParameter(":appid",        OracleDbType.Varchar2)
                {
                    Value = appid
                },
                new OracleParameter(":account_type", OracleDbType.Decimal)
                {
                    Value = account_type
                },
                new OracleParameter(":out_code",     OracleDbType.Decimal)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":out_appid",    OracleDbType.Varchar2, 128)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":out_mchid",    OracleDbType.Varchar2, 128)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":out_pubkey",   OracleDbType.Varchar2, 1024)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":out_prikey",   OracleDbType.Varchar2, 2048)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":cert_path",    OracleDbType.Varchar2, 1024)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":ext1",         OracleDbType.Varchar2, 1024)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":ext2",         OracleDbType.Varchar2, 1024)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":ext3",         OracleDbType.Varchar2, 1024)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":ext4",         OracleDbType.Varchar2, 1024)
                {
                    Direction = ParameterDirection.Output
                },
                new OracleParameter(":ext5",         OracleDbType.Varchar2, 1024)
                {
                    Direction = ParameterDirection.Output
                }
            };

            log.Info("输入参数:");
            foreach (var item in pars.Where(v => v.Direction != ParameterDirection.Output).ToList())
            {
                log.Info(string.Format("{0}:{1}", item.ParameterName, item.Value));
            }

            SqlHelper.ExecuteNonQuery("sp_receipt_account_get", CommandType.StoredProcedure, pars);

            log.Info("输出参数:");
            foreach (var item in pars.Where(v => v.Direction == ParameterDirection.Output).ToList())
            {
                log.Info(string.Format("{0}:{1}", item.ParameterName, item.Value));
            }

            QueryAccountResult result = new QueryAccountResult();

            result.Status = pars[pars.Length - 11].Value.ToString() == "100";
            if (result.Status)
            {
                result.Ext5     = pars[pars.Length - 1].Value.ToString();
                result.Ext4     = pars[pars.Length - 2].Value.ToString();
                result.Ext3     = pars[pars.Length - 3].Value.ToString();
                result.Ext2     = pars[pars.Length - 4].Value.ToString();
                result.Ext1     = pars[pars.Length - 5].Value.ToString();
                result.CertPath = pars[pars.Length - 6].Value.ToString();
                result.Prikey   = pars[pars.Length - 7].Value.ToString();
                result.Pubkey   = pars[pars.Length - 8].Value.ToString();
                result.Mchid    = pars[pars.Length - 9].Value.ToString();
                result.Appid    = pars[pars.Length - 10].Value.ToString();
            }
            return(result);
        }