/// <summary> /// 获取验证码 /// </summary> /// <param name="uniacid">商户ID</param> /// <param name="phoneNumber">手机号码</param> /// <returns></returns> public IActionResult GetSmsVerifyCode(string uniacid, string phoneNumber) { var filter = Builders <VerifyCodeModel> .Filter; var mongo = new MongoDBTool(); var company = mongo.GetMongoCollection <CompanyModel>().Find(x => x.uniacid.Equals(uniacid)).FirstOrDefault(); if (company == null || company.YTX == null) { var em = new ExceptionModel() { Content = "商户未设置云通信信息" }; em.Save(); return(this.JsonErrorStatus()); } var collection = mongo.GetMongoCollection <VerifyCodeModel>(); var date = DateTime.Now.AddMinutes(VerifyTimeOut); collection.DeleteMany(filter.Lt(x => x.CreateTime, date) & filter.Eq(x => x.uniacid, uniacid)); var filterSum = filter.Eq(x => x.PhoneNumber, phoneNumber) & filter.Gt(x => x.CreateTime, date); VerifyCodeModel vcm = collection.FindOneAndDelete(filterSum); if (vcm == null) { vcm = new VerifyCodeModel() { PhoneNumber = phoneNumber, CreateTime = DateTime.Now, uniacid = uniacid }; } string jsonData = JsonConvert.SerializeObject(new SMSModel() { appid = company.YTX.AppID, mobile = vcm.PhoneNumber, datas = new string[] { vcm.VerifyCode, VerifyTimeOut + "" } }); string url = "/sms/TemplateSMS.wx"; string result = new PhoneHelper(company.YTX).SendRequest(url, jsonData); var jObj = (JObject)JsonConvert.DeserializeObject(result); JToken statuscode; bool hasVal = jObj.TryGetValue("statusCode", out statuscode); if (hasVal && statuscode.ToString().Equals("0")) { collection.InsertOne(vcm); return(this.JsonErrorStatus()); } return(this.JsonErrorStatus()); }
public string RequestCreateJackPot(string accountID, string goodsID) { var mongo = new MongoDBTool(); var accountFilter = Builders <AccountModel> .Filter.Eq(x => x.AccountID, new ObjectId(accountID)); var goodsFilter = Builders <GoodsModel> .Filter.Eq(x => x.GoodsID, new ObjectId(goodsID)); var account = mongo.GetMongoCollection <AccountModel>().Find(accountFilter).FirstOrDefault(); var goods = mongo.GetMongoCollection <GoodsModel>().Find(goodsFilter).FirstOrDefault(); JsApiPay jsApiPay = new JsApiPay(); jsApiPay.openid = account.OpenID; jsApiPay.total_fee = goods.GoodsPrice; var body = "test"; var attach = "test"; var goods_tag = goods.GoodsTitle; jsApiPay.GetUnifiedOrderResult(body, attach, goods_tag); return(jsApiPay.GetJsApiParameters()); }
/// <summary> /// 头像上传 /// </summary> /// <param name="openId"></param> /// <returns></returns> public string UploadAvatar(string accountID) { BaseResponseModel <String> responseModel = new BaseResponseModel <String>(); if (string.IsNullOrEmpty(accountID)) { responseModel.StatusCode = (int)ActionParams.code_error_null; responseModel.JsonData = $@"参数:openId:{accountID}"; return(JsonConvert.SerializeObject(responseModel)); } long size = 0; var files = Request.Form.Files; try { foreach (var file in files) { var filename = ContentDispositionHeaderValue .Parse(file.ContentDisposition) .FileName .Trim('"'); string saveDir = $@"{ConstantProperty.BaseDir}{ConstantProperty.AvatarDir}"; if (!Directory.Exists(saveDir)) { Directory.CreateDirectory(saveDir); } filename = filename.Substring(filename.LastIndexOf(".")); string saveName = ConstantProperty.AvatarDir + $@"{accountID}{filename}"; filename = ConstantProperty.BaseDir + saveName; size += file.Length; using (FileStream fs = System.IO.File.Create(filename)) { file.CopyTo(fs); fs.Flush(); var filter = Builders <AccountModel> .Filter.Eq(x => x.AccountID, new ObjectId(accountID)); var update = Builders <AccountModel> .Update.Set(x => x.AccountAvatar, saveName); var dbTool = new MongoDBTool(); dbTool.GetMongoCollection <AccountModel>().UpdateOne(filter, update); } } responseModel.StatusCode = (int)ActionParams.code_ok; } catch (Exception) { responseModel.StatusCode = (int)ActionParams.code_error; throw; } return(JsonConvert.SerializeObject(responseModel)); }
/// <summary> /// 微信支付成功返回数据 /// </summary> /// <param name="data"></param> private void OnPaySuccess(WxPayData data) { var attach = (string)data.GetValue("attach"); var wxOrderId = (string)data.GetValue("transaction_id"); if (string.IsNullOrEmpty(attach)) { var em = new ExceptionModel() { Content = "微信支付返回:attach为空" }; em.Save(); throw em; } if (string.IsNullOrEmpty(wxOrderId)) { var em = new ExceptionModel() { Content = "微信支付返回:微信订单号为空" }; em.Save(); throw em; } string[] aa = attach.Split(','); string uniacid = aa[0]; string accountID = aa[1]; string orderID = aa[2]; var mongo = new MongoDBTool(); var accountCollection = mongo.GetMongoCollection <AccountModel>(); var filter = Builders <AccountModel> .Filter; var filterSum = filter.Eq(x => x.AccountID, new ObjectId(accountID)) & filter.Eq("Orders.OrderID", new ObjectId(orderID)); var account = accountCollection.Find(filterSum).FirstOrDefault(); var wcOrder = account.Orders.Find(x => x.OrderID.Equals(new ObjectId(orderID)) && !x.IsPaid); if (wcOrder == null) { var em = new ExceptionModel() { Content = "微信支付返回:订单不存在或者已经生成" }; em.Save(); throw em; } var update = Builders <AccountModel> .Update .Set("Orders.$.WeChatOrderID", wxOrderId) .Set("Orders.$.IsPaid", true); accountCollection.UpdateOne(filterSum, update); }
public IActionResult CallMany() { var mongo = new MongoDBTool(); var company = mongo.GetMongoCollection <CompanyModel>().Find(x => x.uniacid.Equals("24")).FirstOrDefault(); if (company == null || company.YTX == null) { var em = new ExceptionModel() { Content = "商户未设置云通信信息" }; em.Save(); return(this.JsonErrorStatus()); } string jsonData = JsonConvert.SerializeObject(new MeetingPhoneModel() { appid = company.YTX.AppID, creator = "15501022450", meetingname = "ceshi", parties = new Party[] { new Party() { name = "22", phone = "13245437784" } } } ); string url = "/call/TeleMeeting.wx"; string result = new PhoneHelper(company.YTX).SendRequest(url, jsonData); var jObj = (JObject)JsonConvert.DeserializeObject(result); JToken statuscode; bool hasVal = jObj.TryGetValue("statusCode", out statuscode); if (hasVal && statuscode.ToString().Equals("0")) { return(this.JsonSuccessStatus()); } return(this.JsonErrorStatus()); }
protected BaseData(string collectionName) { mongo = new MongoDBTool(); mongoDB = mongo.GetMongoDatabase(); collection = mongo.GetMongoCollection <T>(collectionName); }
protected BaseData() { mongo = new MongoDBTool(); mongoDB = mongo.GetMongoDatabase(); collection = mongo.GetMongoCollection <T>(); }
/// <summary> /// 微信支付成功返回数据 /// </summary> /// <param name="data"></param> private void OnPaySuccess(WxPayData data) { var attach = (string)data.GetValue("attach"); var wxOrderId = (string)data.GetValue("transaction_id"); if (string.IsNullOrEmpty(attach)) { var em = new ExceptionModel() { Content = "微信支付返回:attach为空" }; em.Save(); throw em; } if (string.IsNullOrEmpty(wxOrderId)) { var em = new ExceptionModel() { Content = "微信支付返回:微信订单号为空" }; em.Save(); throw em; } string[] aa = attach.Split(','); string accountID = aa[1]; string orderID = aa[2]; var mongo = new MongoDBTool(); var accountCollection = mongo.GetMongoCollection <AccountModel>(); var filter = Builders <AccountModel> .Filter; var filterSum = filter.Eq(x => x.AccountID, new ObjectId(accountID)) & filter.Eq("WeChatOrders.WeChatOrderID", new ObjectId(orderID)); var account = accountCollection.Find(filterSum).FirstOrDefault(); var wcOrder = account.WeChatOrders.Find(x => x.WeChatOrderID.Equals(new ObjectId(orderID)) && x.WXOrderId == null); if (wcOrder == null) { var em = new ExceptionModel() { Content = "微信支付返回:订单不存在或者已经生成" }; em.Save(); throw em; } var update = Builders <AccountModel> .Update .Set("WeChatOrders.$.WXOrderId", wxOrderId) .Set(x => x.Balances, account.Balances + wcOrder.Total); if (wcOrder.VoicePackets != null) { var ad = new AccountData(); var serviceMoney = ad.GetServiceMoney(account.uniacid, wcOrder.VoicePackets.Amount); var balance = account.Balances + wcOrder.Total; balance = balance - (wcOrder.VoicePackets.Amount + serviceMoney); if (balance >= 0) { update = Builders <AccountModel> .Update.Set("WeChatOrders.$.WXOrderId", wxOrderId); ad.CreateVoicePackets(account, wcOrder.VoicePackets, serviceMoney, balance); } } accountCollection.UpdateOne(filterSum, update); }