/// <summary> /// 海峡竞技消费PHP /// </summary> /// <param name="consume"></param> /// <returns></returns> public async Task <bool> Consume_php(ConsumeDto consume) { ConsumePhpDto consumephp = new ConsumePhpDto { GameKey = _phpoptions.Value.gameKey, GameSetId = consume.forderId, OrderId = consume.forderId, UserId = consume.fuserId, Amount = consume.amount, OperateTime = Convert.ToInt64(DateTime.Now.ToOADate()), Description = consume.description }; PHPRequest Request = new PHPRequest(); Request.AppKey = _phpoptions.Value.appKey; Request.Data = _sys.Base64Encode(Encoding.UTF8, JsonHelper.SerializeObject(consumephp)); Request.Sign = _sys.Sha512Encode($"{Request.AppKey}{_phpoptions.Value.secret}{Request.Data}{Request.Nonce}{Request.Timestamp}"); string strJson = JsonHelper.SerializeObject(Request); string strUrl = string.Format(_phpoptions.Value.url, "v1", "haixiaBet"); _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 = consume.amount, CreateTime = DateTime.Now, Name = consume.description, OrderId = consume.forderId, UserId = long.Parse(consume.fuserId), Price = consume.amount, Quantity = 1, Status = 0 //0正常,1退款 }; var entity = _mapper.Map <UserExchangeDto, UserExchangeEntity>(temp); _context.Exchange.Add(entity); await _context.SaveChangesAsync(); return(true); } return(false); }
/// <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); }