예제 #1
0
        /// <summary>
        /// 查询用户余额
        /// author:陶林辉
        /// </summary>
        /// <param name="userId"></param>
        /// <returns>余额,可兑出</returns>
        public UserBalanceDto AcquireBalance(long userId)
        {
            BalanceReuqest Balance = new BalanceReuqest
            {
                FuserId = userId.ToString()
            };
            ZhangYuRequest Request = new ZhangYuRequest();

            Request.AppKey = _options.Value.AppKey;
            Request.Data   = _sys.Base64Encode(Encoding.UTF8, JsonHelper.SerializeObject(Balance));
            Request.Sign   = _sys.Sha512Encode($"{Request.AppKey}{_options.Value.AppSecret}{Request.Data}{Request.Nonce}{Request.Timestamp}");
            string strUrl  = string.Format(_options.Value.Url, "v1", "balance");
            string strJson = JsonHelper.SerializeObject(Request);

            _log.Info($"查询用户余额请求参数{strJson}");
            var response = JsonHelper.DeserializeJsonToObject <ZhangYuResponse>(_sys.PostJsonData(strUrl, strJson, Encoding.UTF8));

            _log.Info($"查询用户余额返回值{ JsonHelper.SerializeObject(response)}");
            if (response.Code == "0")
            {
                var vResult = JsonHelper.DeserializeJsonToObject <UserBalanceDto>(_sys.Base64Decode(response.Data));
                return(vResult);
            }
            return(null);
        }
예제 #2
0
        /// <summary>
        /// 商品兑换
        /// author:白尚德
        /// </summary>
        /// <param name="exchange"></param>
        /// <returns></returns>
        public async Task <bool> Exchange_php(ExchangeDto exchange)
        {
            PHPRequest Request = new PHPRequest
            {
                AppKey = _options.Value.AppKey,
                Data   = _sys.Base64Encode(Encoding.UTF8, JsonHelper.SerializeObject(exchange))
            };

            Request.Sign = _sys.Sha512Encode($"{Request.AppKey}{_options.Value.AppSecret}{Request.Data}{Request.Nonce}{Request.Timestamp}");
            string strJson = JsonHelper.SerializeObject(Request);
            string strUrl  = string.Format(_options.Value.Url, "v1", "exchange");

            _log.Info($"商品兑换请求参数_php{strJson}");
            var response = JsonHelper.DeserializeJsonToObject <PHPResponse>(_sys.PostJsonData(strUrl, strJson, Encoding.UTF8));
            var result   = JsonHelper.DeserializeJsonToObject <CostStatusResult>(_sys.Base64Decode(response.Data));

            _log.Info($"商品兑换返回值_php{JsonHelper.SerializeObject(response)}");
            if (result.code == 0)
            {
                UserExchangeDto temp = new UserExchangeDto
                {
                    Amount     = exchange.Amount,
                    CreateTime = DateTime.Now,
                    Name       = exchange.Name,
                    OrderId    = exchange.ForderId,
                    UserId     = long.Parse(exchange.FuserId),
                    Price      = exchange.Price,
                    Quantity   = exchange.Quantity,
                    Status     = 0 //0正常,1退款
                };
                var entity = _mapper.Map <UserExchangeDto, UserExchangeEntity>(temp);
                _context.Exchange.Add(entity);
                await _context.SaveChangesAsync();

                return(true);
            }
            return(false);
        }