From 4008c7e22c9c01eb653b04f934990486df622654 Mon Sep 17 00:00:00 2001
From: username@email.com <yzy2002yzy@163.com>
Date: 星期一, 14 七月 2025 12:21:35 +0800
Subject: [PATCH] Merge branch 'master' of http://47.108.235.38:8080/r/FZCZTB

---
 Admin.NET/FZCZTB.NET.SYSService/MSM/ZCSMSService.cs |  216 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 216 insertions(+), 0 deletions(-)

diff --git a/Admin.NET/FZCZTB.NET.SYSService/MSM/ZCSMSService.cs b/Admin.NET/FZCZTB.NET.SYSService/MSM/ZCSMSService.cs
new file mode 100644
index 0000000..051b110
--- /dev/null
+++ b/Admin.NET/FZCZTB.NET.SYSService/MSM/ZCSMSService.cs
@@ -0,0 +1,216 @@
+锘�// Admin.NET 椤圭洰鐨勭増鏉冦�佸晢鏍囥�佷笓鍒╁拰鍏朵粬鐩稿叧鏉冨埄鍧囧彈鐩稿簲娉曞緥娉曡鐨勪繚鎶ゃ�備娇鐢ㄦ湰椤圭洰搴旈伒瀹堢浉鍏虫硶寰嬫硶瑙勫拰璁稿彲璇佺殑瑕佹眰銆�
+//
+// 鏈」鐩富瑕侀伒寰� MIT 璁稿彲璇佸拰 Apache 璁稿彲璇侊紙鐗堟湰 2.0锛夎繘琛屽垎鍙戝拰浣跨敤銆傝鍙瘉浣嶄簬婧愪唬鐮佹爲鏍圭洰褰曚腑鐨� LICENSE-MIT 鍜� LICENSE-APACHE 鏂囦欢銆�
+//
+// 涓嶅緱鍒╃敤鏈」鐩粠浜嬪嵄瀹冲浗瀹跺畨鍏ㄣ�佹壈涔辩ぞ浼氱З搴忋�佷镜鐘粬浜哄悎娉曟潈鐩婄瓑娉曞緥娉曡绂佹鐨勬椿鍔紒浠讳綍鍩轰簬鏈」鐩簩娆″紑鍙戣�屼骇鐢熺殑涓�鍒囨硶寰嬬籂绾峰拰璐d换锛屾垜浠笉鎵挎媴浠讳綍璐d换锛�
+
+using Admin.NET.Core.Service;
+using Admin.NET.Core;
+using Furion.DependencyInjection;
+using System;
+using System.Collections.Generic;
+using System.Linq;
+using System.Text;
+using System.Threading.Tasks;
+using Microsoft.Extensions.Options;
+using Dm.util;
+using Aop.Api.Domain;
+using Furion.FriendlyException;
+using Furion.DataValidation;
+using static QRCoder.PayloadGenerator;
+using System.Net;
+using Org.BouncyCastle.Asn1.Ocsp;
+using Microsoft.AspNetCore.Mvc;
+using Microsoft.AspNetCore.Authorization;
+using Furion.DynamicApiController;
+using System.ComponentModel;
+using System.ComponentModel.DataAnnotations;
+using Yitter.IdGenerator;
+using Lazy.Captcha.Core;
+using Furion;
+using NewLife;
+
+namespace FZCZTB.NET.SYSService.MSM;
+/// <summary>
+/// 鏀块噰鐭俊鏈嶅姟
+/// </summary>
+[AllowAnonymous]
+[ApiDescriptionSettings("FZCAPISYS",Order = 149)]
+public class ZCSMSService : IDynamicApiController,ITransient
+{
+    private readonly SMSConfigOptions _smsOptions;
+    private readonly SysCacheService _sysCacheService;
+    private readonly ICaptcha _captcha;
+    public ZCSMSService(IOptions<SMSConfigOptions> smsOptions,
+          SysCacheService sysCacheService,
+          ICaptcha captcha
+          )
+    {
+      
+        _smsOptions = smsOptions.Value;
+        _sysCacheService = sysCacheService;
+    
+         _captcha = captcha;
+    }
+
+
+    /// <summary>
+    /// 鏍规嵁钘忕敤妯$増鏍煎紡鍖栫煭淇″唴瀹� 浼氳嚜鍔ㄨ创涓婃爣绛�
+    /// </summary>
+    /// <param name="Code"> 闇�瑕佹浛鎹㈢殑鍐呭锛岀敤浜庢浛鎹㈡湯鐝唴瀹圭殑code閮ㄥ垎</param>
+    /// <param name="Key"></param>
+    [NonAction]
+    public string FormartMessage(string? Code, string Key = "VCode")
+    {
+     var Temp=     _smsOptions.lingKai.Templates.Where(x => x.TemplateCode == Key).FirstOrDefault();
+        if ( Temp != null )
+        {
+            if(Code != null)
+            {
+             
+                    return Temp.Content.replace("${code}", Code) + Temp.SignName;
+             
+            }
+           
+            else
+                return Temp.Content+Temp.SignName;
+        }
+        if (Code == null)
+            throw Oops.Oh("鐭俊鍐呭涓虹┖");
+        return Code;
+    }
+
+
+    /// <summary>
+    /// 鍙戦�佺煭淇�
+    /// </summary>
+    /// <param name="Content">瑕佹浛鎹㈢殑鍐呭</param>   
+    [NonAction]
+    public async Task SendSMSAsync(string Content,string Phone)
+    {
+        if (!Phone.TryValidate(ValidationTypes.PhoneNumber).IsValid) throw Oops.Oh("璇锋纭~鍐欐墜鏈哄彿鐮�");
+
+       if( string.IsNullOrEmpty(Content)) throw Oops.Oh("璇峰~鍐欐纭殑鎵嬫満鍙风爜");
+
+        string postdata1 = "CorpID=" + _smsOptions.lingKai.Number + "&Pwd=" + _smsOptions.lingKai.AccountPassPassword + "&Mobile=" + Phone + "&Content="+ Content + "&SendTime=";
+        string code = (string)await HttpPost(_smsOptions.lingKai.Url, postdata1);
+
+        var data = Convert.ToInt64(code);
+        if (data > 0)
+        {
+             return ;
+        }
+        Oops.Oh($"鍙戦�佺煭淇″け璐ワ紝閿欒鐮亄data}");
+   
+
+    }
+
+  
+
+
+    /// <summary>
+    /// 鑾峰彇楠岃瘉鐮� 馃敄
+    /// </summary>
+    /// <returns></returns>
+    [AllowAnonymous]
+    [SuppressMonitor]
+    [DisplayName("鑾峰彇楠岃瘉鐮�")]
+    public dynamic GetCaptcha()
+    {
+        var codeId = YitIdHelper.NextId().ToString();
+        var captcha = _captcha.Generate(codeId);
+        var expirySeconds = App.GetOptions<CaptchaOptions>()?.ExpirySeconds ?? 60;
+        return new { Id = codeId, Img = captcha.Base64, ExpirySeconds = expirySeconds };
+    }
+
+    /// <summary>
+    /// 鏍¢獙鐭俊楠岃瘉鐮�
+    /// </summary>
+    /// <param name="input"></param>
+    /// <returns></returns>
+    [AllowAnonymous]
+    [DisplayName("鏍¢獙鐭俊楠岃瘉鐮�")]
+    public bool VerifyCode(SmsVerifyCodeInput input)
+    {
+        var verifyCode = _sysCacheService.Get<string>($"{CacheConst.KeyPhoneVerCode}{input.Phone}");
+
+        if (string.IsNullOrWhiteSpace(verifyCode)) throw Oops.Oh("楠岃瘉鐮佷笉瀛樺湪鎴栧凡澶辨晥锛岃閲嶆柊鑾峰彇锛�");
+
+        if (verifyCode != input.Code) throw Oops.Oh("楠岃瘉鐮侀敊璇紒");
+        _sysCacheService.Remove($"{CacheConst.KeyPhoneVerCode}{input.Phone}");
+        return true;
+    }
+    /// <summary>
+    /// 鍙戦�侀獙璇佺煭淇★紝瑕佽楠岃瘉鐮� 闇�瑕佽緭鍏ユ牎楠岋紝閬垮厤鐢佃剳鏀诲嚮
+    /// </summary>
+    /// <param name="phoneNumber"> 鐢佃瘽鍙风爜</param>
+    /// <param name="VerifyCode">鍥剧墖鏍¢獙鏁版嵁</param>
+    ///   <param name="VerifyCodeId">妫�楠岀殑ID</param>
+    /// <returns></returns>
+    [AllowAnonymous]
+    [DisplayName("鍙戦�侀獙璇佺爜")]
+    public async Task SendSMS([Required] string phoneNumber , [Required] string  VerifyCode, [Required] string  VerifyCodeId)
+    {
+        if (!phoneNumber.TryValidate(ValidationTypes.PhoneNumber).IsValid) throw Oops.Oh("璇锋纭~鍐欐墜鏈哄彿鐮�");
+
+        // 鏍¢獙楠岃瘉鐮�
+        if (!_captcha.Validate(VerifyCodeId, VerifyCode)) throw Oops.Oh(ErrorCodeEnum.D0008);
+        _captcha.Generate(VerifyCodeId);
+
+        // 鐢熸垚闅忔満楠岃瘉鐮�
+        var random = new Random();
+        var verifyCode = random.Next(100000, 999999);
+
+        var templateParam = new
+        {
+            code = verifyCode
+        };
+       var code=   FormartMessage(verifyCode.toString());
+       
+       await SendSMSAsync(code, phoneNumber);
+   
+        _sysCacheService.Set($"{CacheConst.KeyPhoneVerCode}{phoneNumber}", verifyCode, TimeSpan.FromSeconds(_smsOptions.lingKai.VerifyTimeOut.ToInt()));
+     
+         
+
+        
+    }
+
+    /// <summary>
+    /// 鍙戦�侀獙璇佺爜
+    /// </summary>
+    /// <param name="Url"> 閾炬帴</param>
+    /// <param name="postDataStr"> 楠岃瘉鐮�</param>
+    /// <returns></returns>
+    private  async Task<string> HttpPost(string Url, string postDataStr)
+    {
+        //HttpWebRequest request = (HttpWebRequest)WebRequest.Create(Url);
+        //request.Method = "POST";
+        //request.ContentType = "application/x-www-form-urlencoded;charset=gb2312";
+
+        //byte[] postData = Encoding.GetEncoding("gb2312").GetBytes(postDataStr);
+        //request.ContentLength = postData.Length;
+        //Stream myRequestStream = request.GetRequestStream();
+        //myRequestStream.Write(postData, 0, postData.Length);
+        //myRequestStream.Close();
+        //HttpWebResponse response = (HttpWebResponse)await request.GetResponseAsync();
+        //Stream myResponseStream = response.GetResponseStream();
+        //StreamReader myStreamReader = new StreamReader(myResponseStream, Encoding.GetEncoding("gb2312"));
+        //string retString = myStreamReader.ReadToEnd();
+        //myStreamReader.Close();
+        //myResponseStream.Close();
+
+        //return retString;
+        // 鍒涘缓 HttpClient 瀹炰緥
+        using var httpClient = new HttpClient();
+        // 鍑嗗瑕佸彂閫佺殑鍐呭锛岃缃紪鐮佸拰鍐呭绫诲瀷
+        var content = new StringContent(postDataStr, Encoding.GetEncoding("gb2312"), "application/x-www-form-urlencoded");
+        // 鍙戦�� POST 璇锋眰
+        var response = await httpClient.PostAsync(Url, content);
+        // 纭繚璇锋眰鎴愬姛锛岃嫢澶辫触鍒欐姏鍑哄紓甯�
+        response.EnsureSuccessStatusCode();
+        // 璇诲彇鍝嶅簲鍐呭
+        return await response.Content.ReadAsStringAsync();
+    }
+
+}

--
Gitblit v1.9.1