protected string encodePayParams(PayParams data) { Dictionary <string, object> map = new Dictionary <string, object>(); map.Add("productId", data.productId); map.Add("productName", data.productName); map.Add("productDesc", data.productDesc); map.Add("price", data.price); map.Add("ratio", data.ratio); map.Add("buyNum", data.buyNum); map.Add("coinNum", data.coinNum); map.Add("serverId", data.serverId); map.Add("serverName", data.serverName); map.Add("roleId", data.roleId); map.Add("roleName", data.roleName); map.Add("roleLevel", data.roleLevel); map.Add("payNotifyUrl", data.payNotifyUrl); map.Add("vip", data.vip); map.Add("extension", data.extension); map.Add("union", data.union); map.Add("gameSign", data.gameSign); map.Add("gameGuid", data.gameGuid); return(MiniJSON.Json.Serialize(map)); }
protected bool Check(IDictionary <string, string> dict, string fieldName) { dict.TryGetValue(fieldName, out var result); var param = PayParams.GetValue(fieldName); return(result != null && param != null && result == param); }
//去 Server获取游戏订单号,这里逻辑是访问游戏服务器,然后游戏服务器去 Server获取订单号 //并返回 public PayParams reqOrder(PayParams data) { //TODO 去游戏服务器获取订单号 //测试 data.extension = "test111"; return(data); }
public override void Pay(PayParams data) { string text = this.encodePayParams(data); this.SDKCall("pay", new object[] { text }); }
protected override void AddBizParams() { PayParams .SafeAdd("body", m_PayRequest.Order.Description) .SafeAdd("out_trade_no", m_PayRequest.Order.OrderId) .SafeAdd("total_fee", m_PayRequest.Order.Amount.ToString()) .SafeAdd("spbill_create_ip", m_PayRequest.ClientIp) .SafeAdd("notify_url", m_PayRequest.NotifyUrl) .SafeAdd("trade_type", GetTradeType(m_PayRequest.TradeType)) .SafeAdd("product_id", m_PayRequest.Order.ProductId); }
protected override void InitParams() { PayParams.Clear(); PayParams .SafeAdd("mch_id", m_Merchant.Id) .SafeAdd("nonce_str", GenerateNonceString()); var sign = PayParams.ToSortDict().WechatSign(m_Merchant.ApiSecret); PayParams.SafeAdd("sign", sign); }
public override async Task <T> PostAsync() { InitParams(); var xmlData = PayParams.ToSortDict().ToXml(); var xmlResult = await Util.PostAsync(PostUrl, xmlData); var resultDict = xmlResult.ToSortDict(); var response = ParseResult(resultDict); return(response); }
static int OrderAndPay(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); SDKInterface obj = (SDKInterface)ToLua.CheckObject <SDKInterface>(L, 1); PayParams arg0 = (PayParams)ToLua.CheckObject <PayParams>(L, 2); obj.OrderAndPay(arg0); return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
protected virtual void InitParams() { PayParams.Clear(); PayParams .SafeAdd("appid", m_Merchant.AppId) .SafeAdd("mch_id", m_Merchant.Id) .SafeAdd("nonce_str", GenerateNonceString()); AddBizParams(); var sign = PayParams.ToSortDict().WechatSign(m_Merchant.SignKey); PayParams.SafeAdd("sign", sign); }
static int reqOrder(IntPtr L) { try { ToLua.CheckArgsCount(L, 2); SDKInterface obj = (SDKInterface)ToLua.CheckObject <SDKInterface>(L, 1); PayParams arg0 = (PayParams)ToLua.CheckObject <PayParams>(L, 2); PayParams o = obj.reqOrder(arg0); ToLua.PushObject(L, o); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
static int set_roleLevel(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); PayParams obj = (PayParams)o; int arg0 = (int)LuaDLL.luaL_checknumber(L, 2); obj.roleLevel = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index roleLevel on a nil value")); } }
static int get_roleLevel(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); PayParams obj = (PayParams)o; int ret = obj.roleLevel; LuaDLL.lua_pushinteger(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index roleLevel on a nil value")); } }
static int get_productDesc(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); PayParams obj = (PayParams)o; string ret = obj.productDesc; LuaDLL.lua_pushstring(L, ret); return(1); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index productDesc on a nil value")); } }
static int set_gameGuid(IntPtr L) { object o = null; try { o = ToLua.ToObject(L, 1); PayParams obj = (PayParams)o; string arg0 = ToLua.CheckString(L, 2); obj.gameGuid = arg0; return(0); } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e, o, "attempt to index gameGuid on a nil value")); } }
private static int Pay(IntPtr L) { int result; try { ToLua.CheckArgsCount(L, 2); SDKInterface sDKInterface = (SDKInterface)ToLua.CheckObject(L, 1, typeof(SDKInterface)); PayParams data = (PayParams)ToLua.CheckObject(L, 2, typeof(PayParams)); sDKInterface.Pay(data); result = 0; } catch (Exception e) { result = LuaDLL.toluaL_exception(L, e, null); } return(result); }
public override void Pay(PayParams data) { Dictionary <string, object> map = new Dictionary <string, object>(); map.Add("buyNum", data.buyNum); map.Add("coinNum", data.coinNum); map.Add("price", data.price); map.Add("productId", data.productId); map.Add("productName", data.productName); map.Add("productDesc", data.productDesc); map.Add("roleId", data.roleId); map.Add("roleName", data.roleName); map.Add("roleLevel", data.roleLevel); map.Add("serverId", data.serverId); map.Add("serverName", data.serverName); map.Add("vip", data.vip); map.Add("extension", data.extension); string json = MiniJSON.Json.Serialize(map); pay(json); }
static int _CreatePayParams(IntPtr L) { try { int count = LuaDLL.lua_gettop(L); if (count == 0) { PayParams obj = new PayParams(); ToLua.PushObject(L, obj); return(1); } else { return(LuaDLL.luaL_throw(L, "invalid arguments to ctor method: PayParams.New")); } } catch (Exception e) { return(LuaDLL.toluaL_exception(L, e)); } }
public PayParams reqOrder(PayParams data) { data.orderID = "345435634534"; data.extension = "test111"; return(data); }
/// <summary> /// 准备支付,请求支付数据 /// </summary> /// <param name="userId"></param> /// <param name="input"></param> /// <returns></returns> public async Task <AppPrepayDto> Prepay(string userId, OrderPrepayInput input) { using var locker = Locker.Lock(Lockers.PrepayOrderGetPayData.Format(input.PrepayOrderSn), 3); var order = await DbContext.Set <PrepayOrders>() .FirstOrDefaultAsync(o => o.Sn == input.PrepayOrderSn && o.UserId == userId); if (order == null) { throw new Exception("订单不存在"); } if (order.Status != PrepayOrderStatus.Waiting) { throw new Exception("订单状态错误"); } var now = DateTime.Now.GetLongDate(); var mch = MchOptions.GetByName(order.MchName, input.Channel.Convert2Type()); if (mch == null) { throw new Exception("channel 参数错误"); } var dataProvider = ServiceProvider.GetServices <IPrepayOrderDataProvider>() .SingleOrDefault(p => p.SourceType == order.SourceType); if (dataProvider == null) { throw new Exception("无效来源或者来源没有数据提供"); } var canpay = await dataProvider.CanPay(userId.ParseTo <int>(), order.SourceSn); if (!canpay.canPay) { throw new Exception(canpay.errorReason ?? "订单异常"); } var cacheKey = prepayCacheKey.Format(order.Id, input.Channel, input.AppId, mch.MchId); // 缓存中查看有没有支付对应的支付数据,有就直接返回,没有就调用对应的支付通道并获取 var prepayData = await DistributedCache.GetObjectWithJsonAsync <PrepayData>(cacheKey); if (prepayData == null) { var oldLocalTradeNo = order.CurrentPayLocalTradeNo; var newLocalTradeNo = Guid.NewGuid().ToString("n"); var payParams = new PayParams() { OrderId = order.Id, OrderSn = order.Sn, LocalTradeNo = newLocalTradeNo, Amount = order.PayAmount, Title = order.Title, Attach = order.Attach, ClientIp = input.ClientIp, TraderId = input.TraderId, RedirectUrl = input.RedirectUrl, Channel = input.Channel, MchId = mch.MchId, AppId = input.AppId }; var payment = Payments.FirstOrDefault(r => r.Channel == input.Channel); if (payment == null) { throw new Exception("无效的支付方式"); } if (!oldLocalTradeNo.IsNullOrWhiteSpace()) { try { // 每次请求新的支付数据时,都将旧的预付单关闭掉,避免重复支付 await payment.CloseOrder(input.AppId, mch.MchId, oldLocalTradeNo); } catch { // ignored } } order.CurrentPayLocalTradeNo = newLocalTradeNo; prepayData = await payment.GetPrepayData(payParams); await DistributedCache.SetObjectWithJsonAsync(cacheKey, prepayData, DateTimeOffset.Now.AddHours(1)); } try { var result = new AppPrepayDto { PayData = prepayData.PayData }; order.PayChannel = input.Channel; order.PrepayOriginData = prepayData.PrepayOriginData; order.MchId = mch.MchId; order.LastPrepayTime = now; order.AppId = input.AppId; await DbContext.SaveChangesAsync(); return(result); } catch (Exception e) { throw new Exception("支付数据生成失败", e); } }
/*public override void Pay(PayParams data) * { * throw new NotImplementedException(); * }*/ public override void OrderAndPay(PayParams data) { throw new NotImplementedException(); }
//调用SDK支付界面 //public abstract void Pay(PayParams data); //调用SDK支付界面 public abstract void OrderAndPay(PayParams data);
/*public override void Pay( PayParams data) * { * string json = encodePayParams(data); * SDKCall("pay", json); * }*/ public override void OrderAndPay(PayParams data) { string json = encodePayParams(data); SDKCall("orderAndPay", json); }
public abstract void Pay(PayParams data);
protected override void AddBizParams() { PayParams .SafeAdd("out_trade_no", m_PayRequest.Order.OrderId); }
private string encodePayParams(PayParams data) { return(Json.Serialize(new Dictionary <string, object> { { "productId", data.productId }, { "productName", data.productName }, { "productDesc", data.productDesc }, { "price", data.price }, { "buyNum", data.buyNum }, { "coinNum", data.coinNum }, { "serverId", data.serverId }, { "serverName", data.serverName }, { "roleId", data.roleId }, { "roleName", data.roleName }, { "roleLevel", data.roleLevel }, { "vip", data.vip }, { "orderID", data.orderID }, { "extension", data.extension } })); }
public override void OrderAndPay(PayParams data) { string json = encodePayParams(data); SDK_Pay(json); }