From 9224c8a09aab564127424fcf219640f55780a35d Mon Sep 17 00:00:00 2001 From: zpc Date: Sat, 11 Oct 2025 15:00:21 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B3=A8=E5=86=8C=EF=BC=8C=E7=89=A9=E6=B5=81?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../User/ICoreCmsUserServices.cs | 7 + CoreCms.Net.Model/FromBody/FMLogin.cs | 16 + .../Shop/CoreCmsLogisticsServices.cs | 24 +- .../User/CoreCmsUserServices.cs | 84 +++ .../CoreShop/common/request/http.api.js | 4 + .../coreshop-login-modal.vue | 555 ++++++++++-------- .../Controllers/User/CoreCmsUserController.cs | 6 +- CoreCms.Net.Web.Admin/NLog.config | 2 +- CoreCms.Net.Web.Admin/appsettings.json | 2 +- .../Controllers/UserController.cs | 34 ++ CoreCms.Net.Web.WebApi/Doc.xml | 7 + 11 files changed, 496 insertions(+), 245 deletions(-) diff --git a/CoreCms.Net.IServices/User/ICoreCmsUserServices.cs b/CoreCms.Net.IServices/User/ICoreCmsUserServices.cs index 40f2cbb..46177b2 100644 --- a/CoreCms.Net.IServices/User/ICoreCmsUserServices.cs +++ b/CoreCms.Net.IServices/User/ICoreCmsUserServices.cs @@ -104,6 +104,13 @@ namespace CoreCms.Net.IServices Task SmsLogin(FMWxAccountCreate entity, int loginType = (int) GlobalEnumVars.LoginType.WeChatPhoneNumber, int platform = 1); + /// + /// 手机号密码登录 + /// + /// 登录实体 + /// + Task PasswordLogin(FMPasswordLogin entity); + /// /// 根据条件查询分页数据 diff --git a/CoreCms.Net.Model/FromBody/FMLogin.cs b/CoreCms.Net.Model/FromBody/FMLogin.cs index 4bdaa7d..7b27f9c 100644 --- a/CoreCms.Net.Model/FromBody/FMLogin.cs +++ b/CoreCms.Net.Model/FromBody/FMLogin.cs @@ -30,4 +30,20 @@ namespace CoreCms.Net.Model.FromBody public string password { get; set; } public string repassword { get; set; } } + + /// + /// 手机号密码登录实体 + /// + public class FMPasswordLogin + { + /// + /// 手机号码 + /// + public string mobile { get; set; } + + /// + /// 密码 + /// + public string password { get; set; } + } } \ No newline at end of file diff --git a/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs b/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs index 8c41286..7484c9d 100644 --- a/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs +++ b/CoreCms.Net.Services/Shop/CoreCmsLogisticsServices.cs @@ -12,6 +12,7 @@ using System; using System.Collections.Generic; using System.Linq; using System.Threading.Tasks; + using CoreCms.Net.Configuration; using CoreCms.Net.IRepository; using CoreCms.Net.IRepository.UnitOfWork; @@ -21,8 +22,11 @@ using CoreCms.Net.Model.Entities; using CoreCms.Net.Model.ViewModels.Api; using CoreCms.Net.Model.ViewModels.UI; using CoreCms.Net.Utility.Helper; + using Flurl.Http; +using Qiniu.Util; + namespace CoreCms.Net.Services { @@ -173,17 +177,23 @@ namespace CoreCms.Net.Services var allConfigs = await _settingServices.GetConfigDictionaries(); - var showApiAppid = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowApiAppid); var showApiSecret = CommonHelper.GetConfigDictionary(allConfigs, SystemSettingConstVars.ShowApiSecret); - var showApiTimesTamp = DateTime.Now.ToString("yyyyMMddHHmmss"); + var url = $"https://route.showapi.com/64-19?appKey={showApiSecret}"; + if (phone.Length > 4) + { + phone = phone.Substring(phone.Length - 4, 4); + } + // 构建POST请求参数 + var postData = new + { + com = "auto", // 固定值 + nu = number, // 订单号 + phone = phone // 手机尾号 + }; - var signStr = "com" + com + "nu" + number + "phone" + phone + "showapi_appid" + showApiAppid + "showapi_timestamp" + showApiTimesTamp + showApiSecret; - var md5Sign = CommonHelper.Md5For32(signStr).ToLower(); + var result = await url.PostUrlEncodedAsync(postData).ReceiveJson(); - var url = "https://route.showapi.com/64-19?com=" + com + "&nu=" + number + "&phone=" + phone + "&showapi_appid=" + showApiAppid + - "&showapi_timestamp=" + showApiTimesTamp + "&showapi_sign=" + md5Sign; - var result = await url.GetJsonAsync(); if (result.showapi_res_code != 0) { diff --git a/CoreCms.Net.Services/User/CoreCmsUserServices.cs b/CoreCms.Net.Services/User/CoreCmsUserServices.cs index 452e974..f44b4cd 100644 --- a/CoreCms.Net.Services/User/CoreCmsUserServices.cs +++ b/CoreCms.Net.Services/User/CoreCmsUserServices.cs @@ -641,6 +641,90 @@ namespace CoreCms.Net.Services #endregion + #region 手机号密码登录 + /// + /// 手机号密码登录 + /// + /// 登录实体 + /// + public async Task PasswordLogin(FMPasswordLogin entity) + { + var jm = new WebApiCallBack(); + + if (string.IsNullOrEmpty(entity.mobile)) + { + jm.msg = "请输入手机号码"; + return jm; + } + + if (string.IsNullOrEmpty(entity.password)) + { + jm.msg = "请输入密码"; + return jm; + } + + if (!CommonHelper.IsMobile(entity.mobile)) + { + jm.msg = "请输入合法的手机号码"; + return jm; + } + + // 查询用户是否存在 + var userInfo = await _dal.QueryByClauseAsync(p => p.mobile == entity.mobile); + if (userInfo == null) + { + jm.msg = "用户不存在"; + return jm; + } + + // 检查用户状态 + if (userInfo.status != (int)GlobalEnumVars.UserStatus.正常) + { + jm.msg = "用户账户已被禁用"; + return jm; + } + + // 检查用户是否设置了密码 + if (string.IsNullOrEmpty(userInfo.passWord)) + { + jm.msg = "该账户未设置密码,请使用其他方式登录"; + return jm; + } + + // 验证密码 + var encryptedPassword = CommonHelper.EnPassword(entity.password, userInfo.createTime); + if (userInfo.passWord != encryptedPassword) + { + jm.msg = "密码错误"; + return jm; + } + + // 登录成功,生成JWT Token + var claims = new List { + new Claim(ClaimTypes.Name, userInfo.nickName), + new Claim(JwtRegisteredClaimNames.Jti, userInfo.id.ToString()), + new Claim(ClaimTypes.Expiration, DateTime.Now.AddSeconds(_permissionRequirement.Expiration.TotalSeconds).ToString()) }; + + //用户标识 + var identity = new ClaimsIdentity(JwtBearerDefaults.AuthenticationScheme); + identity.AddClaims(claims); + jm.status = true; + jm.msg = "登录成功"; + jm.data = JwtToken.BuildJwtToken(claims.ToArray(), _permissionRequirement); + + //录入登录日志 + var log = new CoreCmsUserLog(); + log.userId = userInfo.id; + log.state = (int)GlobalEnumVars.UserLogTypes.登录; + log.ip = _httpContextAccessor.HttpContext?.Connection.RemoteIpAddress != null ? + _httpContextAccessor.HttpContext.Connection.RemoteIpAddress.MapToIPv4().ToString() : "127.0.0.1"; + log.createTime = DateTime.Now; + log.parameters = GlobalEnumVars.UserLogTypes.登录.ToString(); + await _userLogServices.InsertAsync(log); + + return jm; + } + #endregion /// /// 根据条件查询分页数据 diff --git a/CoreCms.Net.Uni-App/CoreShop/common/request/http.api.js b/CoreCms.Net.Uni-App/CoreShop/common/request/http.api.js index 4cba1e1..0ea6594 100644 --- a/CoreCms.Net.Uni-App/CoreShop/common/request/http.api.js +++ b/CoreCms.Net.Uni-App/CoreShop/common/request/http.api.js @@ -222,6 +222,9 @@ const install = (Vue, vm) => { let syncWeChatInfo = (params = {}) => vm.$u.post('/Api/User/SyncWeChatInfo', params, { method: 'user.SyncWeChatInfo', needToken: true }); //小程序手机授权(拉取手机号码) let loginByGetPhoneNumber = (params = {}) => vm.$u.post('/Api/User/DecryptPhoneNumber', params, { method: 'user.wxapploginByGetPhoneNumber', needToken: false }); + //账号密码登录 + let loginByPassword = (params = {}) => vm.$u.post('/Api/User/PasswordLogin', params, { method: 'user.wxapploginByPassword', needToken: false }); + //取下级地址列表 let getAreaList = (params = {}) => vm.$u.post('/Api/Common/GetAreas', params, { method: 'user.getarealist', needToken: false }); //取搜索页推荐关键字 @@ -490,6 +493,7 @@ const install = (Vue, vm) => { loginByDecodeEncryptedData, syncWeChatInfo, loginByGetPhoneNumber, + loginByPassword, getAreaList, getRecommendKeys, myInvite, diff --git a/CoreCms.Net.Uni-App/CoreShop/components/coreshop-login-modal/coreshop-login-modal.vue b/CoreCms.Net.Uni-App/CoreShop/components/coreshop-login-modal/coreshop-login-modal.vue index 8e0a050..aa0bcec 100644 --- a/CoreCms.Net.Uni-App/CoreShop/components/coreshop-login-modal/coreshop-login-modal.vue +++ b/CoreCms.Net.Uni-App/CoreShop/components/coreshop-login-modal/coreshop-login-modal.vue @@ -10,20 +10,27 @@ - {{shopName||'登录授权'}} - - - 申请 + {{ shopName || '用户登录' }} - 获取以下权限为您提供服务 - - 1、获取你的手机号提供更好的账户安全,物流,订单状态提醒等服务(在接下来微信授权手机号的弹窗中选择“允许”)
- 2、使用我们的相关服务,需要将您的手机号授权给我们。 + 请输入您的账号密码 + + + + - + 同意 《服务协议》 @@ -33,9 +40,10 @@ - 暂不授权 - 确定授权 - 确定授权 + 取消 + 登录 + 登录
@@ -44,239 +52,318 @@ diff --git a/CoreCms.Net.Web.Admin/Controllers/User/CoreCmsUserController.cs b/CoreCms.Net.Web.Admin/Controllers/User/CoreCmsUserController.cs index 2c3a442..1be7bb0 100644 --- a/CoreCms.Net.Web.Admin/Controllers/User/CoreCmsUserController.cs +++ b/CoreCms.Net.Web.Admin/Controllers/User/CoreCmsUserController.cs @@ -31,6 +31,8 @@ using Microsoft.AspNetCore.Mvc; using NPOI.HSSF.UserModel; using SqlSugar; +using static SKIT.FlurlHttpClient.Wechat.Api.Models.WeDataQueryBindListResponse.Types; + namespace CoreCms.Net.Web.Admin.Controllers { /// @@ -410,7 +412,8 @@ namespace CoreCms.Net.Web.Admin.Controllers //事物处理过程开始 - if (!string.IsNullOrEmpty(entity.passWord)) oldModel.passWord = CommonHelper.Md5For32(entity.passWord); + if (!string.IsNullOrEmpty(entity.passWord)) oldModel.passWord = CommonHelper.EnPassword(entity.passWord, oldModel.createTime); + //CommonHelper.Md5For32(entity.passWord); oldModel.mobile = entity.mobile; oldModel.sex = entity.sex; oldModel.birthday = entity.birthday; @@ -423,7 +426,6 @@ namespace CoreCms.Net.Web.Admin.Controllers var bl = await _coreCmsUserServices.UpdateAsync(oldModel); jm.code = bl ? 0 : 1; jm.msg = bl ? GlobalConstVars.EditSuccess : GlobalConstVars.EditFailure; - return jm; } diff --git a/CoreCms.Net.Web.Admin/NLog.config b/CoreCms.Net.Web.Admin/NLog.config index 4f57dd7..fe6ca4c 100644 --- a/CoreCms.Net.Web.Admin/NLog.config +++ b/CoreCms.Net.Web.Admin/NLog.config @@ -14,7 +14,7 @@ dbProvider="Microsoft.Data.SqlClient.SqlConnection, Microsoft.Data.SqlClient" connectionString="Server=127.0.0.1;Database=BaseMIS;User ID=sa;Password=123456" --> - + INSERT INTO SysNLogRecords (LogDate,LogLevel,LogType,LogTitle,Logger,Message,MachineName,MachineIp,NetRequestMethod diff --git a/CoreCms.Net.Web.Admin/appsettings.json b/CoreCms.Net.Web.Admin/appsettings.json index e842a13..f8187c3 100644 --- a/CoreCms.Net.Web.Admin/appsettings.json +++ b/CoreCms.Net.Web.Admin/appsettings.json @@ -1,7 +1,7 @@ { "ConnectionStrings": { "DbType": "SqlServer", //数据库将支持两种模式【SqlServer,MySql】 - "SqlConnection": "Server=192.168.195.8;uid=sa;pwd=Dbt@com@123;Database=CoreShop;MultipleActiveResultSets=true;pooling=true;min pool size=5;max pool size=32767;connect timeout=20;Encrypt=True;TrustServerCertificate=True;" + "SqlConnection": "Server=192.168.195.8;uid=sa;pwd=Dbt@com@123;Database=Shop;MultipleActiveResultSets=true;pooling=true;min pool size=5;max pool size=32767;connect timeout=20;Encrypt=True;TrustServerCertificate=True;" //SqlServer数据库连接字符串,需要开启数据库连接复用【MultipleActiveResultSets=true】 // 如果采用容器化部署Service 要写成mysql的服务名,否则写地址 diff --git a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs index 54594a7..32ad63b 100644 --- a/CoreCms.Net.Web.WebApi/Controllers/UserController.cs +++ b/CoreCms.Net.Web.WebApi/Controllers/UserController.cs @@ -431,6 +431,40 @@ namespace CoreCms.Net.Web.WebApi.Controllers #endregion + #region 手机号密码登录=================================================================== + /// + /// 手机号密码登录 + /// + /// + /// + [HttpPost] + public async Task PasswordLogin([FromBody] FMPasswordLogin entity) + { + var jm = new WebApiCallBack(); + + if (string.IsNullOrEmpty(entity.mobile)) + { + jm.msg = "请输入手机号码"; + return jm; + } + + if (string.IsNullOrEmpty(entity.password)) + { + jm.msg = "请输入密码"; + return jm; + } + + if (!CommonHelper.IsMobile(entity.mobile)) + { + jm.msg = "请输入合法的手机号码"; + return jm; + } + + jm = await _userServices.PasswordLogin(entity); + return jm; + } + #endregion + #region 用户短信注册并返回jwt token(弃用)====================================================== /// /// 用户短信注册并返回jwt token(弃用) diff --git a/CoreCms.Net.Web.WebApi/Doc.xml b/CoreCms.Net.Web.WebApi/Doc.xml index b88829f..bd67715 100644 --- a/CoreCms.Net.Web.WebApi/Doc.xml +++ b/CoreCms.Net.Web.WebApi/Doc.xml @@ -897,6 +897,13 @@ + + + 手机号密码登录 + + + + 用户短信注册并返回jwt token(弃用)