using APT.BaseData.Domain.Entities.FM; using APT.BaseData.Domain.IServices.OP; using APT.Infrastructure.Api; using APT.Infrastructure.Core; using Newtonsoft.Json; using System; using System.Net; namespace APT.BaseData.Services.Services.OP { public class OPSmsService : CommonService, IOPSmsService { public OPSmsService(IRepository repository) : base(repository) { } public bool SendNote(T_FM_NOTICE note) { try { //Random r = new Random(); //JSMSClient _smsClient = new JSMSClient("1cad1e6d2e226662f6388989", "692e9b7d38266a4f7220252d"); //if (string.IsNullOrEmpty(note.MESSAGE_TEMPLATE_ID)) //{ // JSMSResult result = _smsClient.SendTemplateMessage(new TemplateMessage // { // Mobile = note.TEL, // TemplateId = 148580,//模板id是在极光平台上申请的 // TemplateParameters = new Dictionary // { // { "date", note.CREATE_TIME.GetValueOrDefault().ToString("MM-dd HH:mm") },//报警时间 // { "msg",note.MESSAGE}, // { "msgid",r.Next(1,100).ToString()},//描述 // { "server","optiEnergy"}//报警端 // } // }); // return result.Succeeded; //} //else //{ // JSMSResult result = _smsClient.SendTemplateMessage(new TemplateMessage // { // Mobile = note.TEL, // TemplateId = Convert.ToInt32(note.MESSAGE_TEMPLATE_ID),//模板id是在极光平台上申请的 // TemplateParameters = new Dictionary // { // { "code",note.MESSAGE} // } // }); // return result.Succeeded; //} } catch (Exception ex) { this.ThrowError("010001", $"{ex.Message};{ex.Source};{ex.StackTrace};{ex.InnerException}"); } return true; } public bool SendMessage(string phoneNumber, string code) { //try //{ // T_FM_NOTICE notice = new T_FM_NOTICE() // { // ORG_ID = new Guid(LibUtils.ToString(ConfigurationManager.WexinSettings["OrgId"]).ToString()), // MESSAGE = $"您的手机验证码:{code},有效期1分钟,请勿泄露。如非本人操作,请忽略此短信。谢谢!", // TEL = phoneNumber, // NOTICE_TYPE = 0, // //MESSAGE_TEMPLATE_ID = "148580" // }; // this.AddEntity(notice); //} //catch (Exception ex) //{ // throw ex; //} return true; } /// /// 极光短信返回实体类。 /// private class JSMSResult { //{\"msg_id\":605999989525} //{"error":{"code":50013,"message":"invalid temp_id"}} /// /// 发送成功消息Id。 /// public long Msg_Id { get; set; } /// /// 错误信息。 /// public ErrorResult Error { get; set; } /// /// 是否发送成功。 /// public bool Succeeded { get; private set; } //public static implicit operator JSMSResult(HttpResponse response) //{ // var result = JsonConvert.DeserializeObject(response.Content); // result.Succeeded = response.StatusCode == HttpStatusCode.OK; // return result; //} } /// /// 极光短信错误实体类 /// private class ErrorResult { /// /// 错误编码。 /// public int Code { get; set; } /// /// 错误消息 /// public string Message { get; set; } } } }