コード例 #1
0
        public IEnumerator ApplyOrderSerial(Coroutine coroutine,
                                            ActivityCharacterProxy _this,
                                            ApplyOrderSerialInMessage msg)
        {
            var proxy = (ActivityProxy)_this;

            PlayerLog.WriteLog(proxy.CharacterId, "----------Activity----------ApplyOrderSerial----------:{0}",
                               msg.Request.Msg.GoodId);

            return(InAppPurchase.ApplyOrderSerial(coroutine, _this.Service, msg));
        }
コード例 #2
0
 public static IEnumerator ApplyOrderSerial(Coroutine coroutine,
                                            ActivityService _this,
                                            ApplyOrderSerialInMessage msg)
 {
     return(mImpl.ApplyOrderSerial(coroutine, _this, msg));
 }
コード例 #3
0
        public IEnumerator ApplyOrderSerial(Coroutine coroutine, ActivityService _this, ApplyOrderSerialInMessage msg)
        {
            var inMsg = msg.Request.Msg;
            var table = Table.GetRecharge(inMsg.GoodId);

            RechargeLogger.Info("ApplyOrderSerial Request GoodId:{0} Channel:{1} ExtInfo:{2} CharacterId:{3},step 1 ",
                                inMsg.GoodId, inMsg.Channel, inMsg.ExtInfo, msg.CharacterId);
            if (table == null)
            {
                Logger.Error("ApplyOrderSerial tableid : {0} does not exists in RechargeTable!!!", inMsg.GoodId);
                msg.Reply((int)ErrorCodes.Error_GoodId_Not_Exist);
                yield break;
            }

            var __this = (ActivityServerControl)_this;

            var infos = inMsg.Channel.Split('.');

            if (infos.Length <= 1)
            {
                msg.Reply((int)ErrorCodes.Unknow);
                yield break;
            }

            var    platform = infos[0];
            var    channel  = infos[1];
            string guid;
            string extinfo = inMsg.ExtInfo;

            if (channel.Equals("moe"))
            {
                const string apikey   = "mayakey";
                var          extInfos = inMsg.ExtInfo.Split('.');


                //var bytes = BitConverter.GetBytes(++__this.udidSeed);
                //guid = Convert.ToBase64String(bytes);
                guid = (++__this.udidSeed).ToString();

                var sb = new StringBuilder();
                sb.Append(guid);
                sb.Append('|');
                sb.Append("nouse");
                sb.Append('|');
                sb.Append(apikey);
                var sign = Shared.RequestManager.Encrypt_MD5_UTF8(sb.ToString());

                var dic = new Dictionary <string, string>();
                dic.Add("cporder", guid);
                dic.Add("data", "nouse");
                dic.Add("notifyurl", __this.PayServerNotifyAddress);
                dic.Add("verifyurl", __this.PayServerVerifyAddress);
                dic.Add("sign", sign);

                var url    = string.Format(@"http://sdk.uborm.com:40000/{0}/{1}/SaveOrder/", extInfos[0], extInfos[1]);
                var result = AsyncReturnValue <string> .Create();

                yield return(((ActivityServerControl)_this).WebRequestManager.DoRequest(coroutine, url, dic, result));

                if (string.IsNullOrEmpty(result.Value))
                {
                    Logger.Error("ApplyOrderSerial get webResponse is null.");
                    msg.Reply((int)ErrorCodes.Error_GoodId_Not_Exist);
                    yield break;
                }

                var jsonResult = (JObject)JsonConvert.DeserializeObject(result.Value);
                var resultCode = jsonResult["code"].ToString();
                var resultDesc = jsonResult["msg"].ToString();

                if (!resultCode.Equals("0"))
                {
                    Logger.Error("ApplyOrderSerial resultCode is." + resultCode + "Desc:" + resultDesc);
                    msg.Reply((int)ErrorCodes.Error_GoodId_Not_Exist);
                    yield break;
                }

                JObject joObject = new JObject();
                joObject["code"]    = 0;
                joObject["msg"]     = "OK";
                joObject["id"]      = extInfos[2];
                joObject["cporder"] = guid;
                joObject["order"]   = jsonResult["cporder"];
                var price = table.Price * 100;
                joObject["amount"]       = price.ToString();
                joObject["createtime"]   = jsonResult["orderdate"];
                joObject["Itemid"]       = "";
                joObject["Itemquantity"] = 1;
                joObject["status"]       = 1;
                joObject["info"]         = "";

                var bytes = System.Text.Encoding.Default.GetBytes(joObject.ToString());
                extinfo = Convert.ToBase64String(bytes);
            }
            else
            {
                guid = Guid.NewGuid().ToString("N");
            }

            var tempType = table.Type;

            if (tempType == 3)
            {
                tempType = tempType * 1000 + table.Id;
            }

            var order = new PreOrder
            {
                Amount   = table.Price,
                Channel  = inMsg.Channel,
                OrderId  = guid,
                ExtInfo  = extinfo,
                PayType  = (short)tempType,
                Uid      = msg.ClientId,
                PlayerId = msg.CharacterId
            };


            // var ret = InAppPurchase.PayDbConnection.NewPreOrder(order);


            var orderData = new ConnectData
            {
                preOrder    = order,
                connect     = InAppPurchase.PayDbConnection,
                returnValue = ePayDbReturn.Exception,
                mType       = ConnectDataType.PushData
            };


            yield return(__this.payDbManagerManager.DoOrder(coroutine, orderData));

            var ret = orderData.returnValue;

            if (ret != ePayDbReturn.Success)
            {
                RechargeLogger.Fatal("ApplyOrderSerial NewPreOrder to sql failed, ret :{0} guid:{1}", ret, guid);

                Logger.Fatal("ApplyOrderSerial NewPreOrder to sql failed, ret :{0}",
                             Enum.GetName(typeof(ePayDbReturn), ret));

                msg.Reply((int)ErrorCodes.Error_GoodId_Not_Exist);
                yield break;
            }

            RechargeLogger.Info("ApplyOrderSerial NewPreOrder to db success orderid:{0} CharacterId:{1},step 3 ", guid,
                                msg.CharacterId);


            if (inMsg.Channel.Equals("ios.appstore"))
            {
                msg.Response = new OrderSerialData {
                    OrderId = table.GoodsId
                };
            }
            else
            {
                msg.Response = new OrderSerialData {
                    OrderId = guid
                };
            }

            msg.Reply();
        }