.Net core----使用容联云短信推送
一直在忙于写接口,也没有时间去好好的整理的一片文档,写一篇经常的用到的短信推送案例 还是比较喜欢干货 作为有个程序员 有时候复制粘贴习惯了 实在的还是比较实在 比如能用复制解决的为什么不用复制 效率上也是一方面
sdk需自行安装
/// <summary> /// 短信验证码推送 /// </summary> /// <param name="phone">推送手机号码</param> /// <param name="val">验证码</param> /// <param name="type">1短信,2语音</param> /// <param name="template">推送模板</param> public bool MessageCode(string phone, string val, int type, string template = "推送的模板号") { Infrastructure.Sdk.CCPRestSDK api = new CCPRestSDK(); /*服务器地址,服务器端口*/ bool bIsInit = api.init("app.cloopen.com", "8883"); string strRet = string.Empty; string strResult = string.Empty; /*主账号,主账号令牌,如果主页更换了token需要在这里更改令牌*/ api.setAccount("主账号", "令牌"); api.setAppId("应用id"); /*应用ID*/ try { Dictionary<string, object> RetData = null; if (type == 1) //短信 { /*手机号码,短信模板,验证码*/ RetData = api.SendTemplateSMS(phone, template, new string[] { val, "1" }); } else { /*手机号码,验证码,显示主叫号码,重复次数,回调地址*/ RetData = api.VoiceVerify(phone, val, null, "3", null); } //推送短信/电话 strRet = api.getDictionaryData(RetData); } catch (Exception) { throw; } finally { string[] str_Temp = strRet.Split(';'); strResult = str_Temp[0]; strResult = strResult.Substring(strResult.IndexOf("=") + 1); } if (strResult != "000000") { //推送失败 return false; } return true; }
本文来自博客园,作者:.拾贰,转载请注明原文链接:https://www.cnblogs.com/wuyabaibsd/p/10748935.html