private static UserRegLoginResp GenerateUserToken(ResultMo <UserInfoMo> userRes) { if (!userRes.IsSuccess()) { return(userRes.ConvertToResult <UserRegLoginResp>()); } var tokenRes = MemberTokenUtil.AppendToken(MemberShiper.AppAuthorize.AppSource, userRes.data.Id, MemberAuthorizeType.User); return(tokenRes.IsSuccess() ? new UserRegLoginResp() { token = tokenRes.data, user = userRes.data } : tokenRes.ConvertToResult <UserRegLoginResp>()); }
/// <summary> /// 验证回调接口签名 /// </summary> /// <param name="formDics">表单的字典值</param> /// <returns></returns> public ResultMo CheckCallBackSign(IDictionary <string, string> formDics) { var sign = formDics["sign"]; var signType = formDics["sign_type"]; formDics.Remove("sign"); //formDics.Remove("sign_type"); var sortDics = new SortedDictionary <string, string>(formDics); var checkContent = string.Join("&", sortDics.Select(d => string.Concat(d.Key, "=", d.Value.UrlDecode()))); var result = new ResultMo(); CheckSign(checkContent, sign, result); return(result); }
/// <summary> /// 验证回调接口签名 /// </summary> /// <param name="formDics">表单的字典值</param> /// <returns></returns> public ResultMo CheckCallBackSign(IDictionary <string, string> formDics) { if (!formDics.ContainsKey("sign")) { return(new ResultMo(ResultTypes.ParaError, "未发现sign参数")); } var sign = formDics["sign"]; //var signType = formDics["sign_type"]; formDics.Remove("sign"); formDics.Remove("sign_type"); var sortDics = new SortedDictionary <string, string>(formDics); var checkContent = string.Join("&", sortDics.Select(d => string.Concat(d.Key, "=", d.Value.UrlDecode()))); var result = new ResultMo(); CheckSign(checkContent, sign, result); return(result); }
/// <summary> /// 设置字典配置信息 /// </summary> /// <typeparam name="TConfig"></typeparam> /// <param name="key"></param> /// <param name="dirConfig"></param> /// <returns></returns> public ResultMo SetDirConfig <TConfig>(string key, TConfig dirConfig) where TConfig : class, new() { if (string.IsNullOrEmpty(key)) { throw new ArgumentNullException("key", "配置键值不能为空!"); } if (dirConfig == null) { throw new ArgumentNullException("dirConfig", "配置信息不能为空!"); } string path = string.Concat(_defaultPath, "\\", "Config"); ResultMo result; FileStream fs = null; try { if (!Directory.Exists(path)) { Directory.CreateDirectory(path); } fs = new FileStream(string.Concat(path, "\\", key, ".config"), FileMode.Create, FileAccess.Write); var type = typeof(TConfig); var xmlSer = new XmlSerializer(type); xmlSer.Serialize(fs, dirConfig); result = new ResultMo(); } finally { fs?.Dispose(); } return(result); }
private static void ReponseEnd(ResultMo res, AuthorizationFilterContext context) { if (IsAjax(context.HttpContext)) { context.Result = new JsonResult(res); } else { if (res.IsResultType(ResultTypes.UnAuthorize)) { var rUrl = string.Concat(context.HttpContext.Request.Path, "?", context.HttpContext.Request.QueryString); var url = string.Concat(loginUrl, "?rurl=" + rUrl.UrlEncode()); context.Result = new RedirectResult(url ?? "/"); } else { context.Result = new RedirectResult(string.Concat("/un/error?ret=", res.ret, "&message=", res.msg)); } } }
private static void ReponseEnd(ResultMo res, AuthorizationFilterContext context) { if (IsAjax(context.HttpContext)) { context.Result = new JsonResult(res); } else { if (res.IsResultType(ResultTypes.UnAuthorize)) { var rUrl = string.Concat(context.HttpContext.Request.Path, context.HttpContext.Request.QueryString); context.HttpContext.Response.Cookies.Append(GlobalKeysUtil.UserReturnUrlCookieName, rUrl); context.Result = new RedirectResult(loginUrl ?? "/"); } else { context.Result = new RedirectResult(string.Concat("/un/error?ret=", res.ret, "&message=", res.msg)); } } }
/// <summary> /// 接受微信支付通知后需要返回的信息 /// </summary> /// <param name="res"></param> /// <returns></returns> public string GetCallBackReturnXml(ResultMo res) { return(string.Format($"<xml><return_code><![CDATA[{ (res.IsSuccess() ? "SUCCESS" : "FAIL")}]]></return_code><return_msg><![CDATA[{ res.msg}]]></return_msg></xml>")); }
/// <summary> /// 结果类直接转化为 异常结果实例 /// </summary> /// <param name="res"></param> /// <returns></returns> public static ResultException ConvertToException(this ResultMo res) { return(new ResultException(res.sys_ret, res.ret, res.msg)); }
/// <summary> /// 结束请求 /// </summary> /// <param name="context"></param> /// <param name="res"></param> /// <returns></returns> protected static async Task ResponseEnd(HttpContext context, ResultMo res) { ClearCacheHeaders(context.Response); context.Response.ContentType = "application/json;charset=utf-8"; await context.Response.WriteAsync($"{{\"Ret\":{res.Ret},\"Message\":\"{res.Message}\"}}"); }
/// <summary> /// 接受微信支付通知后需要返回的信息 /// </summary> /// <param name="res"></param> /// <returns></returns> public string GetTradeSendXml(ResultMo res) { return ($"<xml><return_code><![CDATA[{(res.IsSuccess ? "Success" : "FAIL")}]]></return_code><return_msg><![CDATA[{res.Message}]]></return_msg></xml>"); }
/// <summary> /// 【系统结果】是否是对应的类型 /// </summary> /// <param name="res"></param> /// <param name="type"></param> /// <returns></returns> public static bool IsSysResultType(this ResultMo res, SysResultTypes type) => res.sys_ret == (int)type;
/// <summary> /// 【系统结果】xi /// </summary> /// <param name="res"></param> /// <returns></returns> public static bool IsSysOk(this ResultMo res) => res.sys_ret == 0;
/// <summary> /// 【业务结果】是否是对应的类型 /// </summary> /// <param name="res"></param> /// <param name="type"></param> /// <returns></returns> public static bool IsResultType(this ResultMo res, ResultTypes type) => res.ret == (int)type;
/// <summary> /// 【业务结果】是否是Success /// </summary> /// <param name="res"></param> /// <returns></returns> public static bool IsSuccess(this ResultMo res) => res.ret == 0;
/// <summary> /// 接受微信支付通知后需要返回的信息 /// </summary> /// <param name="res"></param> /// <returns></returns> public string GetTradeSendXml(ResultMo res) { return ($"<xml><return_code><![CDATA[{(res.IsSuccess() ? "SUCCESS" : "FAIL")}]]></return_code><return_msg><![CDATA[{res.msg}]]></return_msg></xml>"); }