public object callbacktest([FromBody] NullableSortedDict <string, object> data)
        {
            //string outTradeNo,int status,double? payedAmount

            return(new {
                status = "success"
            });
        }
        public object PayTest()
        {
            NullableSortedDict <string, object> postDict = new NullableSortedDict <string, object>();

            postDict["account"]    = "34509003";
            postDict["outTradeNo"] = Guid.NewGuid().ToString("N");
            postDict["amount"]     = 0.0001;
            postDict["notifyUrl"]  = $"http://{Request.Host}/api/callbacktest";
            postDict["currency"]   = "BTC";
            postDict["sign"]       = Helper.Sign(postDict, "810de1dffdb7409383370f2bc509f7a3");

            return(Pay(postDict));
        }
        /// <summary>
        /// 查询支付状态
        /// </summary>
        /// <param name="postData"></param>
        /// <returns></returns>
        public object Query([FromBody] NullableSortedDict <string, object> postData)
        {
            try
            {
                using (var db = new MainDB())
                {
                    string outTradeNo = postData.GetValue <string>("outTradeNo");
                    string sign       = postData.GetValue <string>("sign");

                    var tran = db.Transaction.FirstOrDefault(m => m.OutTradeNo == outTradeNo);
                    if (tran == null)
                    {
                        throw new Exception("无效的outTradeNo");
                    }

                    var wallet = db.Wallet.FirstOrDefault(m => m.id == tran.WalletId);

                    var signResult = Helper.Sign(postData, wallet.Secret);
                    if (signResult != sign)
                    {
                        throw new Exception("签名校验失败");
                    }

                    return(Helper.SignResult(new
                    {
                        outTradeNo = outTradeNo,
                        payedAmount = tran.PayedAmount,
                        status = (int)tran.Status,
                        cyptoCoinTrans = Newtonsoft.Json.JsonConvert.SerializeObject((from m in db.CyptoCoinTran
                                                                                      where m.TransactionId == tran.id
                                                                                      select new {
                            cyptoCoinTransId = m.CyptoCoinTransId,
                            confirmations = m.Confirmations,
                            payedAmount = m.PayedAmount,
                            payTime = m.PayTime                   // 接收到款项的时间
                        }).ToArray())
                    }, wallet.Secret));
                }
            }
            catch (Exception ex)
            {
                return(new
                {
                    status = "error",
                    errMsg = ex.Message
                });
            }
        }
        /// <summary>
        /// 发起btc支付交易
        /// </summary>
        /// <returns></returns>
        public object Pay([FromBody] NullableSortedDict <string, object> postData)
        {
            using (var db = new MainDB())
                using (Way.Lib.CLog log = new Way.Lib.CLog("Pay"))
                {
                    try
                    {
                        double?amount     = postData.GetValue <double?>("amount");
                        string account    = postData.GetValue <string>("account");
                        string sign       = postData.GetValue <string>("sign");
                        string outTradeNo = postData.GetValue <string>("outTradeNo");
                        string notifyUrl  = postData.GetValue <string>("notifyUrl");
                        string currency   = postData.GetValue <string>("currency");

                        if (amount <= 0)
                        {
                            throw new Exception("金额无效");
                        }

                        var wallet = db.Wallet.FirstOrDefault(m => m.Account == account);
                        if (wallet == null)
                        {
                            throw new Exception($"账户“{account}”不存在");
                        }

                        log.LogJson(postData);
                        currency = currency.ToUpper();

                        var signResult = Helper.Sign(postData, wallet.Secret);
                        if (signResult != sign)
                        {
                            throw new Exception("签名校验失败");
                        }

                        var newTran = new DBModels.Transaction {
                            Amount     = amount,
                            NotifyUrl  = notifyUrl,
                            OutTradeNo = outTradeNo
                        };

                        //根据币种创建ICyptoCoinClient
                        var client = Activator.CreateInstance(typeof(ApiController).Assembly.GetType($"Cailutong.CyptoCoinGateway.CyptoCoinPlatform.Impls.{currency}.{currency}_Client")) as CyptoCoinPlatform.ICyptoCoinClient;
                        if (client == null)
                        {
                            throw new Exception("不支持" + currency);
                        }

                        //填充交易里面的付款地址
                        transactionGetCyptoCoinAddress(db, account, currency, client, newTran);
                        newTran.WalletId = wallet.id;
                        db.Insert(newTran);

                        return(Helper.SignResult(new
                        {
                            status = "success",
                            outTradeNo = outTradeNo,
                            targetAddress = newTran.CyptoCoinAddress
                        }, wallet.Secret));
                    }
                    catch (Exception ex)
                    {
                        log.Log(ex.ToString());
                        return(new
                        {
                            status = "error",
                            errMsg = ex.Message
                        });
                    }
                }
        }