/// <summary> /// 获取结果(Post方式) /// </summary> /// <returns></returns> public static ResultModel Post(string url, string post, string resultKey = null, string errorKey = null) { JObject postObj = null; if (!VerifyHelper.IsEmpty(post)) { postObj = JsonHelper.Deserialize <JObject>(post); } if (VerifyHelper.IsNull(postObj)) { postObj = new JObject(); } //公共post参数 postObj["AppId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyAppId); postObj["ClientId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyClientId); postObj["Version"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyVersion); postObj["ip"] = BrowserHelper.GetClientIP(); var passport = postObj.GetValue("passport", StringComparison.InvariantCultureIgnoreCase); if (VerifyHelper.IsNull(passport)) { passport = GetTempUserPassport(); } postObj["passport"] = passport; //postObj["culture"] = CommonHelper.GetContext().Culture; //postObj["security"] = "1xxxx"; return(Request(url, JsonHelper.Serialize(postObj), resultKey: resultKey, errorKey: errorKey)); }
/// <summary> /// 获取临时用户登录Passport /// </summary> /// <returns></returns> protected static JObject GetTempUser() { var tempUser = CachingHelper <HttpRuntimeCaching> .Get <JObject>(KeyModel.Cache.DataCenterTempUser); if (VerifyHelper.IsEmpty(tempUser)) { var tempUserAccount = StringHelper.Get(DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyApiTempUser)).Split('|'); if (VerifyHelper.IsEmpty(tempUserAccount)) { throw new DefaultException("数据中心TempUser配置错误"); } var data = new JObject(); data["AppId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyAppId); data["ClientId"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyClientId); data["Version"] = DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyVersion); data["ip"] = BrowserHelper.GetClientIP(); data["Account"] = tempUserAccount.Length > 0 ? tempUserAccount[0] : ""; data["Password"] = tempUserAccount.Length > 1 ? tempUserAccount[1] : ""; var result = Request(DataCenterConfig.GetApiUrl(KeyModel.Config.DataCenter.KeyAccountLogin), JsonHelper.Serialize(data), resultKey: null, errorKey: null); if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功) && !VerifyHelper.IsEmpty(result.Obj)) { tempUser = result.Obj; } } return(VerifyHelper.IsEmpty(tempUser) ? new JObject() : tempUser); }
/// <summary> /// 写请求数据中心日志 /// </summary> protected static void WriteLog() { bool isWriteLog = BoolHelper.Get(DataCenterConfig.GetValue(KeyModel.Config.DataCenter.KeyWriteLog)); //if (BoolHelper.Get(SysModelConfigs.ApiLog.GetSysModelValue())) //{ // Log4NetHelper.Get(EnumHelper.GetName(EnumLogType.ApiLog)).WriteLogAsync(string.Format("--[Request]--\r\n{0}\r\n--[Response]--\r\n{1}\r\n", JsonHelper.Serialize(item), httpResult.Html)); //} }
/// <summary> /// 发送短信 /// </summary> /// <param name="mobile">手机号</param> /// <param name="content">消息内容</param> /// <param name="taskId">发送任务Id</param> /// <returns></returns> public bool SendSms(string mobile, string content, out Guid taskId) { if (VerifyHelper.IsEmpty(mobile) || VerifyHelper.IsEmpty(content)) { throw new DefaultException(EnumResultCode.参数错误, "mobile", "content"); } taskId = Guid.Empty; var model = new { Mobile = mobile, Content = content }; var result = DataCenterHelper.Post(DataCenterConfig.GetApiUrl(KeyModel.Config.DataCenter.KeySmsSend), model); if (result.Code == EnumHelper.GetValue(EnumResultCode.操作成功)) { return(true); } return(false); }