username@email.com
2025-04-18 0fbf7c551ba932e7c8bfdb1086bd4ef7acc90a9c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
using Aliyun.Acs.Core;
using Aliyun.Acs.Core.Exceptions;
using Aliyun.Acs.Core.Profile;
using Aliyun.Acs.Dysmsapi.Model.V20170525;
using DTO;
using System;
using System.Collections.Generic;
using System.Text;
 
namespace CommonToolsCore
{
    public class SMSHelper
    {
        static String product = "Dysmsapi";//短信API产品名称(短信产品名固定,无需修改)
        static String domain = "dysmsapi.aliyuncs.com";//短信API产品域名(接口地址固定,无需修改)
        static String accessKeyId = "LTAIZL9hStjo3whT";//你的accessKeyId,参考本文档步骤2
        static String accessKeySecret = "fTrKqgHprJGwfyJW5qIO0JHFJ7JVRW";//你的accessKeySecret,参考本文档步骤2
 
        public static ResultEntity SendSMS(string phone, string templateCode, string templateParmJson)
        {
            ResultEntity resultEntity = new ResultEntity();
            IClientProfile profile = DefaultProfile.GetProfile("cn-hangzhou", accessKeyId, accessKeySecret);
            //IAcsClient client = new DefaultAcsClient(profile);
            // SingleSendSmsRequest request = new SingleSendSmsRequest();
            //初始化ascClient,暂时不支持多region(请勿修改)
            profile.AddEndpoint("cn-hangzhou", "cn-hangzhou", product, domain);
            IAcsClient acsClient = new DefaultAcsClient(profile);
            SendSmsRequest request = new SendSmsRequest();
            try
            {
                //必填:待发送手机号。支持以逗号分隔的形式进行批量调用,批量上限为1000个手机号码,批量调用相对于单条调用及时性稍有延迟,验证码类型的短信推荐使用单条调用的方式
                request.PhoneNumbers = phone;
                //必填:短信签名-可在短信控制台中找到
                request.SignName = "政采招投标";//坤德岩土
                //必填:短信模板-可在短信控制台中找到
                request.TemplateCode = templateCode;
                //可选:模板中的变量替换JSON串,如模板内容为"亲爱的${name},您的验证码为${code}"时,此处的值为
                request.TemplateParam = templateParmJson;
                //可选:outId为提供给业务方扩展字段,最终在短信回执消息中将此值带回给调用者
                request.OutId = "";
                //请求失败这里会抛ClientException异常
                SendSmsResponse sendSmsResponse = acsClient.GetAcsResponse(request);
                if(sendSmsResponse.Code == "OK")
                {
                    resultEntity.Result = true;
                }
                else
                {
                    resultEntity.Result = false;
                    resultEntity.Message = sendSmsResponse.Message;
                }
                  
            }
            catch (ServerException e)
            {
 
                resultEntity.Result = true;
                resultEntity.Message = "发送失败" + e.Message;
 
                return resultEntity;
            }
            catch (ClientException e)
            {
 
                resultEntity.Result = true;
                resultEntity.Message = "发送失败" + e.Message;
 
                return resultEntity;
            }
 
            return resultEntity;
        }
 
 
        /// <summary>
        /// 短信实例
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public static ResultEntity PushWToUserBySMS(string phone, string date)
        {
            //if (string.IsNullOrEmpty(phone) || string.IsNullOrEmpty(date))
            //    return "";
            string codeno = "SMS_156282130";
            return SMSHelper.SendSMS(phone, codeno, "{\"date\":\"" + date + "\"}");
        }
 
 
        /// <summary>
        /// 短信实例
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public static string PushWToUserMES(string phone, string conment)
        {
            string url = "https://mb345.com/ws/BatchSend2.aspx";
            string data = "CorpID=XP010534&Pwd=123321&Mobile="+ phone + "&Content="+ conment + " 拒收请回复R【政采咨询网】&SendTime="; //退订回N
            string ssss =   HttpClientRequest.HttpClientPostGB2312(url, "POST", data);
            return ssss;
        }
 
 
        /// <summary>
        /// 发送验证码
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public static string PushWToUserMESYanZhengMa(string phone, string conment)
        {
            string url = "https://mb345.com/ws/BatchSend2.aspx";
            string data = "CorpID=XP010534&Pwd=123321&Mobile=" + phone + "&Content=您好,您的验证码是:" + conment + "【政采咨询网】&SendTime=";
            string ssss = HttpClientRequest.HttpClientPostGB2312(url, "POST", data);
            return ssss;
        }
 
 
 
        /// <summary>
        /// 短信实例
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public static string PushApp(string conment)
        {
           
            string url = "http://yjdl.51zhengcai.com/pushms";
            string data = conment;
            string ssss = HttpClientRequest.HttpClientPost(url, "POST", data);
            return ssss;
        }
 
 
        /// <summary>
        /// 短信实例
        /// </summary>
        /// <param name="phone"></param>
        /// <param name="date"></param>
        /// <returns></returns>
        public static string PushAppduandu(string conment)
        {
 
            string url = "http://rest-hz.goeasy.io/v2/im/message";
            string data = conment;
            string ssss = HttpClientRequest.HttpClientPost(url, "POST", data);
            return ssss;
        }
    }
}