Example #1
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="actionId"></param>
        /// <param name="sessionList"></param>
        /// <param name="package"></param>
        /// <param name="complateHandle"></param>
        /// <param name="onlineInterval"></param>
        /// <returns></returns>
        public static async System.Threading.Tasks.Task BroadcastAction(int actionId, GameSession session, object parameter, Action <GameSession, SocketAsyncResult> complateHandle, int onlineInterval)
        {
            try
            {
                sbyte          opCode  = OpCode.Binary;
                RequestPackage package = parameter is Parameters
                    ? ActionFactory.GetResponsePackage(actionId, session, parameter as Parameters, opCode, null)
                    : ActionFactory.GetResponsePackage(actionId, session, null, opCode, parameter);

                if (session.Equals(null))
                {
                    throw new ArgumentNullException("Session is a null value.");
                }

                IActionDispatcher actionDispatcher = new ScutActionDispatcher();
                package.Bind(session);
                var         actionGetter = new HttpGet(package, session);
                byte[]      data         = ProcessActionResponse(actionDispatcher, actionId, actionGetter);
                GameSession temp         = session;
                try
                {
                    if (onlineInterval <= 0 || session.LastActivityTime > MathUtils.Now.AddSeconds(-onlineInterval))
                    {
                        byte   userRet = 0;
                        string userSid = string.Empty;
                        if (actionGetter.GetByte("UserRet", ref userRet) && userRet == (byte)1 &&
                            actionGetter.GetString("UserSid", ref userSid))
                        {
                            var switchSession = ServerSsMgr.GetSwitchSession();
                            //未连接上路由服,则发给大厅服,由大厅服转发
                            if (switchSession == null)
                            {
                                var    paramStr = "ActionId=100&MsgId=0&UserSid=" + userSid;
                                string sign     = SignUtils.EncodeSign(paramStr, RequestParam.SignKey);
                                paramStr += string.Format("&{0}={1}", "sign", sign);
                                var    postData   = Encoding.UTF8.GetBytes(string.Format("?d={0}", paramStr));
                                byte[] paramBytes = new byte[postData.Length + PackageReader.EnterChar.Length + data.Length];
                                Buffer.BlockCopy(postData, 0, paramBytes, 0, postData.Length);
                                Buffer.BlockCopy(PackageReader.EnterChar, 0, paramBytes, postData.Length, PackageReader.EnterChar.Length);
                                Buffer.BlockCopy(data, 0, paramBytes, postData.Length + PackageReader.EnterChar.Length, data.Length);

                                await session.SendAsync(package.OpCode, paramBytes, 0, paramBytes.Length, result =>
                                {
                                    if (complateHandle != null)
                                    {
                                        complateHandle(temp, result);
                                    }
                                });
                            }
                            //已连接上路由服,则直接发给路由服
                            else
                            {
                                var    paramStr = "ActionId=101&MsgId=0&UserSid=" + userSid;
                                string sign     = SignUtils.EncodeSign(paramStr, RequestParam.SignKey);
                                paramStr += string.Format("&{0}={1}", "sign", sign);
                                var    postData   = Encoding.UTF8.GetBytes(string.Format("?d={0}", paramStr));
                                byte[] paramBytes = new byte[postData.Length + PackageReader.EnterChar.Length + data.Length];
                                Buffer.BlockCopy(postData, 0, paramBytes, 0, postData.Length);
                                Buffer.BlockCopy(PackageReader.EnterChar, 0, paramBytes, postData.Length, PackageReader.EnterChar.Length);
                                Buffer.BlockCopy(data, 0, paramBytes, postData.Length + PackageReader.EnterChar.Length, data.Length);

                                await switchSession.SendAsync(package.OpCode, paramBytes, 0, paramBytes.Length, result =>
                                {
                                    if (complateHandle != null)
                                    {
                                        complateHandle(temp, result);
                                    }
                                });
                            }
                        }
                        else
                        {
                            await session.SendAsync(package.OpCode, data, 0, data.Length, result =>
                            {
                                if (complateHandle != null)
                                {
                                    complateHandle(temp, result);
                                }
                            });
                        }
                    }
                    else
                    {
                        if (complateHandle != null)
                        {
                            complateHandle(temp, new SocketAsyncResult(data)
                            {
                                Result = ResultCode.Close
                            });
                        }
                    }
                }
                catch (Exception ex)
                {
                    if (complateHandle != null)
                    {
                        complateHandle(temp, new SocketAsyncResult(data)
                        {
                            Result = ResultCode.Error, Error = ex
                        });
                    }
                    TraceLog.WriteError("SocialBroadCastActionFactory BroadcastAction  action:{0} userId:{1} error:{2}", actionId, session.UserId, ex);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("SocialBroadCastActionFactory BroadcastAction  action:{0} error:{1}", actionId, ex);
            }
        }
Example #2
0
        /// <summary>
        /// 查询个人用户证件信息
        /// </summary>
        /// <param name="account">用户唯一标识</param>
        public BaseResult <GetPersonalCredentialResult> GetPersonalCredential(string account)
        {
            Dictionary <string, object> requestParams = new Dictionary <string, object>();

            requestParams.Add("account", account);

            SortedDictionary <string, object> keyValues = new SortedDictionary <string, object>();

            keyValues.Add("developerId", Constants.DeveloperID);
            keyValues.Add("rtick", SignUtils.ToUnixEpochDate(DateTime.Now).ToString() + SignUtils.ToRandom(1000, 9999));
            keyValues.Add("signType", Constants.SignType);

            var signResult       = SignUtils.GenerateSign(Constants.Path + Constants.User_GetPersonalCredential, SignUtils.GenerateMD5(requestParams), keyValues);
            var signEncryResult  = RSAEncryption.SignData(signResult, Constants.PrivateKey);
            var signEncodeResult = SignUtils.SignUrlEncode(signEncryResult);

            keyValues.Add("sign", signEncodeResult);
            var originalUrl = Constants.Host + Constants.Path + Constants.User_GetPersonalCredential;
            var requestUrl  = SignUtils.GenerateUrl(originalUrl, keyValues);

            BaseResult <GetPersonalCredentialResult> result = httpService.HttpPost <BaseResult <GetPersonalCredentialResult> >(requestUrl, requestParams);

            return(result);
        }
Example #3
0
        private async System.Threading.Tasks.Task ProcessPackage(RequestPackage package, GameSession session)
        {
            if (package == null)
            {
                return;
            }

            try
            {
                ActionGetter actionGetter;
                byte[]       data = new byte[0];
                if (!string.IsNullOrEmpty(package.RouteName))
                {
                    actionGetter = ActionDispatcher.GetActionGetter(package, session);
                    if (CheckRemote(package.RouteName, actionGetter))
                    {
                        MessageStructure response = new MessageStructure();
                        OnCallRemote(package.RouteName, actionGetter, response);
                        data = response.PopBuffer();
                    }
                    else
                    {
                        return;
                    }
                }
                else
                {
                    SocketGameResponse response = new SocketGameResponse();
                    response.WriteErrorCallback += ActionDispatcher.ResponseError;
                    actionGetter = ActionDispatcher.GetActionGetter(package, session);
                    DoAction(actionGetter, response);
                    data = response.ReadByte();
                }
                try
                {
                    if (session != null && data.Length > 0)
                    {
                        byte   userRet = 0;
                        string userSid = string.Empty;
                        if (actionGetter.GetByte("UserRet", ref userRet) && userRet == (byte)1 &&
                            actionGetter.GetString("UserSid", ref userSid))
                        {
                            var switchSession = ServerSsMgr.GetSwitchSession();
                            //未连接上路由服,则发给大厅服,由大厅服转发
                            if (switchSession == null)
                            {
                                var    paramStr = "ActionId=100&MsgId=0&UserSid=" + userSid;
                                string sign     = SignUtils.EncodeSign(paramStr, RequestParam.SignKey);
                                paramStr += string.Format("&{0}={1}", "sign", sign);
                                var    postData   = Encoding.UTF8.GetBytes(string.Format("?d={0}", paramStr));
                                byte[] paramBytes = new byte[postData.Length + PackageReader.EnterChar.Length + data.Length];
                                Buffer.BlockCopy(postData, 0, paramBytes, 0, postData.Length);
                                Buffer.BlockCopy(PackageReader.EnterChar, 0, paramBytes, postData.Length, PackageReader.EnterChar.Length);
                                Buffer.BlockCopy(data, 0, paramBytes, postData.Length + PackageReader.EnterChar.Length, data.Length);

                                await session.SendAsync(actionGetter.OpCode, paramBytes, 0, paramBytes.Length, OnSendCompleted);
                            }
                            //已连接上路由服,则直接发给路由服
                            else
                            {
                                var    paramStr = "ActionId=101&MsgId=0&UserSid=" + userSid;
                                string sign     = SignUtils.EncodeSign(paramStr, RequestParam.SignKey);
                                paramStr += string.Format("&{0}={1}", "sign", sign);
                                var    postData   = Encoding.UTF8.GetBytes(string.Format("?d={0}", paramStr));
                                byte[] paramBytes = new byte[postData.Length + PackageReader.EnterChar.Length + data.Length];
                                Buffer.BlockCopy(postData, 0, paramBytes, 0, postData.Length);
                                Buffer.BlockCopy(PackageReader.EnterChar, 0, paramBytes, postData.Length, PackageReader.EnterChar.Length);
                                Buffer.BlockCopy(data, 0, paramBytes, postData.Length + PackageReader.EnterChar.Length, data.Length);

                                await switchSession.SendAsync(actionGetter.OpCode, paramBytes, 0, paramBytes.Length, OnSendCompleted);
                            }
                        }
                    }
                }
                catch (Exception ex)
                {
                    TraceLog.WriteError("PostSend error:{0}", ex);
                }
            }
            catch (Exception ex)
            {
                TraceLog.WriteError("Task error:{0}", ex);
            }
            finally
            {
                if (session != null)
                {
                    session.ExitSession();
                }
            }
        }
Example #4
0
        public ActionResult ChangePwd()
        {
            var sr = RequestResult(res =>
            {
                #region 获取参数
                Hashtable param = base.GetParameters();
                ParamVessel p   = new ParamVessel();
                p.Add("id_shop", string.Empty, HandleType.ReturnMsg);       //id_shop
                p.Add("id_masteruser", string.Empty, HandleType.ReturnMsg); //id_masteruser
                p.Add("id_user", string.Empty, HandleType.ReturnMsg);       //id
                p.Add("old_pwd", string.Empty, HandleType.ReturnMsg);       //old_pwd
                p.Add("new_pwd", string.Empty, HandleType.ReturnMsg);       //new_pwd
                p.Add("sign", string.Empty, HandleType.ReturnMsg);          //sign
                #endregion
                #region 验证参数
                try
                {
                    param = param.Trim(p);
                }
                catch (Exception ex)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = "部份必要参数缺失!";
                    return(res);
                }
                #endregion
                #region 读取ticket
                //读取ticket
                Hashtable ht = new Hashtable();
                ht.Add("key_y", param["id_masteruser"].ToString() + "_" + param["id_shop"].ToString());
                var ticketBr = BusinessFactory.Tb_Ticket.Get(ht);
                if (!ticketBr.Success)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = "主用户或门店ID缺失!";
                    return(res);
                }
                var ticketModel = (Tb_Ticket)ticketBr.Data;
                if (ticketModel == null)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = "登录票据已不存在,请重新登录!";
                    return(res);
                }
                var ticket = ticketModel.ticket;
                #endregion
                #region 验证签名
                IDictionary <string, string> dic = base.GetParameters(new string[] { "id_shop", "id_masteruser", "id_user", "old_pwd", "new_pwd" });

                var validSign = SignUtils.SignRequest(dic, ticket);
                //验证签名
                if (param["sign"].ToString() != validSign)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = "数据签名验证失败!";
                    return(res);
                }
                #endregion

                #region 更新密码
                param.Remove("sign");
                param.Add("id", param["id_user"]);
                param.Remove("id_user");
                var br = BusinessFactory.Account.ChangeUserPwd(param);
                #endregion

                #region 返回
                res.State   = br.Success ? ServiceState.Done : ServiceState.Fail;
                res.Message = br.Message.FirstOrDefault();
                res.Data    = "";
                return(res);

                #endregion
            });

            return(JsonString(sr));
        }
Example #5
0
        /// <summary>
        /// 注册个人用户并申请证书 | 注册企业用户并申请证书
        /// </summary>
        /// <param name="account">用户唯一标识</param>
        /// <param name="name">用户名称</param>
        /// <param name="userType">用户类型</param>
        /// <param name="credential">用户证件信息对象</param>
        /// <param name="applyCert"></param>
        /// <param name="mail">用户邮箱</param>
        /// <param name="mobile">用户手机号</param>
        /// <returns></returns>
        public BaseResult <RegResult> Reg(string account, string name, string userType, object credential, string applyCert, string mail = "", string mobile = "")
        {
            Dictionary <string, object> requestParams = new Dictionary <string, object>();

            requestParams.Add("account", account);
            requestParams.Add("name", name);
            requestParams.Add("userType", userType);
            requestParams.Add("mail", mail);
            requestParams.Add("mobile", mobile);
            requestParams.Add("credential", credential);
            requestParams.Add("applyCert", applyCert);

            SortedDictionary <string, object> keyValues = new SortedDictionary <string, object>();

            keyValues.Add("developerId", Constants.DeveloperID);
            keyValues.Add("rtick", SignUtils.ToUnixEpochDate(DateTime.Now).ToString() + SignUtils.ToRandom(1000, 9999));
            keyValues.Add("signType", Constants.SignType);

            var signResult       = SignUtils.GenerateSign(Constants.Path + Constants.User_Reg, SignUtils.GenerateMD5(requestParams), keyValues);
            var signEncryResult  = RSAEncryption.SignData(signResult, Constants.PrivateKey);
            var signEncodeResult = SignUtils.SignUrlEncode(signEncryResult);

            keyValues.Add("sign", signEncodeResult);
            var originalUrl = Constants.Host + Constants.Path + Constants.User_Reg;
            var requestUrl  = SignUtils.GenerateUrl(originalUrl, keyValues);

            BaseResult <RegResult> result = httpService.HttpPost <BaseResult <RegResult> >(requestUrl, requestParams);

            return(result);
        }
        /// <summary>
        /// 上传用户签名/印章图片
        /// </summary>
        /// <param name="account">用户唯一标识</param>
        /// <param name="imageData">图片文件内容</param>
        /// <param name="imageName">签名/印章图片名称</param>
        /// <returns></returns>
        public BaseResult <CommonResult> UserUpload(string account, string imageData, string imageName = "")
        {
            Dictionary <string, object> requestParams = new Dictionary <string, object>();

            requestParams.Add("account", account);
            requestParams.Add("imageData", imageData);
            if (string.IsNullOrWhiteSpace(imageName))
            {
                requestParams.Add("imageName", imageName);
            }


            SortedDictionary <string, object> keyValues = new SortedDictionary <string, object>();

            keyValues.Add("developerId", Constants.DeveloperID);
            keyValues.Add("rtick", SignUtils.ToUnixEpochDate(DateTime.Now).ToString() + SignUtils.ToRandom(1000, 9999));
            keyValues.Add("signType", Constants.SignType);

            var signResult       = SignUtils.GenerateSign(Constants.Path + Constants.SignatureImage_User_Upload, SignUtils.GenerateMD5(requestParams), keyValues);
            var signEncryResult  = RSAEncryption.SignData(signResult, Constants.PrivateKey);
            var signEncodeResult = SignUtils.SignUrlEncode(signEncryResult);

            keyValues.Add("sign", signEncodeResult);
            var originalUrl = Constants.Host + Constants.Path + Constants.SignatureImage_User_Upload;
            var requestUrl  = SignUtils.GenerateUrl(originalUrl, keyValues);

            BaseResult <CommonResult> result = httpService.HttpPost <BaseResult <CommonResult> >(requestUrl, requestParams);

            return(result);
        }
Example #7
0
        public ActionResult Add()
        {
            ServiceResult res = new ServiceResult()
            {
                State = ServiceState.Done
            };

            try
            {
                #region 编码类型
                Encoding encoding = null;
                //编码类型
                string charset = System.Configuration.ConfigurationManager.AppSettings["Charset"];
                try
                {
                    encoding = Encoding.GetEncoding(charset);
                }
                catch
                {
                    encoding = Encoding.GetEncoding("UTF-8");
                }
                #endregion

                #region 获取参数
                Hashtable param     = base.GetParameters();
                string    id_user   = Request["id_user"] == null ? "" : HttpUtility.UrlDecode(Request["id_user"], encoding);     //id_user
                string    flag_from = Request["flag_from"] == null ? "" : HttpUtility.UrlDecode(Request["flag_from"], encoding); //flag_from
                string    flag_lx   = Request["flag_lx"] == null ? "" : HttpUtility.UrlDecode(Request["flag_lx"], encoding);     //flag_lx
                string    content   = Request["content"] == null ? "" : HttpUtility.UrlDecode(Request["content"], encoding);     //content
                string    sign      = Request["sign"] == null ? "" : HttpUtility.UrlDecode(Request["sign"], encoding);           //sign
                string    ip        = Request["ip"] == null ? "" : HttpUtility.UrlDecode(Request["ip"], encoding);               //ip

                #endregion
                #region 验证参数
                if (string.IsNullOrEmpty(content) || string.IsNullOrEmpty(sign))
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0001;
                    return(JsonString(res));
                }
                #endregion
                #region 验证签名
                Dictionary <string, string> dic = new Dictionary <string, string>();
                dic.Add("id_user", HttpUtility.UrlEncode(id_user, Encoding.UTF8));
                dic.Add("flag_from", HttpUtility.UrlEncode(flag_from, Encoding.UTF8));
                dic.Add("flag_lx", HttpUtility.UrlEncode(flag_lx, Encoding.UTF8));
                //dic.Add("content", HttpUtility.UrlEncode(content, Encoding.UTF8)  );
                var validSign = SignUtils.SignRequest(dic, "CY2016");
                //验证签名
                if (sign != validSign)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0002;
                    return(JsonString(res));
                }
                #endregion
                #region 读取数据
                Hashtable loginInfo = new Hashtable();
                loginInfo.Add("id_user", id_user);
                loginInfo.Add("flag_from", flag_from);

                if (!string.IsNullOrEmpty(ip))
                {
                    loginInfo.Add("ip", ip);
                }

                BusinessFactory.Log.Add(loginInfo, flag_lx.ToString(), content.ToString());

                #endregion
                #region 返回
                res.State   = ServiceState.Done;
                res.Message = "操作成功!";
                res.Data    = "";
                return(JsonString(res));

                #endregion
            }
            catch (Exception ex)
            {
                res.State   = ServiceState.Fail;
                res.Message = ServiceFailCode.S0001;
                return(JsonString(res));
            }
        }
Example #8
0
        public ActionResult OutOrderPay()
        {
            var sr = RequestResult(res =>
            {
                #region 获取参数
                Hashtable param = base.GetParameters();
                ParamVessel p   = new ParamVessel();
                p.Add("id_shop", string.Empty, HandleType.ReturnMsg);       //id_shop
                p.Add("id_masteruser", string.Empty, HandleType.ReturnMsg); //id_masteruser
                p.Add("dh", string.Empty, HandleType.ReturnMsg);            //dh
                p.Add("json_param", string.Empty, HandleType.ReturnMsg);    //json_param
                p.Add("sign", string.Empty, HandleType.ReturnMsg);          //sign
                #endregion
                #region 验证参数
                try
                {
                    param = param.Trim(p);
                }
                catch (Exception ex)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0001;
                    return(res);
                }

                #endregion
                #region 转换payList
                try
                {
                    var payList = Utility.JSON.Deserialize <List <Money_OrderPayList> >(param["json_param"].ToString());
                    param.Add("payList", payList);
                }
                catch (Exception ex)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = "json_param参数格式不正确.";
                    return(res);
                }
                #endregion
                #region 读取ticket
                //读取ticket
                Hashtable ht = new Hashtable();
                ht.Add("key_y", param["id_masteruser"].ToString() + "_" + param["id_shop"].ToString());
                var ticketBr = BusinessFactory.Tb_Ticket.Get(ht);
                if (!ticketBr.Success)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.S0001;
                    return(res);
                }

                var ticketModel = (Tb_Ticket)ticketBr.Data;
                if (ticketModel == null)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0003;
                    return(res);
                }

                var ticket = ticketModel.ticket;
                #endregion
                #region 验证签名
                IDictionary <string, string> dic = base.GetParameters(new string[] { "id_shop", "id_masteruser", "json_param", "dh" });

                var validSign = SignUtils.SignRequest(dic, ticket);
                //验证签名
                if (param["sign"].ToString() != validSign)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0002;
                    return(res);
                }
                #endregion
                #region 执行操作
                var br = BusinessFactory.Pay.OutOrderPay(param);
                #endregion
                #region 返回

                res.State   = br.Success ? ServiceState.Done : ServiceState.Fail;
                res.Message = br.Message.FirstOrDefault();
                res.Data    = br.Data;
                return(res);

                #endregion
            });

            return(JsonString(sr));
        }
        /// <summary>
        /// 下载用户签名/印章图片
        /// </summary>
        /// <param name="account">用户唯一标识</param>
        /// <param name="imageName">签名/印章图片名称</param>
        /// <returns></returns>
        public BaseResult <CommonResult> UserDownload(string account, string imageName = "default")
        {
            SortedDictionary <string, object> keyValues = new SortedDictionary <string, object>();

            keyValues.Add("account", account);
            keyValues.Add("imageName", imageName);
            keyValues.Add("developerId", Constants.DeveloperID);
            keyValues.Add("rtick", SignUtils.ToUnixEpochDate(DateTime.Now).ToString() + SignUtils.ToRandom(1000, 9999));
            keyValues.Add("signType", Constants.SignType);

            var signResult       = SignUtils.GenerateSign(Constants.Path + Constants.SignatureImage_User_Download, "", keyValues);
            var signEncryResult  = RSAEncryption.SignData(signResult, Constants.PrivateKey);
            var signEncodeResult = SignUtils.SignUrlEncode(signEncryResult);

            keyValues.Add("sign", signEncodeResult);
            var originalUrl = Constants.Host + Constants.Path + Constants.SignatureImage_User_Download;
            var requestUrl  = SignUtils.GenerateUrl(originalUrl, keyValues);

            BaseResult <CommonResult> result = httpService.HttpGet <BaseResult <CommonResult> >(requestUrl);

            return(result);
        }
Example #10
0
        /// <summary>
        /// 上传合同文件
        /// </summary>
        /// <param name="account">用户唯一标识</param>
        /// <param name="fdata">文件数据,base64编码</param>
        /// <param name="fmd5">文件md5值</param>
        /// <param name="ftype">文件类型</param>
        /// <param name="fname">文件名</param>
        /// <param name="fpages">文件页数</param>
        /// <returns></returns>
        public BaseResult <StorageUploadResult> Upload(string account, string fdata, string fmd5, string ftype, string fname, int fpages)
        {
            Dictionary <string, object> requestParams = new Dictionary <string, object>();

            requestParams.Add("account", account);
            requestParams.Add("fdata", fdata);
            requestParams.Add("fmd5", fmd5);
            requestParams.Add("ftype", ftype);
            requestParams.Add("fname", fname);
            requestParams.Add("fpages", fpages);

            SortedDictionary <string, object> keyValues = new SortedDictionary <string, object>();

            keyValues.Add("developerId", Constants.DeveloperID);
            keyValues.Add("rtick", SignUtils.ToUnixEpochDate(DateTime.Now).ToString() + SignUtils.ToRandom(1000, 9999));
            keyValues.Add("signType", Constants.SignType);

            var signResult       = SignUtils.GenerateSign(Constants.Path + Constants.Storage_Upload, SignUtils.GenerateMD5(requestParams), keyValues);
            var signEncryResult  = RSAEncryption.SignData(signResult, Constants.PrivateKey);
            var signEncodeResult = SignUtils.SignUrlEncode(signEncryResult);

            keyValues.Add("sign", signEncodeResult);
            var originalUrl = Constants.Host + Constants.Path + Constants.Storage_Upload;
            var requestUrl  = SignUtils.GenerateUrl(originalUrl, keyValues);

            BaseResult <StorageUploadResult> result = httpService.HttpPost <BaseResult <StorageUploadResult> >(requestUrl, requestParams);

            return(result);
        }
Example #11
0
        public ActionResult WXPayQuery()
        {
            var sr = RequestResult(res =>
            {
                #region 获取参数
                Hashtable param = base.GetParameters();
                ParamVessel p   = new ParamVessel();
                p.Add("id_shop", string.Empty, HandleType.ReturnMsg);       //id_shop
                p.Add("id_masteruser", string.Empty, HandleType.ReturnMsg); //id_masteruser
                p.Add("out_trade_no", string.Empty, HandleType.ReturnMsg);  //out_trade_no
                p.Add("sign", string.Empty, HandleType.ReturnMsg);          //sign
                #endregion
                #region 验证参数
                try
                {
                    param = param.Trim(p);
                }
                catch (Exception ex)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0001;
                    return(res);
                }

                #endregion
                #region 读取ticket
                //读取ticket
                Hashtable ht = new Hashtable();
                ht.Add("key_y", param["id_masteruser"].ToString() + "_" + param["id_shop"].ToString());
                var ticketBr = BusinessFactory.Tb_Ticket.Get(ht);
                if (!ticketBr.Success)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.S0001;
                    return(res);
                }

                var ticketModel = (Tb_Ticket)ticketBr.Data;
                if (ticketModel == null)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0003;
                    return(res);
                }

                var ticket = ticketModel.ticket;
                #endregion
                #region 验证签名
                IDictionary <string, string> dic = base.GetParameters(new string[] { "id_shop", "id_masteruser", "out_trade_no" });

                var validSign = SignUtils.SignRequest(dic, ticket);
                //验证签名
                if (param["sign"].ToString() != validSign)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0002;
                    return(res);
                }
                #endregion
                #region 检验支付宝交易号,和商户订单号不能同时为空

                if (string.IsNullOrEmpty(param["out_trade_no"].ToString()))
                {
                    res.State   = ServiceState.Fail;
                    res.Message = "商户订单号不能为空.";
                    return(res);
                }
                #endregion
                #region 执行操作
                var br = BusinessFactory.Pay.WXPayQuery(param);
                #endregion
                #region 返回

                res.State   = br.Success ? ServiceState.Done : ServiceState.Fail;
                res.Message = br.Message.FirstOrDefault();
                res.Data    = br.Data;
                return(res);

                #endregion
            });

            return(JsonString(sr));
        }
Example #12
0
        /// <summary>
        /// PDF文件验签
        /// </summary>
        /// <param name="pdfData">PDF文件</param>
        /// <returns></returns>
        public BaseResult <PDFVerifySignaturesResult> VerifySignatures(string pdfData)
        {
            Dictionary <string, object> requestParams = new Dictionary <string, object>();

            requestParams.Add("pdfData", pdfData);


            SortedDictionary <string, object> keyValues = new SortedDictionary <string, object>();

            keyValues.Add("developerId", Constants.DeveloperID);
            keyValues.Add("rtick", SignUtils.ToUnixEpochDate(DateTime.Now).ToString() + SignUtils.ToRandom(1000, 9999));
            keyValues.Add("signType", Constants.SignType);

            var signResult       = SignUtils.GenerateSign(Constants.Path + Constants.Pdf_VerifySignatures, "", keyValues);
            var signEncryResult  = RSAEncryption.SignData(signResult, Constants.PrivateKey);
            var signEncodeResult = SignUtils.SignUrlEncode(signEncryResult);

            keyValues.Add("sign", signEncodeResult);
            var originalUrl = Constants.Host + Constants.Path + Constants.Pdf_VerifySignatures;
            var requestUrl  = SignUtils.GenerateUrl(originalUrl, keyValues);

            BaseResult <PDFVerifySignaturesResult> result = httpService.HttpPost <BaseResult <PDFVerifySignaturesResult> >(requestUrl, requestParams);

            return(result);
        }
Example #13
0
        /// <summary>
        /// 下载文件
        /// </summary>
        /// <param name="fid">文件编号</param>
        /// <returns></returns>
        public BaseResult <StorageUploadResult> Download(string fid)
        {
            SortedDictionary <string, object> keyValues = new SortedDictionary <string, object>();

            keyValues.Add("fid", fid);
            keyValues.Add("developerId", Constants.DeveloperID);
            keyValues.Add("rtick", SignUtils.ToUnixEpochDate(DateTime.Now).ToString() + SignUtils.ToRandom(1000, 9999));
            keyValues.Add("signType", Constants.SignType);

            var signResult       = SignUtils.GenerateSign(Constants.Path + Constants.Storage_Download, "", keyValues);
            var signEncryResult  = RSAEncryption.SignData(signResult, Constants.PrivateKey);
            var signEncodeResult = SignUtils.SignUrlEncode(signEncryResult);

            keyValues.Add("sign", signEncodeResult);
            var originalUrl = Constants.Host + Constants.Path + Constants.Storage_Download;
            var requestUrl  = SignUtils.GenerateUrl(originalUrl, keyValues);

            BaseResult <StorageUploadResult> result = httpService.HttpGet <BaseResult <StorageUploadResult> >(requestUrl);

            return(result);
        }
Example #14
0
        public ActionResult CheckHY()
        {
            var sr = RequestResult(res =>
            {
                #region 获取参数
                Hashtable param = base.GetParameters();
                ParamVessel p   = new ParamVessel();
                p.Add("id_shop", string.Empty, HandleType.ReturnMsg);       //id_shop
                p.Add("id_masteruser", string.Empty, HandleType.ReturnMsg); //id_masteruser
                p.Add("id_hy", string.Empty, HandleType.ReturnMsg);         //id_hy
                p.Add("password", string.Empty, HandleType.ReturnMsg);      //password
                p.Add("sign", string.Empty, HandleType.ReturnMsg);          //sign
                #endregion
                #region 验证参数
                try
                {
                    param = param.Trim(p);
                }
                catch (Exception ex)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0001;
                    return(res);
                }

                #endregion
                #region 读取ticket
                //读取ticket
                Hashtable ht = new Hashtable();
                ht.Add("key_y", param["id_masteruser"].ToString() + "_" + param["id_shop"].ToString());
                var ticketBr = BusinessFactory.Tb_Ticket.Get(ht);
                if (!ticketBr.Success)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.S0001;
                    return(res);
                }

                var ticketModel = (Tb_Ticket)ticketBr.Data;
                if (ticketModel == null)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0003;
                    return(res);
                }

                var ticket = ticketModel.ticket;
                #endregion
                #region 验证签名
                IDictionary <string, string> dic = base.GetParameters(new string[] { "id_shop", "id_masteruser", "id_hy", "password" });


                var validSign = SignUtils.SignRequest(dic, ticket);
                //验证签名
                if (param["sign"].ToString() != validSign)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0002;
                    return(res);
                }
                #endregion
                #region 执行操作
                param.Remove("sign");
                param.Add("Type", "XF");

                var br = BusinessFactory.Tz_Hy_Je.CheckStock(param);
                #endregion
                #region 返回

                res.State   = br.Success ? ServiceState.Done : ServiceState.Fail;
                res.Message = br.Message.FirstOrDefault();
                res.Data    = br.Data;
                return(res);

                #endregion
            });

            return(JsonString(sr));
        }
Example #15
0
        public ActionResult JfEdit()
        {
            var sr = RequestResult(res =>
            {
                #region 获取参数
                Hashtable param = base.GetParameters();
                ParamVessel p   = new ParamVessel();
                p.Add("id_shop", string.Empty, HandleType.ReturnMsg);       //id_shop
                p.Add("id_masteruser", string.Empty, HandleType.ReturnMsg); //id_masteruser
                p.Add("id_hy", string.Empty, HandleType.ReturnMsg);         //id_hy
                p.Add("id_bill", string.Empty, HandleType.ReturnMsg);       //id_bill
                p.Add("bm_djlx", string.Empty, HandleType.ReturnMsg);       //bm_djlx
                p.Add("rq", string.Empty, HandleType.ReturnMsg);            //rq
                p.Add("jf", string.Empty, HandleType.ReturnMsg);            //je
                p.Add("bz", string.Empty, HandleType.DefaultValue);         //bz
                p.Add("sign", string.Empty, HandleType.ReturnMsg);          //sign
                #endregion
                #region 验证参数
                try
                {
                    param = param.Trim(p);
                }
                catch (Exception ex)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0001;
                    return(res);
                }

                if (!CyVerify.IsNumeric(param["jf"].ToString()))
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0001;
                    return(res);
                }

                DateTime timeTemp = DateTime.Now;
                if (!DateTime.TryParse(param["rq"].ToString(), out timeTemp))
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0001;
                    return(res);
                }

                #endregion
                #region 读取ticket
                //读取ticket
                Hashtable ht = new Hashtable();
                ht.Add("key_y", param["id_masteruser"].ToString() + "_" + param["id_shop"].ToString());
                var ticketBr = BusinessFactory.Tb_Ticket.Get(ht);
                if (!ticketBr.Success)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.S0001;
                    return(res);
                }
                var ticketModel = (Tb_Ticket)ticketBr.Data;
                if (ticketModel == null)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0003;
                    return(res);
                }
                var ticket = ticketModel.ticket;
                #endregion
                #region 验证签名
                IDictionary <string, string> dic = base.GetParameters(new string[] { "id_shop", "id_masteruser", "id_hy", "id_bill", "bm_djlx", "rq", "jf", "bz" });

                var validSign = SignUtils.SignRequest(dic, ticket);
                //验证签名
                if (param["sign"].ToString() != validSign)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0002;
                    return(res);
                }
                #endregion
                #region 执行操作
                param.Remove("sign");

                if (decimal.Parse(param["jf"].ToString()) > 0)
                {
                    param.Add("Type", "Add");
                }
                else
                {
                    param.Add("Type", "Del");
                }

                var br = BusinessFactory.Tz_Hy_Jf.Add(param);
                #endregion
                #region 返回

                res.State   = br.Success ? ServiceState.Done : ServiceState.Fail;
                res.Message = br.Message.FirstOrDefault();
                res.Data    = br.Data;
                return(res);

                #endregion
            });

            return(JsonString(sr));
        }
Example #16
0
        public ActionResult Add()
        {
            var sr = RequestResult(res =>
            {
                #region 获取参数
                Hashtable param = base.GetParameters();
                ParamVessel p   = new ParamVessel();
                p.Add("id_shop", string.Empty, HandleType.ReturnMsg);       //id_shop_create
                p.Add("id_masteruser", string.Empty, HandleType.ReturnMsg); //id_masteruser
                p.Add("membercard", string.Empty, HandleType.DefaultValue); //membercard
                p.Add("phone", string.Empty, HandleType.ReturnMsg);         //phone
                p.Add("name", string.Empty, HandleType.ReturnMsg);          //name
                p.Add("id_hyfl", string.Empty, HandleType.ReturnMsg);       //id_hyfl
                p.Add("rq_b", string.Empty, HandleType.Remove);             //rq_b
                p.Add("rq_e", string.Empty, HandleType.Remove);             //rq_e
                p.Add("qq", string.Empty, HandleType.DefaultValue);         //qq
                p.Add("email", string.Empty, HandleType.DefaultValue);      //email
                p.Add("tel", string.Empty, HandleType.DefaultValue);        //tel
                p.Add("address", string.Empty, HandleType.DefaultValue);    //address
                p.Add("mmno", string.Empty, HandleType.DefaultValue);       //mmno
                p.Add("zipcode", string.Empty, HandleType.DefaultValue);    //zipcode
                p.Add("birthday", string.Empty, HandleType.DefaultValue);   //birthday
                p.Add("hysr", "", HandleType.DefaultValue);                 //hysr

                p.Add("zk", "0.00", HandleType.Remove);                     //zk
                p.Add("flag_nl", "0", HandleType.DefaultValue);             //flag_nl 是否农历
                p.Add("flag_sex", "1", HandleType.Remove);                  //flag_sex
                p.Add("password", "", HandleType.DefaultValue);             //password
                p.Add("flag_yhlx", "1", HandleType.Remove);                 //flag_yhlx


                p.Add("sign", string.Empty, HandleType.ReturnMsg);//sign
                #endregion
                #region 验证参数
                try
                {
                    param = param.Trim(p);
                }
                catch (Exception ex)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0001;
                    return(res);
                }
                #endregion
                #region 读取ticket
                //读取ticket
                Hashtable ht = new Hashtable();
                ht.Add("key_y", param["id_masteruser"].ToString() + "_" + param["id_shop"].ToString());
                //var ticketBr = BusinessFactory.Tb_Ticket.Get(ht);

                var ticketBr = base.GetTicketInfo(param["id_masteruser"].ToString() + "_" + param["id_shop"].ToString());

                if (!ticketBr.Success)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.S0001;
                    return(res);
                }

                var ticketModel = (Tb_Ticket)ticketBr.Data;
                if (ticketModel == null)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0003;
                    return(res);
                }

                var ticket = ticketModel.ticket;
                #endregion
                #region 验证签名
                IDictionary <string, string> dic = base.GetParameters(new string[] { "id_shop", "id_masteruser", "membercard", "phone", "name", "id_hyfl", "qq", "email", "tel", "address", "mmno", "zipcode", "birthday", "flag_nl", "hysr", "rq_b", "rq_e", "zk", "flag_sex", "password", "flag_yhlx" });

                var validSign = SignUtils.SignRequest(dic, ticket);
                //验证签名
                if (param["sign"].ToString() != validSign)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0002;
                    return(res);
                }
                #endregion
                #region 验证参数是否符合
                //验证参数是否符合
                //if (string.IsNullOrEmpty(param["phone"].ToString()) || !CyVerify.IsPhone(param["phone"].ToString()) || (param["flag_nl"].ToString() != "0" && param["flag_nl"].ToString() != "1"))
                if (string.IsNullOrEmpty(param["phone"].ToString()) || (param["flag_nl"].ToString() != "0" && param["flag_nl"].ToString() != "1"))
                {
                    res.State   = ServiceState.Fail;
                    res.Message = ServiceFailCode.A0006;
                    return(res);
                }
                #endregion
                #region 参数处理
                param.Add("id_shop_create", param["id_shop"].ToString());
                param.Add("MMno", param["mmno"].ToString());
                param.Remove("mmno");

                if (!param.ContainsKey("rq_b"))
                {
                    param.Add("rq_b", DateTime.Now.ToString("yyyy-MM-dd 00:00:01"));
                }
                if (!param.ContainsKey("rq_e"))
                {
                    param.Add("rq_e", DateTime.Parse(param["rq_b"].ToString()).AddYears(1).ToString("yyyy-MM-dd 23:59:59"));
                }
                if (!param.ContainsKey("flag_nl"))
                {
                    param.Add("flag_nl", "0");
                }
                if (!param.ContainsKey("flag_sex"))
                {
                    param.Add("flag_sex", "1");
                }


                if (!param.ContainsKey("zk") || !param.ContainsKey("flag_yhlx"))
                {
                    Hashtable ht_hyfl = new Hashtable();
                    ht_hyfl.Add("id", param["id_hyfl"].ToString());
                    var hyflBr = BusinessFactory.Tb_Hyfl.Get(ht_hyfl);
                    if (!hyflBr.Success || hyflBr.Data == null)
                    {
                        res.State   = ServiceState.Fail;
                        res.Message = "操作失败 查询会员类别失败!";
                        return(res);
                    }

                    Tb_Hyfl hyflModel = (Tb_Hyfl)hyflBr.Data;
                    if (hyflModel == null || string.IsNullOrEmpty(hyflModel.id))
                    {
                        res.State   = ServiceState.Fail;
                        res.Message = "操作失败 会员类别不存在!";
                        return(res);
                    }

                    if (!param.ContainsKey("zk"))
                    {
                        param.Add("zk", hyflModel.zk);
                    }
                    if (!param.ContainsKey("flag_yhlx"))
                    {
                        param.Add("flag_yhlx", hyflModel.flag_yhlx);
                    }
                }

                #endregion
                #region 计算生日
                if (!string.IsNullOrEmpty(param["birthday"].ToString()))
                {
                    //计算生日
                    DateTime birthday = DateTime.Parse(param["birthday"].ToString());
                    string hysr       = birthday.ToString("MMdd");
                    if (param.ContainsKey("hysr"))
                    {
                        param.Remove("hysr");
                    }
                    param.Add("hysr", hysr);
                }
                else
                {
                    if (!string.IsNullOrEmpty(param["hysr"].ToString()))
                    {
                        var hysr = param["hysr"].ToString();
                        if (hysr.Length != 4)
                        {
                            res.State   = ServiceState.Fail;
                            res.Message = ServiceFailCode.A0006;
                            return(res);
                        }
                        else
                        {
                            var month = hysr.Substring(0, 2);
                            var day   = hysr.Substring(2, 2);
                            if (!this.CheckMonthDay(month, day))
                            {
                                res.State   = ServiceState.Fail;
                                res.Message = ServiceFailCode.A0006;
                                return(res);
                            }
                        }
                    }
                }
                #endregion
                #region 判断是否共享的处理
                var br_Hy_ShopShare = BusinessFactory.Account.GetHy_ShopShare(param["id_shop_create"].ToString(), param["id_masteruser"].ToString()); //GetHy_ShopShare(param["id_shop_create"].ToString(), param["id_masteruser"].ToString());
                if (!br_Hy_ShopShare.Success)
                {
                    res.State   = ServiceState.Fail;
                    res.Message = br_Hy_ShopShare.Message.FirstOrDefault();
                    return(res);
                }
                var param_Hy_ShopShare = (Hashtable)br_Hy_ShopShare.Data;
                param["id_shop"]       = param_Hy_ShopShare["id_shop"].ToString();
                #endregion
                #region 新增
                var br = BusinessFactory.Tb_Hy_Shop.Add(param);
                #endregion
                #region 返回
                res.State   = br.Success ? ServiceState.Done : ServiceState.Fail;
                res.Message = br.Message.FirstOrDefault();
                res.Data    = br.Data;
                return(res);

                #endregion
            });

            return(JsonString(sr));
        }