如何使用短信接口发送短信
金蝶云社区-阿醴
阿醴
5人赞赏了该文章 2115次浏览 未经作者许可,禁止转载编辑于2018年05月17日 18:16:46

经常有需求需要在点击某个按钮的时候需要发送短信通知特定的用户。如用户点击修改了应收款单发送短信给某个用户,可参考实例1.
当用户审核提交了某个流程需要发送短信通知下个审核人需要发送短信给特定用户。可参考实例2.

1、如何在插件中实现给特定用户发送短信。
a)首先引入短信必须的Kingdee.BOS.ServiceHelper.dll和Kingdee.BOS.dll。当然也少不了插件必须的Kingdee.BOS.Core.dll。

144616k77nqmopukzuommy.bmp

b)编写插件实现发送短信。

 

using Kingdee.BOS.Core.DynamicForm.PlugIn;

using Kingdee.BOS.Msg;

using Kingdee.BOS.ServiceHelper;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace MyTest.Business.PlugIn

{

    public class SMSSendPlugin : AbstractDynamicFormPlugIn

    {

        public override void ButtonClick(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.ButtonClickEventArgs e)

        {

            ////点击按钮的时候,发送短信给当前登录的用户

            if (e.Key == "btn_Send")

            {

                SMSMessageInfo messageInfo= new SMSMessageInfo();

                //发送短信类型:业务预警、短信验证码、工作流、其他

                messageInfo.MessageType = SMSMessageType.Other;

                //发送的短信内容

                messageInfo.SMSMessage = "发送测试短信";

                //收信人。可设置多个用户。

                messageInfo.PhoneInfos = new List<PhoneInfo>() { new  PhoneInfo(this.Context.UserId,"13430688323")};

                SMSServiceHelper.SendSMS(this.Context, messageInfo);

            }

        }

    }

}

复制代码


2.如何在App层调用发短信接口
a)首先引入短信必须的Kingdee.BOS.App.Core.dll、Kingdee.BOS.dll和Kingdee.BOS.Contracts.dll。同时引入操作服务插件所必须的Kingdee.BOS.Core.dll。

152002ztyylv8phoky2ivy.png

b)编写服务插件实现发送短信

using Kingdee.BOS.Contracts;

using Kingdee.BOS.Core.DynamicForm.PlugIn;

using Kingdee.BOS.Msg;

using System;

using System.Collections.Generic;

using System.Linq;

using System.Text;

using System.Threading.Tasks;


namespace MyTest.ServicePlugIn

{

    public class SmsSendServicePlugIn : AbstractOperationServicePlugIn

    {

        public override void EndOperationTransaction(Kingdee.BOS.Core.DynamicForm.PlugIn.Args.EndOperationTransactionArgs e)

        {

            //当操作服务完成后发送短信给当前用户

            ISMSService service = ServiceFactory.GetService<ISMSService>(this.Context);

            try

            {

                SMSMessageInfo messageInfo = new SMSMessageInfo();

                //发送短信类型:业务预警、短信验证码、工作流、其他

                messageInfo.MessageType = SMSMessageType.Other;

                //发送的短信内容

                messageInfo.SMSMessage = "发送测试短信";

                //收信人。可设置多个用户。

                messageInfo.PhoneInfos = new List<PhoneInfo>() { new PhoneInfo(this.Context.UserId, "13430688323") };

                service.SendSMS(this.Context, messageInfo);

            }

            finally

            {

                ServiceFactory.CloseService(service);

            }

        }

    }

}

 

复制代码


赞 5