码迷,mamicode.com
首页 > 其他好文 > 详细

K/3 Wise 群发短信配置和开发(二)之短信群发配置

时间:2014-09-22 19:16:53      阅读:335      评论:0      收藏:0      [点我收藏+]

标签:style   blog   http   color   io   ar   strong   for   数据   

开发环境:K/3 Wise 13.0、Sql Server 2005

目录

一、开启Sql Server Agent代理服务

二、短信发送原理

三、编写存储过程

四、开启Sql Server作业

一、开启Sql Server Agent代理服务

  打开“管理工具” -- “服务” --“Sql Server Agent(MSSQLSERVER)”,设置为“已启动”、“自动”:

  bubuko.com,布布扣

  bubuko.com,布布扣

二、短信发送原理

  往K3Mobile数据库的两个表T_SMSMSGLOGtb_sendmessage插入记录,K/3 Wise将自动发送数据到WeiNaDuo短信接口进行短信发送!

  发送数据模板:

insert into tb_sendmessage(id,biztype,isRevertible,title,msgtype,receivers,ffuncnumber,issent,createtime,fsendstate)
Values(DB000000000001,k3-9AB20E12-60C4-448C-B60D-6DFC8BA7AC77,0,还款提醒:XXX先生/女士,您的融资XX应还租金人民币15,300.00元,本期还款日为8月20日。若已还款请忽略。,0,接收人手机号码,K3V10.3YDSW,0,2014-08-29 10:26:09.937,0)

insert into t_smsmsglog(fsender,freceiver,facctid,frecvphonenum,fsendphonenum,fsendtime,freceivetime,fcontent,fmidserver,frecman,frecmantype,fid)
values(0,-1,2,接收人手机号码,短信中心,2014-08-29 10:26:09.937,1900-01-01 00:00:00.000,还款提醒:XXX先生/女士,您的融资XX应还租金人民币15,300.00元,本期还款日为8月20日。若已还款请忽略。,服务器IP地址,接收人姓名,1,DB000000000001)

 

  金蝶提供了“金蝶短信平台”,可以查看短信发送情况,短信平台地址:http://121.52.221.109:8090/Default.aspx

  bubuko.com,布布扣

  输入账号和密码后:

  bubuko.com,布布扣

三、编写存储过程  

  数据库K3Mobile下,编写存储过程,本例存储过程为“pro_sms_ContractSchemeOutDateWarn”:

  bubuko.com,布布扣

  bubuko.com,布布扣

  附上代码:

IF EXISTS(SELECT * FROM sysobjects WHERE NAME=pro_sms_ContractSchemeOutDateWarn AND TYPE=p)
DROP PROCEDURE pro_sms_ContractSchemeOutDateWarn
GO
CREATE PROC pro_sms_ContractSchemeOutDateWarn
    @OutDay int       --过期提醒的天数
AS
SET NOCOUNT ON

CREATE TABLE #ContractTemp 
(
    FID int identity(1,1),
    FContractNO varchar(50),
    FCustomerName varchar(50),
    FSex varchar(50),
    FMobilePhone varchar(50),
    FReceiveDate datetime,
    FAmountFor decimal(18,2)
)
--版本一:2014-8-31
--INSERT INTO #ContractTemp
--SELECT b.FContractNO,c.FName as FCustomerName,c.F_102 as FSex,c.FMobilePhone,a.FReceiveDate,a.FAmountFor from AIS20130715142849.dbo.t_RPContractScheme a 
--left join AIS20130715142849.dbo.t_RPContract b on a.FContractID=b.FContractID
--Left Join AIS20130715142849.dbo.T_Organization c On b.FCustomer=c.FItemID 
--where datediff(day,getdate(),a.freceivedate)=@OutDay and b.FStatus<>2 and b.FStatus<>1 and c.FMobilePhone is not null
--SELECT * FROM #ContractTemp
--版本二:2014-9-5,纠正“短信发送晚于付款时间2日”的错误;排除已结租合同(包括已审核、已关闭、实收金额合计累计+保证金>=应收金额累计)
INSERT INTO #ContractTemp
select t.FContractNO,c.FName as FCustomerName,c.F_102 as FSex,c.FMobilePhone,t1.FReceiveDate,t1.FAmountFor 
from AIS20130715142849.dbo.t_RPContractScheme t1
left join (select a.FContractID,a.FContractNO,a.FStatus,a.Fcustomer,a.FDecimal,sum(b.famountfor) as famountfortotal,sum(famount12) as famount12total 
from AIS20130715142849.dbo.t_rpcontract a 
left join AIS20130715142849.dbo.t_rpcontractscheme b on a.fcontractid=b.fcontractid where a.fstatus<>1 and a.fstatus<>2
group by a.FContractID,a.fcontractno,a.FStatus,a.FCustomer,a.FDecimal) t ON t1.FContractID=t.FContractID
Left Join AIS20130715142849.dbo.T_Organization c On t.FCustomer=c.FItemID 
where t.FAmount12Total+t.FDecimal<t.FAmountForTotal and t.FStatus<>1 and t.FStatus<>2
and datediff(day,getdate(),t1.freceivedate)=@OutDay and c.FMobilePhone is not null

DECLARE @DBID varchar(50)
DECLARE @curIndex int
DECLARE @totalRows int
DECLARE @FCustomerName varchar(50)
DECLARE @FSex varchar(50)
DECLARE @FMobilePhone varchar(50)
DECLARE @FReceiveDate datetime
DECLARE @FAmountFor varchar(50)
DECLARE @FContractNO varchar(50)
SELECT @curIndex=1
SELECT @totalRows=COUNT(1) FROM #ContractTemp
WHILE(@curIndex<=@totalRows)
BEGIN
SELECT @DBID=null
SELECT @FCustomerName=null
SELECT @FSex=null
SELECT @FMobilePhone=null
SELECT @FReceiveDate=null
SELECT @FAmountFor=null
SELECT @FContractNO=null
SELECT @FCustomerName=FCustomerName FROM #ContractTemp WHERE FID=@curIndex
SELECT @FSex=CASE FSex WHEN 0 THEN 女士 WHEN 1 THEN 先生 ELSE 先生/女士 END FROM #ContractTemp WHERE FID=@curIndex
SELECT @FMobilePhone=FMobilePhone FROM #ContractTemp WHERE FID=@curIndex
SELECT @FReceiveDate=FReceiveDate FROM #ContractTemp WHERE FID=@curIndex
SELECT @FAmountFor=FAmountFor FROM #ContractTemp WHERE FID=@curIndex
SELECT @FAmountFor=CONVERT(varchar,CONVERT(money,@FAmountFor),1)
SELECT @FContractNO=FContractNO FROM #ContractTemp WHERE FID=@curIndex
SELECT @DBID=MAX(FID) FROM t_DBID
SELECT @DBID=DB+REPLACE(SPACE(12-LEN(@DBID)), ,0)+CONVERT(varchar(50),@DBID+1)

INSERT INTO TB_SENDMESSAGE
(ID,bizType,isRevertible,title,msgType,receivers,FFuncNumber) 
VALUES(@DBID,k3-9AB20E12-60C4-448C-B60D-6DFC8BA7AC77,0,还款提醒:+@FCustomerName+@FSex+,您的XX融资合同<+@FContractNO+>本期应还¥+@FAmountFor+元,还款日为+CONVERT(varchar,MONTH(@FReceiveDate))++CONVERT(varchar,DAY(@FReceiveDate))+日.若已还款请忽略.,0,13774534210,13850040496,13959240595,K3V10.3YDSW)

INSERT INTO T_SMSMSGLOG
(FID,FSender,FReceiver,FAcctID,FRecvPhoneNum,FSendPhoneNum,FContent,FSendTime,FReceiveTime,FMidServer,FRecMan,FRecManType) 
VALUES(@DBID,0,-1,2,13774534210,13850040496,13959240595,短信中心,还款提醒:+@FCustomerName+@FSex+,您的XX融资合同<+@FContractNO+>本期应还¥+@FAmountFor+元,还款日为+CONVERT(varchar,MONTH(@FReceiveDate))++CONVERT(varchar,DAY(@FReceiveDate))+日.若已还款请忽略.,GetDate(),0,127.0.0.1,@FCustomerName,1)


INSERT INTO T_DBID(FType)VALUES(sms)
SELECT @curIndex=@curIndex+1
END
DROP TABLE #ContractTemp
GO

--exec pro_sms_ContractSchemeOutDateWarn 2
--select * from t_dbid
--select * from TB_SENDMESSAGE where id like ‘DB%‘
--select * from t_smsmsglog where fid like ‘DB%‘
--delete from TB_SENDMESSAGE
--delete from t_smsmsglog

四、开启Sql Server作业

  bubuko.com,布布扣

  bubuko.com,布布扣

  bubuko.com,布布扣

  bubuko.com,布布扣

K/3 Wise 群发短信配置和开发(二)之短信群发配置

标签:style   blog   http   color   io   ar   strong   for   数据   

原文地址:http://www.cnblogs.com/star-studio/p/3986315.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!