public static void buy(int money_type) { BuyGoodsPanelScript script = OtherData.s_buyGoodsPanelScript; BuyGoodsRequest buyGoodsRequest = LogicEnginerScript.Instance.GetComponent <BuyGoodsRequest>(); int totalPrice = 0; if (money_type == script.m_shopData.money_type) { totalPrice = script.m_shopData.price * script.m_goods_num; } else if (money_type == script.m_shopData.money_type2) { totalPrice = script.m_shopData.price2 * script.m_goods_num; } switch (money_type) { case 1: if (UserData.gold < totalPrice) { ToastScript.createToast("金币不足,请前去充值"); return; } else { buyGoodsRequest.setGoodsInfo(script.m_shopData.goods_id, script.m_goods_num, money_type); buyGoodsRequest.CallBack = script.onReceive_BuyGoods; buyGoodsRequest.OnRequest(); } break; case 2: if (UserData.yuanbao < totalPrice) { ToastScript.createToast("元宝不足,请前去充值"); return; } else { buyGoodsRequest.setGoodsInfo(script.m_shopData.goods_id, script.m_goods_num, money_type); buyGoodsRequest.CallBack = script.onReceive_BuyGoods; buyGoodsRequest.OnRequest(); } break; //人民币购买 case 3: if (!OtherData.s_canRecharge) { ToastScript.createToast("元宝购买暂未开放,敬请期待"); return; } if (UserData.IsRealName) { // ios if (OtherData.s_channelName.CompareTo("ios") == 0) { PlatformHelper.pay(PlatformHelper.GetChannelName(), "AndroidCallBack", "GetPayResult", script.SetRequest(script.m_shopData)); } // 渠道包 else if (AndroidPlatform.isShield(OtherData.s_channelName)) { if (!ChannelHelper.Is3RdLogin()) { PayTypePanelScript.create(script.m_shopData); } else { PlatformHelper.pay(PlatformHelper.GetChannelName(), "AndroidCallBack", "GetPayResult", script.SetRequest(script.m_shopData)); } } // 官方包 else { PayTypePanelScript.create(script.m_shopData); } GameObject.Destroy(script.gameObject); } else { // 部分渠道不需要做实名限制 if (ShieldShopRealName.isShield(OtherData.s_channelName)) { // ios if (OtherData.s_channelName.CompareTo("ios") == 0) { PlatformHelper.pay(PlatformHelper.GetChannelName(), "AndroidCallBack", "GetPayResult", script.SetRequest(script.m_shopData)); } // 渠道包 else if (AndroidPlatform.isShield(OtherData.s_channelName)) { if (!ChannelHelper.Is3RdLogin()) { PayTypePanelScript.create(script.m_shopData); } else { PlatformHelper.pay(PlatformHelper.GetChannelName(), "AndroidCallBack", "GetPayResult", script.SetRequest(script.m_shopData)); } } // 官方包 else { PayTypePanelScript.create(script.m_shopData); } GameObject.Destroy(script.gameObject); } else { CommonExitPanelScript commonExit = CommonExitPanelScript.create().GetComponent <CommonExitPanelScript>(); commonExit.TextContent.text = "您还未实名,无法购买"; commonExit.ButtonClose.gameObject.SetActive(true); commonExit.ButtonConfirm.onClick.AddListener(delegate() { RealNameScript.create(); GameObject.Destroy(commonExit.gameObject); }); } } break; case 4: if (UserData.medal < totalPrice) { ToastScript.createToast("徽章不足,无法购买"); return; } else { buyGoodsRequest.setGoodsInfo(script.m_shopData.goods_id, script.m_goods_num, money_type); buyGoodsRequest.CallBack = script.onReceive_BuyGoods; buyGoodsRequest.OnRequest(); } break; } }
private void NewOrder(UserNote note) { UserSession user = note.Session; Variant v = note.GetVariant(0); string vs = JsonConvert.SerializeObject(v); //LogWrapper.Warn("请求:" + vs); BuyGoodsRequest request = new BuyGoodsRequest(); string meta = v.GetStringOrDefault("goodsmeta"); request.goodsmeta = Convert.ToBase64String(Encoding.UTF8.GetBytes(meta)); request.goodsurl = v.GetStringOrDefault("goodsurl"); request.openid = user.UserID.PadLeft(32, '0'); request.openkey = user.key; request.payitem = v.GetStringOrDefault("payitem"); request.pf = v.GetStringOrDefault("platform") ?? v.GetStringOrDefault("pf"); request.pfkey = v.GetStringOrDefault("pfkey"); request.appmode = v.GetIntOrDefault("appmode", 2); request.device = v.GetIntOrDefault("device"); request.zoneid = ServerLogger.zoneid; string host = ServerManager.BuyHost; string uri = ServerManager.BuyUri; StringBuilder sb = new StringBuilder(512); string quest = request.Build(sb, null).ToString(); string sign = AppSign.Sign(uri, quest); sb.Clear(); sb.Append(uri + "?"); request.Build(sb, UrlUtility.UrlEncode); sb.Append("&sig="); sb.Append(sign); HttpArgs a = new HttpArgs(); a.Host = host; a.Url = sb.ToString(); //LogWrapper.Warn("请求Url:" + a.Url); IPEndPoint ipadd = IPHelper.CreateEndPoint(host, 443); byte[] bin = SslHttpClient.Get(ipadd, a, null); string result = Encoding.UTF8.GetString(bin); Variant re = JsonConvert.DeserializeObject<Variant>(result); if (re.GetIntOrDefault("ret", -1) == 0) { string token = re.GetStringOrDefault("token"); if (!string.IsNullOrEmpty(token)) { if (CreateOrder(note.Player, token)) { user.Call(MallCommand.NewTokenR, true, re); return; } } } user.Call(MallCommand.NewTokenR, false, re); //LogWrapper.Warn("请求结果:" + result); }
static void TestSign() { var v = Encoding.GetEncoding(936); string meta = Convert.ToBase64String(Encoding.GetEncoding(936).GetBytes("10枚晶币*每10Q点可以兑换10枚晶币,祝您游戏愉快,谢谢您的支持!")); BuyGoodsRequest request = new BuyGoodsRequest(); request.appmode = 2; request.device = 0; request.goodsmeta = meta; request.goodsurl = "http://ww.com.cn/test.png"; request.openid = "00000000000000000000000000441794"; request.openkey = "8EABE7C3586EA666327DFA1A2A38F088"; request.payitem = "x*100*1"; request.pf = "pengyou"; request.pfkey = "7cbfc07c376f92b07e3bce209ee1ed47"; request.zoneid = 5; const string host = "119.147.19.43"; const string uri = "/v3/pay/buy_goods"; StringBuilder sb = new StringBuilder(1000); string quest = request.Build(sb, null).ToString(); string sign = AppSign.Sign(uri, quest); LogWrapper.Warn("签名源:" + quest); LogWrapper.Warn("签名结果:" + sign); sb.Clear(); sb.Append(uri + "?"); request.Build(sb); sb.Append("&sig="); sb.Append(sign); string xd = request.ToString(); string result2 = "https://" + host + sb.ToString(); Console.WriteLine(result2); HttpArgs a = new HttpArgs(); a.Host = host; a.Url = sb.ToString(); LogWrapper.Warn("请求内容:" + a.Url); IPEndPoint ipadd = new IPEndPoint(IPAddress.Parse(host), 443); byte[] bin = SslHttpClient.Get(ipadd, a, null); string result = Encoding.UTF8.GetString(bin); Console.WriteLine(result); LogWrapper.Warn("请求结果:" + result); }