AI智能
改变未来

C#使用极光短信发送手机验证码

引用极光官方类库,或下载提供的资源。

JpushEvents.cs

[code]using System;using System.Collections.Generic;using System.Linq;using System.Text;using System.Threading.Tasks;using Jiguang.JSMS;using Jiguang.JSMS.Model;namespace NjswAppClass.Jpush{/// <summary>/// 极光推送/// </summary>public class JpushEvents{/// <summary>/// 发送文本验证码短信。/// <see cref=\"C#/ </summary>public static string SendCode(string tel,int signId){try{JSMSClient jsmsClient = new JSMSClient(PublicValue.jpush_app_key, PublicValue.jpush_master_secret);HttpResponse httpResponse = jsmsClient.SendCode(tel, 1, signId);return httpResponse.Content;}catch (Exception er){return er.Message;}}/// <summary>/// 验证码是否有效/// </summary>/// <param name=\"msgId\"></param>/// <param name=\"code\"></param>/// <returns></returns>public static string IsCodeValid(string msgId, string code){try{JSMSClient jsmsClient = new JSMSClient(PublicValue.jpush_app_key, PublicValue.jpush_master_secret);HttpResponse httpResponse = jsmsClient.IsCodeValid(msgId, code);return httpResponse.Content;}catch (Exception er){return er.Message;}}/// <summary>/// 发送模板短信/// </summary>/// <param name=\"tel\"></param>/// <param name=\"tmptid\"></param>/// <param name=\"tmpmsg\"></param>/// <returns></returns>public static string SendMessage(string tel,int tmptid, Dictionary<string, string> tmpmsg){try{JSMSClient jsmsClient = new JSMSClient(PublicValue.jpush_app_key, PublicValue.jpush_master_secret);TemplateMessage msg = new TemplateMessage();msg.Mobile = tel;msg.SignId = 9999;msg.TemplateId = tmptid;msg.TemplateParameters = tmpmsg;HttpResponse httpResponse = jsmsClient.SendTemplateMessage(msg);return httpResponse.Content;}catch (Exception er){return er.Message;}}}}

PublicValue.jpush_app_key, PublicValue.jpush_master_secret 是极光给你的KEY和secret 。

signId 是 极光签名,如[云一网络]XXXXXXXX

 

 

赞(0) 打赏
未经允许不得转载:爱站程序员基地 » C#使用极光短信发送手机验证码