以下是封装后的发送消息接口SQL代码。
可以直接调用 exec P_Send_TextMsg ‘应用名称’,’接收者’,’消息内容’
发送企业微信消息。
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 |
/* declare @status int exec P_Send_TextMsg '提醒测试','userid','企业微信消息推送测试。',@status output select @status */ create PROC P_Send_TextMsg ( @settype nvarchar(200), @touser nvarchar(512), @content nvarchar(2000), @status int = 1 OUTPUT --0 成功,1 失败 ) AS SET NOCOUNT ON declare @appid as Varchar(1000),@secret as Varchar(1000),@url as Varchar(1000) declare @access_token as Varchar(2000),@PostData Varchar(8000),@ResponseText as Varchar(8000) select @appid=setvalue,@secret=[secret] from [init] where setname='appid' and settype=@settype --获取@access_token exec P_get_access_token @secret,@access_token output if isnull(@access_token,'')='' return --查询 select @url=setvalue from [init] where setname='url' and settype='发送消息' set @url=replace(@url,'[access_token]',@access_token) set @PostData='{ "touser" : "'+@touser+'", "msgtype" : "text", "agentid" : '+@appid+', "text" : { "content" : "'+@content+'" }, "safe":0 }' exec P_Url_SendRequest @url ,@PostData,@ResponseText OUTPUT if exists(select 1 from parsejson(@ResponseText) where name='errmsg' and stringvalue='ok') set @status=0 insert into msglog([settype],[touser],[content],[status],[access_token],[time]) select @settype,@touser,@content,@status,@access_token,GETDATE() GO |
© 2017, ITJOY.NET. 版权所有. 如未注明,均为原创,转载请注明出处。