public static Result smsOrderAdd(string handler, string OrderName, pdermsWebEntities bll) { try { string sql = "SELECT * FROM t_CM_UserInfo WHERE UserName='******'"; List <t_CM_UserInfo> listUsers = bll.ExecuteStoreQuery <t_CM_UserInfo>(sql).ToList(); if (listUsers != null && listUsers.Count > 0) { string mobile = listUsers.First().Mobilephone; Config config = new Config(key); Dictionary <string, string> data = new Dictionary <string, string>(); Result result = null; SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", mobile); data.Add("text", "【" + company + "】您有一个工单名称为[" + subString(OrderName) + "]的待处理工单,请及时处理!"); return(sms.singleSend(data)); } else { string rm = "{\"code\":2,\"msg\":\"" + "查找不到" + handler + "的手机号" + "\",\"count\":1,\"fee\":0.05,\"unit\":\"RMB\",\"mobile\":\"13681206520\",\"sid\":22927664130}"; return(new Result(-1, rm)); } } catch (Exception e) { string rm = "{\"code\":2,\"msg\":\"" + "发送短信出错:" + e.Message + "\",\"count\":1,\"fee\":0.05,\"unit\":\"RMB\",\"mobile\":\"13681206520\",\"sid\":22927664130}"; return(new Result(-1, rm)); } }
/// <summary> /// 中午忘记打卡通知 /// </summary> public void Noon(Dictionary <string, int> dictionary) { if (!dictionary.Any()) { return; } try { var date = DateTime.Now.ToString("MM月dd日 HH:mm:ss"); foreach (var item in dictionary) { // 发送单条短信 SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", item.Key); data.Add("text", $"【秋刀鱼科技】大哥大姐!您截止至{date}中午时仅打卡{item.Value}次!中午要打2次卡!该打卡了!"); sms.singleSend(data); } } catch (Exception exception) { Log.Error("中午忘记打卡通知:" + exception.Message); } }
internal static Result smsAlarm(string Mobilephone, IDAO.Models.t_AlarmTable_en alarm) { Config config = new Config(key); Dictionary <string, string> data = new Dictionary <string, string>(); SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", Mobilephone); data.Add("text", getText(alarm)); return(sms.singleSend(data)); }
//用电计划修改短信通知; public static void smsInform(string mobile, int year, int month) { try { Config config = new Config(key); Dictionary <string, string> data = new Dictionary <string, string>(); Result result = null; SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", mobile); data.Add("text", "【" + company + "】系统已确认分配了您的" + year + "-" + month + "的用电计划,详细信息请登录微信小程序查看。"); result = sms.singleSend(data); Console.WriteLine(result); } catch (Exception e) { } }
//合同事项通知 public static void smsContractTemp(string mobile, string content) { try { Config config = new Config(key); Dictionary <string, string> data = new Dictionary <string, string>(); Result result = null; SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", mobile); data.Add("text", "【" + company + "】您有一条信息通知:" + content + ",请及时处理。如有疑问,联系管理员。"); result = sms.singleSend(data); Console.WriteLine(result); } catch (Exception e) { } }
public static void smsOrderCancel(string handler, string OrderName, pdermsWebEntities bll) { try { string sql = "SELECT * FROM t_CM_UserInfo WHERE UserName='******'"; List <t_CM_UserInfo> listUsers = bll.ExecuteStoreQuery <t_CM_UserInfo>(sql).ToList(); if (listUsers != null && listUsers.Count > 0) { string mobile = listUsers.First().Mobilephone; Config config = new Config(key); Dictionary <string, string> data = new Dictionary <string, string>(); SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", mobile); data.Add("text", "【" + company + "】您的一个待处理工单[" + subString(OrderName) + "],已取消!"); sms.singleSend(data); } }catch (Exception e) { } }
/// <summary> /// 发送短信 /// </summary> /// <param name="content">内容</param> /// <param name="tcode">电话号码</param> /// <returns></returns> public static bool SendSMS(string content, string tcode) { bool flag = false; string cstr = string.Format("【xxxx】{0}", content); Dictionary <string, string> data = new Dictionary <string, string>(); Config config = new Config(SystemSet.SMSKey); SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", tcode); data.Add("text", cstr); var reslut = sms.singleSend(data); flag = reslut.success; if (!flag) { ClassLoger.Fail("Utils.SendSMS短信发送失败", tcode, reslut.responseText); } return(flag); }
/// <summary> /// 下午忘记打卡通知 /// </summary> public void Afternoon(List <string> mobiles) { if (!mobiles.Any()) { return; } try { var date = DateTime.Now.ToString("MM月dd日 HH:mm:ss"); // 发送单条短信 SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", string.Join(",", mobiles)); data.Add("text", $"【秋刀鱼科技】亲!您截止至{date}时未有下班打卡记录!快去打卡!"); sms.batchSend(data); } catch (Exception exception) { Log.Error("下午忘记打卡通知异常:" + exception.Message); } }
/// <summary> /// 云片单条验证短信发送 /// </summary> /// <param name="mobile">手机号码</param> /// <param name="yzmcode">验证码</param> /// <param name="extend">下发号码扩展(纯数字),需申请</param> /// <param name="uid">业务ID,需申请</param> /// <param name="register">是否注册验证短信,需申请</param> /// <param name="errmsg"></param> /// <returns></returns> public static bool SmsSingleSendByYunpian(string mobile, string yzmcode, string extend, string uid, bool register, out string errmsg) { errmsg = null; Config config = new Config(GlobalParameters.Sms_Yunpian_ApiKey); Result result; Dictionary <string, string> data = new Dictionary <string, string>(); SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", mobile); data.Add("text", string.Format(GlobalParameters.Sms_Yunpian_ContentTemplate, yzmcode)); // data.Add("extend", extend); // data.Add("uid", uid); // data.Add("register", register.ToString()); result = sms.singleSend(data); LogHelperWeb.WriteInfo(string.Format("调用云片短信发送,向号码 {0} 发送 {1} 返回:{2} 错误{3}", mobile, yzmcode, result.success, result.data.Last)); if (!result.success) { errmsg = result.data.Last.ToString(); return(false); } return(true); }
/// <summary> /// 早上迟到通知 /// </summary> public void MorningLate(Dictionary <string, DateTime> dictionary) { if (!dictionary.Any()) { return; } try { foreach (var item in dictionary) { // 发送单条短信 SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", item.Key); data.Add("text", $"【秋刀鱼科技】亲!您迟到了哟!您的上班打开时间为{item.Value}。30块!可以吃多少顿麻辣烫!可以买多少个泡泡糖!"); sms.singleSend(data); } } catch (Exception exception) { Log.Error("早上迟到通知:" + exception.Message); } }
static void Main(string[] args) { //设置apikey Config config = new Config("your apikey"); Dictionary <string, string> data = new Dictionary <string, string>(); Result result = null; // 获取用户信息 UserOperator user = new UserOperator(config); result = user.get(data); Console.WriteLine(result); // 获取模板信息 TplOperator tpl = new TplOperator(config); data.Clear(); data.Add("tpl_id", "1"); result = tpl.getDefault(data); Console.WriteLine(result); // 发送单条短信 SmsOperator sms = new SmsOperator(config); data.Clear(); data.Add("mobile", "14012341234"); data.Add("text", "【yunpian】您的验证码是9981"); result = sms.singleSend(data); Console.WriteLine(result); // 发送模板短信(不推荐使用) // data.Clear(); // string tpl_value = HttpUtility.UrlEncode( // HttpUtility.UrlEncode("#code#", Encoding.UTF8) + "=" + // HttpUtility.UrlEncode("1234", Encoding.UTF8) + "&" + // HttpUtility.UrlEncode("#company#", Encoding.UTF8) + "=" + // HttpUtility.UrlEncode("云片网", Encoding.UTF8), Encoding.UTF8); // data.Add("mobile", "14012341231,123,13012312312"); // data.Add("tpl_value", tpl_value); // data.Add("tpl_id", "1"); // result = sms.tplSingleSend(data); // Console.WriteLine(result); // 发送批量短信 data.Clear(); data.Add("mobile", "14012341231,123,13012312312"); data.Add("text", "【yunpian】您的验证码是9981"); result = sms.batchSend(data); Console.WriteLine(result); // 发送个性化短信 data.Clear(); data.Add("mobile", "14022341231,123,13112312312,13112312312"); data.Add("text", "【yunpian】您的验证码是9981,【yunpian】您的验证码是1981,【yunpian】您的验证码是9921,【yunpian】您的验证码是9981"); result = sms.multiSend(data); Console.WriteLine(result); // 发送语音 VoiceOperator voice = new VoiceOperator(config); data.Clear(); data.Add("code", "1421"); data.Add("mobile", "13012312312"); result = voice.send(data); Console.WriteLine(result); // 发送流量 FlowOperator flow = new FlowOperator(config); data.Clear(); result = flow.getPackage(data); Console.WriteLine(result); data.Clear(); data.Add("sn", "1008601"); data.Add("mobile", "18712341234"); result = flow.recharge(data); Console.WriteLine(result); Console.ReadLine(); }