Exemple #1
0
        /// <summary>
        /// 获取支付信息
        /// </summary>
        /// <param name="prepay_id"></param>
        /// <returns></returns>
        private string GetPayReqInfo(SDK_Weixin_Config config, string prepay_id)
        {
            //随机字符串
            string nonceStr = new Random(1).Next(0, 99999).ToString();

            //时间戳
            long timeStamp = MFDSAUtil.GetTimestamp();

            string package = "Sign=WXPay";

            string temp = string.Format("appid={0}&noncestr={1}&package={2}&partnerid={3}&prepayid={4}&timestamp={5}&key={6}",
                                        config.appid, nonceStr, package, config.mch_id, prepay_id, timeStamp, config.payKey);

            //签名
            string sign = MFEncryptUtil.Md5(temp).ToUpper(); //签名是MD5大写形式

            JsonData data = new JsonData();

            data["partnerId"] = config.mch_id; //商户号
            data["prepayId"]  = prepay_id;     //统一下单编号
            data["nonceStr"]  = nonceStr;      //随机字符串
            data["timeStamp"] = timeStamp;     //时间戳
            data["package"]   = package;       //
            data["sign"]      = sign;          //签名

            return(JsonMapper.ToJson(data));
        }
    /// <summary>
    /// 玩家注册
    /// </summary>
    /// <param name="userName"></param>
    /// <param name="pwd"></param>
    /// <param name="channelId">渠道号</param>
    /// <returns></returns>
    public MFReturnValue <int> Register(string userName, string pwd, string channelId, string deviceIdentifier, string deviceModel)
    {
        MFReturnValue <int> retValue = new MFReturnValue <int>();

        //1、验证用户名是否存在

        //2、如果不存在添加数据

        using (SqlConnection conn = new SqlConnection(DBConn.DBAccount))
        {
            conn.Open();

            //开始事物的目的,只打开一次数据库
            SqlTransaction trans = conn.BeginTransaction();

            List <AccountEntity> lst = GetListWithTran(this.TableName, "Id", "UserName='******'", trans: trans, isAutoStatus: false);

            if (lst == null || lst.Count == 0)
            {
                //说明用户不存在
                AccountEntity entity = new AccountEntity();
                entity.Status              = EnumEntityStatus.Released;
                entity.UserName            = userName;
                entity.Pwd                 = MFEncryptUtil.Md5(pwd);
                entity.ChannelId           = channelId;
                entity.LastLogOnServerTime = DateTime.Now;
                entity.CreateTime          = DateTime.Now;
                entity.UpdateTime          = DateTime.Now;
                entity.DeviceIdentifier    = deviceIdentifier;
                entity.DeviceModel         = deviceModel;

                MFReturnValue <object> ret = this.Create(trans, entity);

                if (!ret.HasError)
                {
                    retValue.Value = (int)ret.OutputValues["Id"];
                    trans.Commit();
                }
                else
                {
                    retValue.HasError = true;
                    retValue.Message  = "用户名已经存在";
                    trans.Rollback();
                }
            }
            else
            {
                //说明存在
                retValue.HasError = true;
                retValue.Message  = "用户名已经存在";
            }
        };

        return(retValue);
    }
Exemple #3
0
        public RetValue Post([FromBody] string jsonStr)
        {
            RetValue ret = new RetValue();

            JsonData jsonData = JsonMapper.ToObject(jsonStr);

            //时间戳
            long   t = Convert.ToInt64(jsonData["t"].ToString());
            string deviceIdentifier = jsonData["deviceIdentifier"].ToString();
            string deviceModel      = jsonData["deviceModel"].ToString();
            string sign             = jsonData["sign"].ToString();

            //1.判断时间戳 如果大于3秒 直接返回错误
            if (MFDSAUtil.GetTimestamp() - t > 3)
            {
                ret.HasError  = true;
                ret.ErrorCode = 1002; //"请求无效";
                return(ret);
            }

            //2.验证签名
            string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier));

            if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase))
            {
                ret.HasError  = true;
                ret.ErrorCode = 1002; //"请求无效";
                return(ret);
            }

            string sdkName    = jsonData["SDKName"].ToString();
            string actionName = jsonData["ActionName"].ToString();
            string userData   = jsonData["UserData"].ToString();

            IChannelSDK sdk = null;

            m_SDKDic.TryGetValue(sdkName, out sdk);
            if (sdk == null)
            {
                Type m_SdkType = Type.GetType(string.Format("WebAccount.Models.SDK.{0}", sdkName));
                sdk = Activator.CreateInstance(m_SdkType) as IChannelSDK;
                m_SDKDic[sdkName] = sdk;
            }

            return(sdk.DoAction(actionName, userData, new string[] { deviceIdentifier, deviceModel }));
        }
Exemple #4
0
        /// <summary>
        /// 获取统一下单
        /// </summary>
        /// <param name="userData"></param>
        /// <returns></returns>
        private RetValue GetPrepayId(string userData)
        {
            JsonData data = JsonMapper.ToObject(userData);

            short             channelId = data["ChannelId"].ToString().ToShort();
            SDK_Weixin_Config config    = GetWeixinConfig(channelId);

            string rechargeProductId = data["RechargeProductId"].ToString();
            string orderId           = data["OrderId"].ToString();

            //产品说明
            string body = "充值产品";

            //随机字符串
            string nonce_str = new Random().Next(0, 99999).ToString();

            //商户订单号
            string out_trade_no = DateTime.Now.ToString("yyyyMMddHHmmssfff");

            //终端IP
            string spbill_create_ip = MFSystemUtil.GetIP();


            //总金额 订单总金额,单位为分
            int total_fee = RechargeShopDBModel.Instance.Get(int.Parse(rechargeProductId)).Price * 100;

            total_fee = 1; //临时改成1分

            //交易类型
            string trade_type = @"APP";

            string attach = string.Format("{0}^{1}", channelId, orderId);

            string temp = string.Format("appid={0}&attach={1}&body={2}&mch_id={3}&nonce_str={4}&notify_url={5}&out_trade_no={6}&spbill_create_ip={7}&total_fee={8}&trade_type={9}&key={10}", config.appid, attach, body, config.mch_id, nonce_str, config.notify_url, out_trade_no, spbill_create_ip, total_fee, trade_type, config.payKey);

            string sign = MFEncryptUtil.Md5(temp).ToUpper(); //签名是MD5大写形式

            string urlString = "https://api.mch.weixin.qq.com/pay/unifiedorder";

            StringBuilder sbr = new StringBuilder();

            sbr.Append("<xml>");
            sbr.AppendFormat("<appid><![CDATA[{0}]]></appid>", config.appid);
            sbr.AppendFormat("<attach><![CDATA[{0}]]></attach>", attach);
            sbr.AppendFormat("<body><![CDATA[{0}]]></body>", body);
            sbr.AppendFormat("<mch_id><![CDATA[{0}]]></mch_id>", config.mch_id);
            sbr.AppendFormat("<nonce_str><![CDATA[{0}]]></nonce_str>", nonce_str);
            sbr.AppendFormat("<out_trade_no><![CDATA[{0}]]></out_trade_no>", out_trade_no);
            sbr.AppendFormat("<spbill_create_ip><![CDATA[{0}]]></spbill_create_ip>", spbill_create_ip);
            sbr.AppendFormat("<total_fee><![CDATA[{0}]]></total_fee>", total_fee);
            sbr.AppendFormat("<trade_type><![CDATA[{0}]]></trade_type>", trade_type);
            sbr.AppendFormat("<notify_url><![CDATA[{0}]]></notify_url>", config.notify_url);
            sbr.AppendFormat("<sign><![CDATA[{0}]]></sign>", sign);
            sbr.Append("</xml>");

            string resposeContent = NetWorkHttp.Instance.HttpPost(urlString, sbr.ToString());

            RetValue retValue = new RetValue();

            XDocument doc = XDocument.Parse(resposeContent);

            XElement rootElement = doc.Root;

            string return_code = rootElement.Element("return_code").Value;

            if (return_code.Equals("SUCCESS", StringComparison.CurrentCultureIgnoreCase))
            {
                string prepay_id = rootElement.Element("prepay_id").Value;
                retValue.Value = GetPayReqInfo(config, prepay_id);
            }
            else
            {
                retValue.HasError = true;
            }
            return(retValue);
        }
        // POST: api/GameServer
        public object Post([FromBody] string jsonStr)
        {
            RetValue ret = new RetValue();

            JsonData jsonData = JsonMapper.ToObject(jsonStr);

            //时间戳
            long   t = Convert.ToInt64(jsonData["t"].ToString());
            string deviceIdentifier = jsonData["deviceIdentifier"].ToString();
            string deviceModel      = jsonData["deviceModel"].ToString();
            string sign             = jsonData["sign"].ToString();

            //1.判断时间戳 如果大于3秒 直接返回错误
            if (MFDSAUtil.GetTimestamp() - t > 3)
            {
                ret.HasError  = true;
                ret.ErrorCode = ProtoCode.RequestDelay; //"请求无效";
                //return ret;
            }

            //2.验证签名
            string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier));

            if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase))
            {
                ret.HasError  = true;
                ret.ErrorCode = ProtoCode.SignatureInvalid; //"请求无效";
                return(ret);
            }

            int type = Convert.ToInt32(jsonData["Type"].ToString());

            if (type == 0)
            {
                string channelId    = jsonData["ChannelId"].ToString();
                string innerVersion = jsonData["InnerVersion"].ToString();

                //先获取渠道状态 根据渠道状态 来加载不同的区服
                ChannelEntity entity = ChannelCacheModel.Instance.GetEntity(string.Format("[ChannelId]={0} and [InnerVersion]={1}", channelId, innerVersion));
                if (entity == null)
                {
                    ret.HasError  = true;
                    ret.ErrorCode = ProtoCode.ChannelNumberNoExist; //"渠道号不存在";
                }

                //获取页签
                return(GameServerCacheModel.Instance.GetGameServerPageList(string.Format("[ChannelStatus]={0}", entity.ChannelStatus)));
            }
            else if (type == 1)
            {
                string channelId    = jsonData["ChannelId"].ToString();
                string innerVersion = jsonData["InnerVersion"].ToString();

                //先获取渠道状态 根据渠道状态 来加载不同的区服
                ChannelEntity entity = ChannelCacheModel.Instance.GetEntity(string.Format("[ChannelId]={0} and [InnerVersion]={1}", channelId, innerVersion));
                if (entity == null)
                {
                    ret.HasError  = true;
                    ret.ErrorCode = ProtoCode.ChannelNumberNoExist; //"渠道号不存在";
                }

                int pageIndex = int.Parse(jsonData["pageIndex"].ToString());
                //获取区服列表
                return(GameServerCacheModel.Instance.GetGameServerList(pageIndex, string.Format("[ChannelStatus]={0}", entity.ChannelStatus)));
            }
            else if (type == 2)
            {
                //更新最后登录信息
                int    userId         = int.Parse(jsonData["userId"].ToString());
                int    lastServerId   = int.Parse(jsonData["lastServerId"].ToString());
                string lastServerName = jsonData["lastServerName"].ToString();

                Dictionary <string, object> dic = new Dictionary <string, object>();
                dic["Id"] = userId;
                dic["LastLogOnServerId"]   = lastServerId;
                dic["LastLogOnServerName"] = lastServerName;
                dic["LastLogOnServerTime"] = DateTime.Now;

                AccountCacheModel.Instance.Update("LastLogOnServerId=@LastLogOnServerId, LastLogOnServerName=@LastLogOnServerName, LastLogOnServerTime=@LastLogOnServerTime", "Id=@Id", dic);
            }

            return(ret);
        }
    /// <summary>
    /// 玩家登录
    /// </summary>
    /// <param name="userName">用户名</param>
    /// <param name="pwd">密码</param>
    /// <returns></returns>
    public AccountEntity LogOn(string userName, string pwd, string deviceIdentifier, string deviceModel)
    {
        string        condition = string.Format("[UserName]='{0}' and [Pwd]='{1}'", userName, MFEncryptUtil.Md5(pwd));
        AccountEntity entity    = this.GetEntity(condition);

        if (entity != null)
        {
            entity.DeviceIdentifier = deviceIdentifier;
            entity.DeviceModel      = deviceModel;
            this.Update(entity);
        }
        return(entity);
    }
Exemple #7
0
        public RetValue Post([FromBody] string jsonStr)
        {
            RetValue ret = new RetValue();

            JsonData jsonData = JsonMapper.ToObject(jsonStr);

            //时间戳
            long   t = Convert.ToInt64(jsonData["t"].ToString());
            string deviceIdentifier = jsonData["deviceIdentifier"].ToString();
            string deviceModel      = jsonData["deviceModel"].ToString();
            string sign             = jsonData["sign"].ToString();

            //1.判断时间戳 如果大于3秒 直接返回错误
            if (MFDSAUtil.GetTimestamp() - t > 3)
            {
                ret.HasError = true;
                ret.ErrorMsg = "请求无效";
                return(ret);
            }

            //2.验证签名
            string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier));

            if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase))
            {
                ret.HasError = true;
                ret.ErrorMsg = "请求无效";
                return(ret);
            }

            //订单号 付费服务器识别码_玩家账号_要充值到哪个GameServerId_角色ID_充值的产品Id_时间
            string orderId = jsonData["orderId"].ToString();

            string[] arr = orderId.Split('_');
            if (arr.Length == 6)
            {
                //1.记录充值日志
                RechargeLogEntity rechargeLogEntity = new RechargeLogEntity();
                rechargeLogEntity.AccountId = arr[1].ToInt();
                string channelId = AccountCacheModel.Instance.GetEntity(rechargeLogEntity.AccountId).ChannelId;

                rechargeLogEntity.ChannelId         = channelId;
                rechargeLogEntity.GameServerId      = arr[2].ToInt();
                rechargeLogEntity.RoldId            = arr[3].ToInt();
                rechargeLogEntity.RechargeProductId = arr[4].ToString();
                rechargeLogEntity.OrderId           = orderId;
                rechargeLogEntity.CreateTime        = DateTime.Now;

                RechargeLogCacheModel.Instance.Create(rechargeLogEntity);


                //2.找到对应的游戏服
                int gameServerId = arr[2].ToInt();

                GameServerEntity entity = GameServerCacheModel.Instance.GetEntity(gameServerId);
                if (entity != null)
                {
                    //发送socket请求 给游戏服
                    Socket rechargeServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                    rechargeServer.Connect(new IPEndPoint(IPAddress.Parse(entity.Ip), entity.Port));
                    string str = string.Format("{0}_{1}_{2}", channelId, arr[3], arr[4]);
                    rechargeServer.Send(System.Text.UTF8Encoding.UTF8.GetBytes(str));
                }
                else
                {
                    ret.HasError = true;
                    ret.ErrorMsg = "充值失败";
                }
            }
            else
            {
                ret.HasError = true;
                ret.ErrorMsg = "充值失败";
            }
            return(ret);
        }
Exemple #8
0
        // POST: api/Account
        public RetValue Post([FromBody] string jsonStr)
        {
            RetValue ret = new RetValue();

            JsonData jsonData = JsonMapper.ToObject(jsonStr);

            //时间戳
            long   t = Convert.ToInt64(jsonData["t"].ToString());
            string deviceIdentifier = jsonData["deviceIdentifier"].ToString();
            string deviceModel      = jsonData["deviceModel"].ToString();
            string sign             = jsonData["sign"].ToString();

            //1.判断时间戳 如果大于3秒 直接返回错误
            if (MFDSAUtil.GetTimestamp() - t > 3)
            {
                ret.HasError = true;
                ret.ErrorMsg = "请求无效";
                return(ret);
            }

            ////  2.验证签名
            string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier));

            if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase))
            {
                ret.HasError = true;
                ret.ErrorMsg = "请求无效";
                return(ret);
            }


            int    type     = Convert.ToInt32(jsonData["Type"].ToString());
            string userName = jsonData["UserName"].ToString();
            string pwd      = jsonData["Pwd"].ToString();

            if (type == 0)
            {
                string channelId = jsonData["ChannelId"].ToString();
                ret.Type = "0";
                //注册
                MFReturnValue <int> retValue = AccountCacheModel.Instance.Register(userName, pwd, channelId, deviceIdentifier, deviceModel);
                ret.HasError = retValue.HasError;
                ret.ErrorMsg = retValue.Message;

                int userID = retValue.Value;

                AccountEntity entity = AccountCacheModel.Instance.GetEntity(userID);

                RetAccountEntity retAccountEntity = new RetAccountEntity(entity);
                ret.Value = JsonMapper.ToJson(retAccountEntity);
            }
            else
            {
                ret.Type = "1";
                //登录
                AccountEntity entity = AccountCacheModel.Instance.LogOn(userName, pwd, deviceIdentifier, deviceModel);
                if (entity != null)
                {
                    RetAccountEntity rect = new RetAccountEntity(entity);
                    ret.objValue = rect;
                }
                else
                {
                    // 登录失败
                    ret.HasError = true;
                    ret.ErrorMsg = "帐户取出来为空";
                }
            }

            return(ret);
        }
Exemple #9
0
        public RetValue Post([FromBody] string jsonStr)
        {
            RetValue ret = new RetValue();

            JsonData jsonData = JsonMapper.ToObject(jsonStr);

            //时间戳
            long   t = Convert.ToInt64(jsonData["t"].ToString());
            string deviceIdentifier = jsonData["deviceIdentifier"].ToString();
            string deviceModel      = jsonData["deviceModel"].ToString();
            string sign             = jsonData["sign"].ToString();

            //1.判断时间戳 如果大于3秒 直接返回错误
            if (MFDSAUtil.GetTimestamp() - t > 3)
            {
                ret.HasError  = true;
                ret.ErrorCode = 1002;// "请求无效";
                return(ret);
            }

            //2.验证签名
            string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier));

            if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase))
            {
                ret.HasError  = true;
                ret.ErrorCode = 1002; //"请求无效";
                return(ret);
            }

            //苹果回执
            string receipt = jsonData["receipt"].ToString();

            string strJosn = string.Format("{{\"receipt-data\":\"{0}\"}}", receipt);
            // 请求验证
            string strResult = CreatePostHttpResponse(strJosn, true);

            JsonData retJson = LitJson.JsonMapper.ToObject(strResult);

            int status = int.Parse(retJson["status"].ToString());

            if (status == 0)
            {
                //成功
                string   retreceipt        = retJson["receipt"].ToJson();
                JsonData retReceiptJson    = JsonMapper.ToObject(retreceipt);
                string   rechargeProductId = retReceiptJson["product_id"].ToString();
                ret.Value = rechargeProductId; //把充值产品编号传递给客户端
                //订单号 付费服务器识别码_玩家账号_要充值到哪个GameServerId_角色ID_充值的产品Id_时间
                string orderId = jsonData["orderId"].ToString();

                string[] arr = orderId.Split('_');
                if (arr.Length == 6)
                {
                    //1.记录充值日志
                    RechargeLogEntity rechargeLogEntity = new RechargeLogEntity();
                    rechargeLogEntity.AccountId = arr[1].ToInt();
                    short channelId = AccountCacheModel.Instance.GetEntity(rechargeLogEntity.AccountId).ChannelId;
                    rechargeLogEntity.Status            = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
                    rechargeLogEntity.ChannelId         = channelId;
                    rechargeLogEntity.GameServerId      = arr[2].ToInt();
                    rechargeLogEntity.RoldId            = arr[3].ToInt();
                    rechargeLogEntity.RechargeProductId = short.Parse(rechargeProductId);
                    rechargeLogEntity.OrderId           = orderId;
                    rechargeLogEntity.CreateTime        = DateTime.Now;

                    RechargeLogCacheModel.Instance.Create(rechargeLogEntity);


                    //2.找到对应的游戏服
                    int gameServerId = arr[2].ToInt();

                    GameServerEntity entity = GameServerCacheModel.Instance.GetEntity(gameServerId);
                    if (entity != null)
                    {
                        //发送socket请求 给游戏服
                        Socket rechargeServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                        rechargeServer.Connect(new IPEndPoint(IPAddress.Parse(entity.Ip), entity.Port));
                        string str = string.Format("{0}_{1}_{2}", channelId, arr[3], arr[4]);
                        rechargeServer.Send(System.Text.UTF8Encoding.UTF8.GetBytes(str));
                    }
                    else
                    {
                        ret.HasError  = true;
                        ret.ErrorCode = 1004; //"充值失败";
                    }
                }
                else
                {
                    ret.HasError  = true;
                    ret.ErrorCode = 1004; //"充值失败";
                }
            }
            else
            {
                ret.HasError  = true;
                ret.ErrorCode = 1004; //"充值失败";
            }


            return(ret);
        }
        // POST: api/Account
        public RetValue Post([FromBody] string jsonStr)
        {
            RetValue ret = new RetValue();

            JsonData jsonData = JsonMapper.ToObject(jsonStr);

            //时间戳

            long   t = Convert.ToInt64(jsonData["t"].ToString());
            string deviceIdentifier = jsonData["deviceIdentifier"].ToString();
            string deviceModel      = jsonData["deviceModel"].ToString();
            string sign             = jsonData["sign"].ToString();

            //1.判断时间戳 如果大于3秒 直接返回错误
            if (MFDSAUtil.GetTimestamp() - t > 3)
            {
                ret.HasError  = true;
                ret.ErrorCode = ProtoCode.RequestDelay;//"url请求无效";
                return(ret);
            }

            //2.验证签名
            string signServer = MFEncryptUtil.Md5(string.Format("{0}:{1}", t, deviceIdentifier));

            if (!signServer.Equals(sign, StringComparison.CurrentCultureIgnoreCase))
            {
                ret.HasError  = true;
                ret.ErrorCode = ProtoCode.SignatureInvalid;//"签名无效";
                return(ret);
            }

            int    type     = Convert.ToInt32(jsonData["Type"].ToString());
            string userName = jsonData["UserName"].ToString();

            string pwd = jsonData["Pwd"].ToString();

            if (type == 0)
            {
                short channelId = jsonData["ChannelId"].ToString().ToShort();

                //注册
                MFReturnValue <int> retValue = AccountCacheModel.Instance.Register(userName, pwd, channelId, deviceIdentifier, deviceModel);
                ret.HasError = retValue.HasError;
                //ret.ErrorMsg = retValue.Message;
                ret.ErrorCode = ProtoCode.AccountRegistrationFailed;

                int           userID = retValue.Value;
                AccountEntity entity = AccountCacheModel.Instance.GetEntity(userID);
                ret.Value = JsonMapper.ToJson(new RetAccountEntity(entity));
            }
            else
            {
                //登录
                AccountEntity entity = AccountCacheModel.Instance.LogOn(userName, pwd, deviceIdentifier, deviceModel);
                if (entity != null)
                {
                    ret.Value = JsonMapper.ToJson(new RetAccountEntity(entity));
                }
                else
                {
                    ret.HasError  = true;
                    ret.ErrorCode = ProtoCode.AccountDoesNotExist; //"帐户不存在";
                }
            }

            return(ret);
        }
Exemple #11
0
        public HttpResponseMessage Post()
        {
            #region 接收通知
            byte[] buffer = new byte[HttpContext.Current.Request.InputStream.Length];
            HttpContext.Current.Request.InputStream.Read(buffer, 0, buffer.Length);
            string req = System.Text.Encoding.Default.GetString(buffer);
            req = HttpContext.Current.Server.UrlDecode(req);

            string xml = req;

            LogHelper.WriteLog(typeof(WeixinRechargeController), "收到xml数据");
            LogHelper.WriteLog(typeof(WeixinRechargeController), xml);


            XDocument receiveDoc = XDocument.Parse(xml);
            XElement  root       = receiveDoc.Root;

            string   return_code   = "";
            XElement return_codeXE = root.Element("return_code");
            if (return_codeXE != null)
            {
                return_code = return_codeXE.Value;
            }

            if (return_code == "SUCCESS")
            {
                StringBuilder sbr = new StringBuilder();

                //应用ID
                XElement appidXE = root.Element("appid");
                if (appidXE != null)
                {
                    string appid = appidXE.Value;
                    sbr.AppendFormat("appid={0}", appid);
                }

                string orderId   = ""; //订单号
                short  channelId = 0;  //渠道号

                //商家数据包
                XElement attachXE = root.Element("attach");
                if (attachXE != null)
                {
                    string   attach = attachXE.Value;
                    string[] arr    = attach.Split('^');
                    channelId = arr[0].ToShort();
                    orderId   = arr[1];

                    sbr.AppendFormat("&attach={0}", attach);
                }

                //付款银行
                XElement bank_typeXE = root.Element("bank_type");
                if (bank_typeXE != null)
                {
                    string bank_type = bank_typeXE.Value;
                    sbr.AppendFormat("&bank_type={0}", bank_type);
                }

                //现金支付金额
                XElement cash_feeXE = root.Element("cash_fee");
                if (cash_feeXE != null)
                {
                    int cash_fee = cash_feeXE.Value.ToInt();
                    sbr.AppendFormat("&cash_fee={0}", cash_fee);
                }

                //现金支付货币类型
                XElement cash_fee_typeXE = root.Element("cash_fee_type");
                if (cash_fee_typeXE != null)
                {
                    string cash_fee_type = cash_fee_typeXE.Value;
                    sbr.AppendFormat("&cash_fee_type={0}", cash_fee_type);
                }

                //代金券使用数量
                XElement coupon_countXE = root.Element("coupon_count");
                if (coupon_countXE != null)
                {
                    int coupon_count = coupon_countXE.Value.ToInt();
                    sbr.AppendFormat("&coupon_count={0}", coupon_count);
                }

                //代金券金额
                XElement coupon_feeXE = root.Element("coupon_fee");
                if (coupon_feeXE != null)
                {
                    int coupon_fee = coupon_feeXE.Value.ToInt();
                    sbr.AppendFormat("&coupon_fee={0}", coupon_fee);
                }

                //代金券ID
                XElement coupon_idXE = root.Element("coupon_id");
                if (coupon_idXE != null)
                {
                    string coupon_id = coupon_idXE.Value;
                    sbr.AppendFormat("&coupon_id={0}", coupon_id);
                }

                //设备号
                XElement device_infoXE = root.Element("device_info");
                if (device_infoXE != null)
                {
                    string device_info = device_infoXE.Value;
                    sbr.AppendFormat("&device_info={0}", device_info);
                }

                //错误代码
                XElement err_codeXE = root.Element("err_code");
                if (err_codeXE != null)
                {
                    string err_code = err_codeXE.Value;
                    sbr.AppendFormat("&err_code={0}", err_code);
                }

                //错误代码描述
                XElement err_code_desXE = root.Element("err_code_des");
                if (err_code_desXE != null)
                {
                    string err_code_des = err_code_desXE.Value;
                    sbr.AppendFormat("&err_code_des={0}", err_code_des);
                }

                //货币种类
                XElement fee_typeXE = root.Element("fee_type");
                if (fee_typeXE != null)
                {
                    string fee_type = fee_typeXE.Value;
                    sbr.AppendFormat("&fee_type={0}", fee_type);
                }

                //是否关注公众账号
                XElement is_subscribeXE = root.Element("is_subscribe");
                if (is_subscribeXE != null)
                {
                    string is_subscribe = is_subscribeXE.Value;
                    sbr.AppendFormat("&is_subscribe={0}", is_subscribe);
                }

                //商户号
                XElement mch_idXE = root.Element("mch_id");
                if (mch_idXE != null)
                {
                    string mch_id = mch_idXE.Value;
                    sbr.AppendFormat("&mch_id={0}", mch_id);
                }

                //随机字符串
                XElement nonce_strXE = root.Element("nonce_str");
                if (nonce_strXE != null)
                {
                    string nonce_str = nonce_strXE.Value;
                    sbr.AppendFormat("&nonce_str={0}", nonce_str);
                }

                //用户标识
                XElement openidXE = root.Element("openid");
                if (openidXE != null)
                {
                    string openid = openidXE.Value;
                    sbr.AppendFormat("&openid={0}", openid);
                }


                //商户订单号
                XElement out_trade_noXE = root.Element("out_trade_no");
                if (out_trade_noXE != null)
                {
                    string out_trade_no = out_trade_noXE.Value;
                    sbr.AppendFormat("&out_trade_no={0}", out_trade_no);
                }

                //业务结果
                XElement result_codeXE = root.Element("result_code");
                if (result_codeXE != null)
                {
                    string result_code = result_codeXE.Value;
                    sbr.AppendFormat("&result_code={0}", result_code);
                }

                //返回状态码
                //return_code
                sbr.AppendFormat("&return_code={0}", return_code);

                //返回信息
                XElement return_msgXE = root.Element("return_msg");
                if (return_msgXE != null)
                {
                    string return_msg = return_msgXE.Value;
                    sbr.AppendFormat("&return_msg={0}", return_msg);
                }

                //签名
                string   sign   = "";
                XElement signXE = root.Element("sign");
                if (signXE != null)
                {
                    sign = signXE.Value;
                }

                //支付完成时间
                XElement time_endXE = root.Element("time_end");
                if (time_endXE != null)
                {
                    string time_end = time_endXE.Value;
                    sbr.AppendFormat("&time_end={0}", time_end);
                }

                //总金额
                XElement total_feeXE = root.Element("total_fee");
                if (total_feeXE != null)
                {
                    int total_fee = total_feeXE.Value.ToInt();
                    sbr.AppendFormat("&total_fee={0}", total_fee);
                }

                //交易类型
                XElement trade_typeXE = root.Element("trade_type");
                if (trade_typeXE != null)
                {
                    string trade_type = trade_typeXE.Value;
                    sbr.AppendFormat("&trade_type={0}", trade_type);
                }

                //微信支付订单号
                XElement transaction_idXE = root.Element("transaction_id");
                if (transaction_idXE != null)
                {
                    string transaction_id = transaction_idXE.Value;
                    sbr.AppendFormat("&transaction_id={0}", transaction_id);
                }


                sbr.AppendFormat("&key={0}", SDK_Weixin.GetWeixinConfig(channelId).payKey);

                //SDK_Weixin.appid
                //校验签名
                string mySign = MFEncryptUtil.Md5(sbr.ToString()).ToUpper(); //签名是MD5大写形式

                if (mySign == sign)
                {
                    //签名验证通过

                    //订单号 付费服务器识别码_玩家账号_要充值到哪个GameServerId_角色ID_充值的产品Id_时间
                    string[] arr = orderId.Split('_');
                    if (arr.Length == 6)
                    {
                        //判断订单号是否已经处理过
                        RechargeLogEntity searchEntity = RechargeLogCacheModel.Instance.GetEntity("OrderId='" + orderId + "'");
                        if (searchEntity == null)
                        {
                            //1.记录充值日志
                            RechargeLogEntity rechargeLogEntity = new RechargeLogEntity();
                            rechargeLogEntity.AccountId         = arr[1].ToInt();
                            rechargeLogEntity.Status            = Mmcoy.Framework.AbstractBase.EnumEntityStatus.Released;
                            rechargeLogEntity.ChannelId         = channelId;
                            rechargeLogEntity.GameServerId      = arr[2].ToInt();
                            rechargeLogEntity.RoldId            = arr[3].ToInt();
                            rechargeLogEntity.RechargeProductId = arr[4].ToShort();
                            rechargeLogEntity.OrderId           = orderId;
                            rechargeLogEntity.CreateTime        = DateTime.Now;

                            RechargeLogCacheModel.Instance.Create(rechargeLogEntity);


                            //2.找到对应的游戏服
                            int gameServerId = arr[2].ToInt();

                            GameServerEntity entity = GameServerCacheModel.Instance.GetEntity(gameServerId);
                            if (entity != null)
                            {
                                try
                                {
                                    //发送socket请求 给游戏服
                                    Socket rechargeServer = new Socket(AddressFamily.InterNetwork, SocketType.Stream, ProtocolType.Tcp);
                                    rechargeServer.Connect(new IPEndPoint(IPAddress.Parse(entity.Ip), entity.Port));
                                    string str = string.Format("{0}_{1}_{2}", channelId, arr[3], arr[4]);
                                    rechargeServer.Send(System.Text.UTF8Encoding.UTF8.GetBytes(str));
                                }
                                catch { }
                            }
                        }
                    }
                }
            }

            #endregion

            #region 返回通知

            StringBuilder sbrReturn = new StringBuilder();

            sbrReturn.Append("<xml>");
            sbrReturn.Append("<return_code><![CDATA[SUCCESS]]></return_code>");
            sbrReturn.Append("<return_msg><![CDATA[OK]]></return_msg>");
            sbrReturn.Append("</xml>");

            //一定要这样写 才能正确的返回xml格式数据给微信,直接返回字符串 微信不识别,那么微信还会重复调用这个接口进行通知
            return(new HttpResponseMessage()
            {
                Content = new StringContent(sbrReturn.ToString(), Encoding.UTF8, "application/xml")
            });

            #endregion
        }