62,046
社区成员
发帖
与我相关
我的任务
分享
$.ajax({
url: "/api/dd/" + actionName,
type: "Post",
data:{ { MessageUrl: "https://open-doc.dingtalk.com", PicUrl: '@lAjPBY0V4soLGfPOK4j7vs4jjlda', Title: '测试通过web api发送链接消息', Text: '链接消息测试文本'}, { Touser: 'manager4469' }},
success: function (data) {
alert(data);
}
public void SendLinkMsgUser(LinkMsgModel linkMsgModel,Link link)
{
var msgModel = new LinkMsgModel()
{
// Agentid = linkMsgModel.Agentid,
Link = new Link()
{
//MessageUrl = link.MessageUrl,
//PicUrl = link.PicUrl,
//Title = link.Title,
//Text = link.Text,
},
Agentid=linkMsgModel.Agentid,
Touser=linkMsgModel.Touser
// Touser = linkMsgModel.Touser
};
ddManager.SendMessage(msgModel);
}
public class LinkMsgModel : MessageRequestBaseModel
{
public LinkMsgModel()
{
this.MessageType = MessageType.Link;
}
public Link Link { get; set; }
}
public class Link
{
public string MessageUrl { get; set; }
public string PicUrl { get; set; }
public string Title { get; set; }
public string Text { get; set; }
}
public class MessageRequestBaseModel
{
public string Touser { get; set; }//个人
public string Toparty { get; set; }//公司或部门
[Required]
public string Agentid { get; set; }//应用id
[JsonIgnore]
public MessageType MessageType { get; set; } = MessageType.Text;
public string Msgtype { get { return GetDispayName(MessageType); } }
public string GetDispayName(MessageType type)
{
return type.ToString().ToLower();
}
}
var LinkMsgModel=new { "MessageUrl": "https://open-doc.dingtalk.com", "PicUrl": '@lAjPBY0V4soLGfPOK4j7vs4jjlda', "Title": '测试通过web api发送链接消息', "Text": '链接消息测试文本'}
var link=new { "Touser": 'manager4469' }
ajax传入data:{linkMsgModel:LinkMsgModel,link:link}[code=csharp]
[/code] //发送链接消息
$.ajax({
url: "/api/dd/" + actionName,
type: "Post",
contentType: 'application/json',
data: JSON.stringify({
linkMsgModel: {
PicUrl: "'@lAjPBY0V4soLGfPOK4j7vs4jjlda'",
Title: "66655tttt"
},
link: {
Text: "111111",
Touser: "2222222"
}
}
),
success: function (data) {
alert(data);
}
2.后台:
Route("SendLinkMsgUser")]
[HttpPost]
public void SendLinkMsgUser(object linkMsgModel,object link)
{
var msgModel = new LinkMsgModel()
{
// Agentid = linkMsgModel.Agentid,
Link = new Link()
{
//MessageUrl = link.MessageUrl,
//PicUrl = link.PicUrl,
//Title = link.Title,
//Text = link.Text,
},
//Agentid=linkMsgModel.Agentid,
//Touser=linkMsgModel.Touser
// Touser = linkMsgModel.Touser
};
}