@@ -8,6 +8,10 @@ using System.IO; | |||
using System.Web.Mvc; | |||
using Learun.Application.WebApi.Modules; | |||
using System.Linq; | |||
using System.Net; | |||
using Learun.Cache.Base; | |||
using Learun.Cache.Factory; | |||
using Nancy.Responses; | |||
namespace Learun.Application.WebApi | |||
{ | |||
@@ -22,6 +26,7 @@ namespace Learun.Application.WebApi | |||
{ | |||
private SunshineEducationIBLL sunshineEducationIBLL = new SunshineEducationBLL(); | |||
private AnnexesFileIBLL annexesFileIBLL = new AnnexesFileBLL(); | |||
private ICache redisCache = CacheFactory.CaChe(); | |||
/// <summary> | |||
/// 阳光教育 | |||
@@ -38,9 +43,67 @@ namespace Learun.Application.WebApi | |||
Post["/upload"] = Upload; | |||
Post["/save"] = SaveForm;//提交,回复,评论 | |||
Post["/clicks"] = ClicksForm; | |||
Get["/getverifycode"] = GetVerifyCode; | |||
Post["/checkverifycode"] = CheckVerifyCode; | |||
} | |||
#region 获取数据 | |||
/// <summary> | |||
/// 检查图形验证码并发送短信验证码 | |||
/// </summary> | |||
/// <param name="_"></param> | |||
/// <returns></returns> | |||
public Response CheckVerifyCode(dynamic _) | |||
{ | |||
MobileVerify mobileVerify = this.GetReqData<MobileVerify>(); | |||
var code = redisCache.Read<string>("sunshineimgvcode" + mobileVerify.pagecode); | |||
if (!string.IsNullOrEmpty(code) && code == mobileVerify.verifycode) | |||
{ | |||
//发送短信 | |||
return Success("短信验证码已成功发送。"); | |||
} | |||
else | |||
{ | |||
return Fail("验证失败,验证码错误或已失效。"); | |||
} | |||
} | |||
/// <summary> | |||
/// 获取图形验证码 | |||
/// </summary> | |||
/// <param name="_">页面编号</param> | |||
/// <returns></returns> | |||
public Response GetVerifyCode(dynamic _) | |||
{ | |||
string pagecode = this.GetReqData(); | |||
return new StreamResponse(() => GetImgVerifyCode(pagecode), "image/Gif"); | |||
} | |||
public Stream GetImgVerifyCode(string pagecode) | |||
{ | |||
MemoryStream ms = null; | |||
try | |||
{ | |||
(byte[] buffer,string code) = new VerifyCode().GetVerifyCodeForMobileApi(); | |||
redisCache.Write<string>("sunshineimgvcode" + pagecode, code, new TimeSpan(0, 5, 0)); | |||
ms = new MemoryStream(buffer); | |||
return ms; | |||
} | |||
catch (Exception e) | |||
{ | |||
return null; | |||
} | |||
//finally | |||
//{ | |||
// if (ms != null) | |||
// { | |||
// ms.Close(); | |||
// ms.Dispose(); | |||
// } | |||
//} | |||
} | |||
/// <summary> | |||
/// 获取页面显示列表分页数据 | |||
/// <summary> | |||
@@ -248,6 +311,12 @@ namespace Learun.Application.WebApi | |||
public string keyValue { get; set; } | |||
public string strEntity { get; set; } | |||
} | |||
public class MobileVerify | |||
{ | |||
public string mobile { get; set; } | |||
public string verifycode { get; set; } | |||
public string pagecode { get;set; } | |||
} | |||
#endregion | |||
} |
@@ -20,6 +20,14 @@ | |||
<assemblyIdentity name="System.Text.Json" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |||
<bindingRedirect oldVersion="0.0.0.0-6.0.0.0" newVersion="6.0.0.0" /> | |||
</dependentAssembly> | |||
<dependentAssembly> | |||
<assemblyIdentity name="System.Numerics.Vectors" publicKeyToken="b03f5f7f11d50a3a" culture="neutral" /> | |||
<bindingRedirect oldVersion="0.0.0.0-4.1.4.0" newVersion="4.1.4.0" /> | |||
</dependentAssembly> | |||
<dependentAssembly> | |||
<assemblyIdentity name="System.Buffers" publicKeyToken="cc7b13ffcd2ddd51" culture="neutral" /> | |||
<bindingRedirect oldVersion="0.0.0.0-4.0.3.0" newVersion="4.0.3.0" /> | |||
</dependentAssembly> | |||
</assemblyBinding> | |||
</runtime> | |||
<entityFramework> | |||
@@ -75,6 +75,9 @@ | |||
<Reference Include="System.Core" /> | |||
<Reference Include="System.Drawing" /> | |||
<Reference Include="System.Net.Http" /> | |||
<Reference Include="System.ValueTuple, Version=4.0.3.0, Culture=neutral, PublicKeyToken=cc7b13ffcd2ddd51, processorArchitecture=MSIL"> | |||
<HintPath>..\..\..\packages\System.ValueTuple.4.5.0\lib\net461\System.ValueTuple.dll</HintPath> | |||
</Reference> | |||
<Reference Include="System.Web" /> | |||
<Reference Include="System.Xml.Linq" /> | |||
<Reference Include="System.Data.DataSetExtensions" /> | |||
@@ -77,5 +77,63 @@ namespace Learun.Util | |||
bmp.Dispose(); | |||
} | |||
} | |||
public (byte[],string) GetVerifyCodeForMobileApi() | |||
{ | |||
int codeW = 80; | |||
int codeH = 30; | |||
int fontSize = 16; | |||
string chkCode = string.Empty; | |||
//颜色列表,用于验证码、噪线、噪点 | |||
Color[] color = { Color.Black, Color.Red, Color.Blue, Color.Green, Color.Orange, Color.Brown, Color.Brown, Color.DarkBlue }; | |||
//字体列表,用于验证码 | |||
string[] font = { "Times New Roman" }; | |||
//验证码的字符集,去掉了一些容易混淆的字符 | |||
char[] character = { '2', '3', '4', '5', '6', '8', '9', 'a', 'b', 'd', 'e', 'f', 'h', 'k', 'm', 'n', 'r', 'x', 'y', 'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'J', 'K', 'L', 'M', 'N', 'P', 'R', 'S', 'T', 'W', 'X', 'Y' }; | |||
Random rnd = new Random(); | |||
//生成验证码字符串 | |||
for (int i = 0; i < 4; i++) | |||
{ | |||
chkCode += character[rnd.Next(character.Length)]; | |||
} | |||
//创建画布 | |||
Bitmap bmp = new Bitmap(codeW, codeH); | |||
Graphics g = Graphics.FromImage(bmp); | |||
g.Clear(Color.White); | |||
//画噪线 | |||
for (int i = 0; i < 1; i++) | |||
{ | |||
int x1 = rnd.Next(codeW); | |||
int y1 = rnd.Next(codeH); | |||
int x2 = rnd.Next(codeW); | |||
int y2 = rnd.Next(codeH); | |||
Color clr = color[rnd.Next(color.Length)]; | |||
g.DrawLine(new Pen(clr), x1, y1, x2, y2); | |||
} | |||
//画验证码字符串 | |||
for (int i = 0; i < chkCode.Length; i++) | |||
{ | |||
string fnt = font[rnd.Next(font.Length)]; | |||
Font ft = new Font(fnt, fontSize); | |||
Color clr = color[rnd.Next(color.Length)]; | |||
g.DrawString(chkCode[i].ToString(), ft, new SolidBrush(clr), (float)i * 18, (float)0); | |||
} | |||
//将验证码图片写入内存流,并将其以 "image/Png" 格式输出 | |||
MemoryStream ms = new MemoryStream(); | |||
try | |||
{ | |||
bmp.Save(ms, ImageFormat.Png); | |||
return (ms.ToArray(), chkCode); | |||
} | |||
catch (Exception) | |||
{ | |||
return (null,""); | |||
} | |||
finally | |||
{ | |||
g.Dispose(); | |||
bmp.Dispose(); | |||
} | |||
} | |||
} | |||
} |
@@ -7,6 +7,7 @@ | |||
<package id="Newtonsoft.Json" version="12.0.1" targetFramework="net461" /> | |||
<package id="NPOI" version="2.3.0" targetFramework="net45" /> | |||
<package id="SharpZipLib" version="0.86.0" targetFramework="net45" /> | |||
<package id="System.ValueTuple" version="4.5.0" targetFramework="net461" /> | |||
<package id="ThoughtWorks.QRCode" version="1.1.0" targetFramework="net461" /> | |||
<package id="YUICompressor.NET" version="2.7.0.0" targetFramework="net45" /> | |||
</packages> |
@@ -1,42 +1,42 @@ | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<?xml version="1.0" encoding="utf-8"?> | |||
<configuration> | |||
<appSettings> | |||
<!--阿里云短信平台参数--> | |||
<add key="product" value="Dysmsapi"/> | |||
<add key="domain" value="dysmsapi.aliyuncs.com"/> | |||
<add key="accessId" value="LTAIv9edWmNRk2ai"/> | |||
<add key="accessSecret" value="iFBh4DYE7kwKACV4hhoGxDrILd63uL"/> | |||
<add key="regionIdForPop" value="cn-hangzhou"/> | |||
<add key="SignName" value="阿里云短信测试专用"/> | |||
<add key="product" value="Dysmsapi" /> | |||
<add key="domain" value="dysmsapi.aliyuncs.com" /> | |||
<add key="accessId" value="LTAIv9edWmNRk2ai" /> | |||
<add key="accessSecret" value="iFBh4DYE7kwKACV4hhoGxDrILd63uL" /> | |||
<add key="regionIdForPop" value="cn-hangzhou" /> | |||
<add key="SignName" value="阿里云短信测试专用" /> | |||
<!--斑羚短信平台--> | |||
<add key="sdkappid" value="140009369387"/> | |||
<add key="appkey" value="4d2743a4233e5d8625eefa31f876721b"/> | |||
<add key="sdkappid" value="140009369387" /> | |||
<add key="appkey" value="4d2743a4233e5d8625eefa31f876721b" /> | |||
<!--一信通短信平台--> | |||
<add key="SpCode" value="320328"/> | |||
<add key="LoginName" value="9c34cbd5462e8034d9b779887c1e8398"/> | |||
<add key="Password" value="29745012d0575978cd8c93d8d6c62f9d96e6b808eb9ac87845721c7c29b39c8f"/> | |||
<add key="ClientSettingsProvider.ServiceUri" value=""/> | |||
<add key="SpCode" value="320328" /> | |||
<add key="LoginName" value="9c34cbd5462e8034d9b779887c1e8398" /> | |||
<add key="Password" value="29745012d0575978cd8c93d8d6c62f9d96e6b808eb9ac87845721c7c29b39c8f" /> | |||
<add key="ClientSettingsProvider.ServiceUri" value="" /> | |||
</appSettings> | |||
<startup> | |||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1"/> | |||
<supportedRuntime version="v4.0" sku=".NETFramework,Version=v4.6.1" /> | |||
</startup> | |||
<runtime> | |||
<assemblyBinding xmlns="urn:schemas-microsoft-com:asm.v1"> | |||
<dependentAssembly> | |||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral"/> | |||
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0"/> | |||
<assemblyIdentity name="Newtonsoft.Json" publicKeyToken="30ad4fe6b2a6aeed" culture="neutral" /> | |||
<bindingRedirect oldVersion="0.0.0.0-9.0.0.0" newVersion="9.0.0.0" /> | |||
</dependentAssembly> | |||
</assemblyBinding> | |||
</runtime> | |||
<system.web> | |||
<membership defaultProvider="ClientAuthenticationMembershipProvider"> | |||
<providers> | |||
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri=""/> | |||
<add name="ClientAuthenticationMembershipProvider" type="System.Web.ClientServices.Providers.ClientFormsAuthenticationMembershipProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" /> | |||
</providers> | |||
</membership> | |||
<roleManager defaultProvider="ClientRoleProvider" enabled="true"> | |||
<providers> | |||
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400"/> | |||
<add name="ClientRoleProvider" type="System.Web.ClientServices.Providers.ClientRoleProvider, System.Web.Extensions, Version=4.0.0.0, Culture=neutral, PublicKeyToken=31bf3856ad364e35" serviceUri="" cacheTimeout="86400" /> | |||
</providers> | |||
</roleManager> | |||
</system.web> | |||