添加项目文件。
This commit is contained in:
97
common/Tnb.Thirdparty/WeChat/Internal/QYMember.cs
vendored
Normal file
97
common/Tnb.Thirdparty/WeChat/Internal/QYMember.cs
vendored
Normal file
@@ -0,0 +1,97 @@
|
||||
namespace JNPF.Extras.Thirdparty.WeChat;
|
||||
|
||||
/// <summary>
|
||||
/// 企业用户.
|
||||
/// </summary>
|
||||
public sealed class QYMember
|
||||
{
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// [创建、更新 必填]成员UserID。对应管理端的帐号,企业内必须唯一。不区分大小写,长度为1~64个字节.
|
||||
/// </summary>
|
||||
public string userid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// [创建必填]成员名称。长度为1~64个字符.
|
||||
/// </summary>
|
||||
public string name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 英文名。长度为1-64个字节,由字母、数字、点(.)、减号(-)、空格或下划线(_)组成.
|
||||
/// </summary>
|
||||
public string english_name { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 手机号码。企业内必须唯一,mobile/email二者不能同时为空.
|
||||
/// </summary>
|
||||
public string mobile { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// [创建必填]成员所属部门id列表,不超过20个.
|
||||
/// </summary>
|
||||
public long[] department { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 部门内的排序值,默认为0,成员次序以创建时间从小到大排列。数量必须和department一致,数值越大排序越前面。有效的值范围是[0, 2^32).
|
||||
/// </summary>
|
||||
public long[] order { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 职位信息。长度为0~128个字符.
|
||||
/// </summary>
|
||||
public string position { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 性别。1表示男性,2表示女性.
|
||||
/// </summary>
|
||||
public string gender { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 邮箱。长度不超过64个字节,且为有效的email格式。企业内必须唯一,mobile/email二者不能同时为空.
|
||||
/// </summary>
|
||||
public string email { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 上级字段,标识是否为上级。在审批等应用里可以用来标识上级审批人.
|
||||
/// </summary>
|
||||
public int isleader { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 启用/禁用成员。1表示启用成员,0表示禁用成员.
|
||||
/// </summary>
|
||||
public int enable { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 成员头像的mediaid,通过素材管理接口上传图片获得的mediaid.
|
||||
/// </summary>
|
||||
public string avatar_mediaid { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 座机。由1-32位的纯数字或’-‘号组成.
|
||||
/// </summary>
|
||||
public string telephone { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 自定义字段。自定义字段需要先在WEB管理端添加,见扩展属性添加方法,否则忽略未知属性的赋值。自定义字段长度为0~32个字符,超过将被截断.
|
||||
/// </summary>
|
||||
public object extattr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 摘要:
|
||||
/// 成员对外属性,字段详情见对外属性: http://work.weixin.qq.com/api/doc#13450.
|
||||
/// </summary>
|
||||
public object external_profile { get; set; }
|
||||
}
|
||||
52
common/Tnb.Thirdparty/WeChat/Internal/WechatMPEvent.cs
vendored
Normal file
52
common/Tnb.Thirdparty/WeChat/Internal/WechatMPEvent.cs
vendored
Normal file
@@ -0,0 +1,52 @@
|
||||
namespace JNPF.Extras.Thirdparty.WeChat.Internal;
|
||||
|
||||
/// <summary>
|
||||
/// 公众号事件.
|
||||
/// </summary>
|
||||
public class WechatMPEvent
|
||||
{
|
||||
/// <summary>
|
||||
/// 签名.
|
||||
/// </summary>
|
||||
public string signature { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 时间戳.
|
||||
/// </summary>
|
||||
public string timestamp { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// nonce.
|
||||
/// </summary>
|
||||
public string nonce { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 算出的值.
|
||||
/// </summary>
|
||||
public string echostr { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 开发者微信号.
|
||||
/// </summary>
|
||||
public string ToUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 发送方帐号(一个OpenID).
|
||||
/// </summary>
|
||||
public string FromUserName { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息创建时间 (整型).
|
||||
/// </summary>
|
||||
public long CreateTime { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 消息类型,event.
|
||||
/// </summary>
|
||||
public string MsgType { get; set; }
|
||||
|
||||
/// <summary>
|
||||
/// 事件类型,subscribe(订阅)、unsubscribe(取消订阅).
|
||||
/// </summary>
|
||||
public string Event { get; set; }
|
||||
}
|
||||
150
common/Tnb.Thirdparty/WeChat/WeChatMPUtil.cs
vendored
Normal file
150
common/Tnb.Thirdparty/WeChat/WeChatMPUtil.cs
vendored
Normal file
@@ -0,0 +1,150 @@
|
||||
using Senparc.Weixin.MP;
|
||||
using Senparc.Weixin.MP.AdvancedAPIs;
|
||||
using Senparc.Weixin.MP.AdvancedAPIs.TemplateMessage;
|
||||
using Senparc.Weixin.MP.AdvancedAPIs.User;
|
||||
using Senparc.Weixin.MP.Containers;
|
||||
|
||||
namespace JNPF.Extras.Thirdparty.WeChat;
|
||||
|
||||
/// <summary>
|
||||
/// 微信公众号.
|
||||
/// </summary>
|
||||
public class WeChatMPUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// 访问令牌.
|
||||
/// </summary>
|
||||
public string accessToken { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数.
|
||||
/// </summary>
|
||||
public WeChatMPUtil() { }
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数.
|
||||
/// </summary>
|
||||
public WeChatMPUtil(string appId, string appSecret)
|
||||
{
|
||||
try
|
||||
{
|
||||
accessToken = AccessTokenContainer.TryGetAccessToken(appId, appSecret);
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 微信后台验证地址.
|
||||
/// </summary>
|
||||
/// <param name="signature">签名.</param>
|
||||
/// <param name="timestamp">时间戳.</param>
|
||||
/// <param name="nonce">nonce.</param>
|
||||
/// <param name="echostr">算出的值.</param>
|
||||
/// <returns></returns>
|
||||
public bool CheckToken(string signature, string timestamp, string nonce)
|
||||
{
|
||||
var token = "WEIXINJNPF";
|
||||
return CheckSignature.Check(signature, timestamp, nonce, token);
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据OpenId进行群发.
|
||||
/// </summary>
|
||||
/// <param name="type">消息类型.</param>
|
||||
/// <param name="value">群发媒体文件时传入mediaId,群发文本消息时传入content,群发卡券时传入cardId.</param>
|
||||
/// <param name="clientmsgid">开发者侧群发msgid,长度限制64字节,如不填,则后台默认以群发范围和群发内容的摘要值做为clientmsgid.</param>
|
||||
/// <param name="openIds"> openId字符串数组.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
/// <returns></returns>
|
||||
public bool SendGroupMessageByOpenId(int type, string value, string[] openIds, string clientmsgid = null, int timeOut = 10000)
|
||||
{
|
||||
try
|
||||
{
|
||||
GroupMessageType messageType = new GroupMessageType();
|
||||
switch (type)
|
||||
{
|
||||
case 1://文本
|
||||
messageType = GroupMessageType.text;
|
||||
break;
|
||||
case 2://图片
|
||||
messageType = GroupMessageType.image;
|
||||
break;
|
||||
case 3://语音
|
||||
messageType = GroupMessageType.voice;
|
||||
break;
|
||||
case 4://视频
|
||||
messageType = GroupMessageType.video;
|
||||
break;
|
||||
case 5://图文
|
||||
messageType = GroupMessageType.mpnews;
|
||||
break;
|
||||
case 6:// 卡券
|
||||
messageType = GroupMessageType.wxcard;
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
var result = GroupMessageApi.SendGroupMessageByOpenId(accessToken, messageType, value, clientmsgid, timeOut, openIds);
|
||||
return result.errcode == 0;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据OpenId发送模板消息.
|
||||
/// </summary>
|
||||
/// <param name="openId"></param>
|
||||
/// <param name="templateId"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public void SendTemplateMessage(string openId, string templateId, string url, object data, TemplateModel_MiniProgram miniProgram = null)
|
||||
{
|
||||
var result = TemplateApi.SendTemplateMessage(accessToken, openId, templateId, url, data, miniProgram);
|
||||
if (result.errcode != 0)
|
||||
{
|
||||
throw new Exception(result.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 根据OpenId发送模板消息.
|
||||
/// </summary>
|
||||
/// <param name="openId"></param>
|
||||
/// <param name="templateId"></param>
|
||||
/// <param name="url"></param>
|
||||
/// <param name="data"></param>
|
||||
/// <returns></returns>
|
||||
public string GetTemplateMp(string templateId)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = TemplateApi.GetPrivateTemplate(accessToken);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
var data = result.template_list.Find(x => x.template_id == templateId);
|
||||
return data.content;
|
||||
}
|
||||
return string.Empty;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 通过openId获取用户信息.
|
||||
/// </summary>
|
||||
/// <param name="openId"></param>
|
||||
/// <returns></returns>
|
||||
public UserInfoJson GetWeChatUserInfo(string openId)
|
||||
{
|
||||
return UserApi.Info(accessToken, openId);
|
||||
}
|
||||
}
|
||||
450
common/Tnb.Thirdparty/WeChat/WeChatUtil.cs
vendored
Normal file
450
common/Tnb.Thirdparty/WeChat/WeChatUtil.cs
vendored
Normal file
@@ -0,0 +1,450 @@
|
||||
using System.Text.Json;
|
||||
using Senparc.Weixin.Work.AdvancedAPIs;
|
||||
using Senparc.Weixin.Work.AdvancedAPIs.MailList;
|
||||
using Senparc.Weixin.Work.AdvancedAPIs.MailList.Member;
|
||||
using Senparc.Weixin.Work.Containers;
|
||||
|
||||
namespace JNPF.Extras.Thirdparty.WeChat;
|
||||
|
||||
/// <summary>
|
||||
/// 企业号微信.
|
||||
/// </summary>
|
||||
public class WeChatUtil
|
||||
{
|
||||
/// <summary>
|
||||
/// 访问令牌.
|
||||
/// </summary>
|
||||
public string accessToken { get; private set; }
|
||||
|
||||
/// <summary>
|
||||
/// 构造函数.
|
||||
/// </summary>
|
||||
public WeChatUtil(string corpId, string corpSecret, string appSecret = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
if (appSecret != null)
|
||||
corpSecret = appSecret;
|
||||
accessToken = AccessTokenContainer.TryGetToken(corpId, corpSecret);
|
||||
}
|
||||
catch (Exception)
|
||||
{
|
||||
}
|
||||
}
|
||||
|
||||
#region 部门
|
||||
|
||||
/// <summary>
|
||||
/// 查询部门.
|
||||
/// </summary>
|
||||
public List<DepartmentList> GetDepartmentList()
|
||||
{
|
||||
var result = MailListApi.GetDepartmentList(accessToken);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return result.department;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建部门.
|
||||
/// </summary>
|
||||
/// <param name="name">部门名称.</param>
|
||||
/// <param name="parentId">父亲部门id.</param>
|
||||
/// <param name="order">在父部门中的次序.</param>
|
||||
/// <param name="msg">返回信息.</param>
|
||||
/// <param name="id">部门id.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
/// <returns></returns>
|
||||
public string CreateDepartment(string name, long parentId, int order, ref string msg, int? id = null, int timeOut = 10000)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = MailListApi.CreateDepartment(accessToken, name, parentId);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return result.id.ToString();
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = result.errmsg;
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = string.Format("【组织{0}创建失败】{1}", name, ex.Message);
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑部门.
|
||||
/// </summary>
|
||||
/// <param name="id">部门Id.</param>
|
||||
/// <param name="name">部门名称.</param>
|
||||
/// <param name="parentId">父亲部门id.</param>
|
||||
/// <param name="order">在父部门中的次序.</param>
|
||||
/// <param name="msg">返回信息.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
/// <returns></returns>
|
||||
public bool UpdateDepartment(int? id, string name, int? parentId, int? order, ref string msg, int timeOut = 10000)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = MailListApi.UpdateDepartment(accessToken, Convert.ToInt64(id), name);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = result.errmsg;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = string.Format("【组织{0}修改失败】{1}", name, ex.Message);
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除部门.
|
||||
/// </summary>
|
||||
/// <param name="id">部门Id.</param>
|
||||
/// <param name="msg">返回信息.</param>
|
||||
/// <returns></returns>
|
||||
public bool DeleteDepartment(int? id, ref string msg)
|
||||
{
|
||||
var result = MailListApi.DeleteDepartment(accessToken, Convert.ToInt64(id));
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
msg = result.errmsg;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 获取部门成员.
|
||||
/// </summary>
|
||||
/// <param name="departmentId">获取的部门id.</param>
|
||||
/// <param name="fetchChild">1/0:是否递归获取子部门下面的成员.</param>
|
||||
/// <returns></returns>
|
||||
public List<GetMemberResult> GetDepartmentMember()
|
||||
{
|
||||
var depList = GetDepartmentList();
|
||||
var userList = new List<GetMemberResult>();
|
||||
if (depList.Count > 0)
|
||||
{
|
||||
foreach (var item in depList.Select(x => x.id))
|
||||
{
|
||||
var result = MailListApi.GetDepartmentMemberInfo(accessToken, item, 1);
|
||||
if (result.errcode == 0 && result.userlist.Count > 0)
|
||||
{
|
||||
userList = userList.Union(result.userlist).ToList();
|
||||
}
|
||||
}
|
||||
}
|
||||
return userList;
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 用户
|
||||
|
||||
/// <summary>
|
||||
/// 获取成员.
|
||||
/// </summary>
|
||||
/// <param name="userId">用户Id.</param>
|
||||
/// <returns></returns>
|
||||
public string GetMember(string userId)
|
||||
{
|
||||
var result = MailListApi.GetMember(accessToken, userId);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return JsonSerializer.Serialize(result);
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 创建成员.
|
||||
/// </summary>
|
||||
/// <param name="member">企业用户.</param>
|
||||
/// <param name="msg">返回信息.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
public bool CreateMember(QYMember member, ref string msg, int timeOut = 10000)
|
||||
{
|
||||
try
|
||||
{
|
||||
MemberCreateRequest memberCreate = new MemberCreateRequest();
|
||||
memberCreate.name = member.name;
|
||||
memberCreate.avatar_mediaid = member.avatar_mediaid;
|
||||
memberCreate.department = member.department;
|
||||
memberCreate.email = member.email;
|
||||
memberCreate.enable = member.enable;
|
||||
memberCreate.english_name = member.english_name;
|
||||
memberCreate.extattr = (Extattr)member.extattr;
|
||||
memberCreate.external_profile = (External_Profile)member.external_profile;
|
||||
memberCreate.gender = member.gender;
|
||||
memberCreate.mobile = member.mobile;
|
||||
memberCreate.order = member.order;
|
||||
memberCreate.position = member.position;
|
||||
memberCreate.telephone = member.telephone;
|
||||
memberCreate.userid = member.userid;
|
||||
var result = MailListApi.CreateMember(accessToken, memberCreate, timeOut);
|
||||
if (result.errcode == 0)
|
||||
return true;
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = ex.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 编辑成员.
|
||||
/// </summary>
|
||||
/// <param name="member">企业用户.</param>
|
||||
/// <param name="msg">返回信息.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
public bool UpdateMember(QYMember member, ref string msg, int timeOut = 10000)
|
||||
{
|
||||
try
|
||||
{
|
||||
MemberUpdateRequest memberUpdate = new MemberUpdateRequest();
|
||||
memberUpdate.name = member.name;
|
||||
memberUpdate.avatar_mediaid = member.avatar_mediaid;
|
||||
memberUpdate.department = member.department;
|
||||
memberUpdate.email = member.email;
|
||||
memberUpdate.enable = member.enable;
|
||||
memberUpdate.english_name = member.english_name;
|
||||
memberUpdate.extattr = (Extattr)member.extattr;
|
||||
memberUpdate.external_profile = (External_Profile)member.external_profile;
|
||||
memberUpdate.gender = member.gender;
|
||||
memberUpdate.mobile = member.mobile;
|
||||
memberUpdate.order = member.order;
|
||||
memberUpdate.position = member.position;
|
||||
memberUpdate.telephone = member.telephone;
|
||||
memberUpdate.userid = member.userid;
|
||||
var result = MailListApi.UpdateMember(accessToken, memberUpdate, timeOut);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
return false;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = ex.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 删除成员.
|
||||
/// </summary>
|
||||
/// <param name="userId">成员Id.</param>
|
||||
/// <param name="msg">返回信息.</param>
|
||||
/// <returns></returns>
|
||||
public bool DeleteMember(string userId, string msg = null)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = MailListApi.DeleteMember(accessToken, userId);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
return false;
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
msg = ex.Message;
|
||||
return false;
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 批量删除成员.
|
||||
/// </summary>
|
||||
/// <param name="useridlist">成员UserID列表.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
/// <returns></returns>
|
||||
public bool BatchDeleteMember(string[] useridlist, int timeOut = 10000)
|
||||
{
|
||||
var result = MailListApi.BatchDeleteMember(accessToken, useridlist, timeOut = 10000);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 手机号获取成员.
|
||||
/// </summary>
|
||||
/// <param name="mobile">手机号码.</param>
|
||||
public string GetUserid(string mobile)
|
||||
{
|
||||
try
|
||||
{
|
||||
var result = MailListApi.GetUserid(accessToken, mobile, 10000);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return result.userid;
|
||||
}
|
||||
else
|
||||
{
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
catch (Exception ex)
|
||||
{
|
||||
|
||||
return string.Empty;
|
||||
}
|
||||
}
|
||||
#endregion
|
||||
|
||||
#region 消息
|
||||
|
||||
/// <summary>
|
||||
/// 发送消息.
|
||||
/// </summary>
|
||||
/// <param name="agentId">企业应用的id.</param>
|
||||
/// <param name="content">消息内容.</param>
|
||||
/// <param name="toUser">UserID列表.</param>
|
||||
/// <param name="toParty">PartyID列表.</param>
|
||||
/// <param name="toTag">TagID列表.</param>
|
||||
/// <param name="safe">否是保密消息.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
/// <returns></returns>
|
||||
public async Task SendText(string agentId, string content, string toUser, string toParty = null, string toTag = null, int safe = 0, int timeOut = 10000)
|
||||
{
|
||||
var result = await MassApi.SendTextAsync(accessToken, agentId, content, toUser, toParty, toTag, safe);
|
||||
if (result.errcode != 0)
|
||||
{
|
||||
throw new Exception(result.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送文件消息.
|
||||
/// </summary>
|
||||
/// <param name="agentId">企业应用的id.</param>
|
||||
/// <param name="mediaId">媒体资源文件ID.</param>
|
||||
/// <param name="toUser">UserID列表.</param>
|
||||
/// <param name="toParty">PartyID列表.</param>
|
||||
/// <param name="toTag">TagID列表.</param>
|
||||
/// <param name="safe">否是保密消息.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
/// <returns></returns>
|
||||
public bool SendFile(string agentId, string mediaId, string toUser, string toParty = null, string toTag = null, int safe = 0, int timeOut = 10000)
|
||||
{
|
||||
var result = MassApi.SendFile(accessToken, agentId, mediaId, toUser, toParty, toTag, safe);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送图片消息.
|
||||
/// </summary>
|
||||
/// <param name="agentId">企业应用的id.</param>
|
||||
/// <param name="mediaId">媒体资源文件ID.</param>
|
||||
/// <param name="toUser">UserID列表.</param>
|
||||
/// <param name="toParty">PartyID列表.</param>
|
||||
/// <param name="toTag">TagID列表.</param>
|
||||
/// <param name="safe">否是保密消息.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
public bool SendImage(string agentId, string mediaId, string toUser, string toParty = null, string toTag = null, int safe = 0, int timeOut = 10000)
|
||||
{
|
||||
var result = MassApi.SendImage(accessToken, agentId, mediaId, toUser, toParty, toTag, safe);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送视频消息.
|
||||
/// </summary>
|
||||
/// <param name="agentId">企业应用的id.</param>
|
||||
/// <param name="mediaId">媒体资源文件ID.</param>
|
||||
/// <param name="toUser">UserID列表.</param>
|
||||
/// <param name="toParty">PartyID列表.</param>
|
||||
/// <param name="toTag">TagID列表.</param>
|
||||
/// <param name="title"> 视频消息的标题.</param>
|
||||
/// <param name="description">视频消息的描述.</param>
|
||||
/// <param name="safe">否是保密消息.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
/// <returns></returns>
|
||||
public bool SendVideo(string agentId, string mediaId, string toUser, string toParty = null, string toTag = null, string title = null, string description = null, int safe = 0, int timeOut = 10000)
|
||||
{
|
||||
var result = MassApi.SendVideo(accessToken, agentId, mediaId, toUser, toParty, toTag, title, description, safe);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
/// <summary>
|
||||
/// 发送语音消息.
|
||||
/// </summary>
|
||||
/// <param name="agentId">企业应用的id.</param>
|
||||
/// <param name="mediaId">媒体资源文件ID.</param>
|
||||
/// <param name="toUser">UserID列表.</param>
|
||||
/// <param name="toParty">PartyID列表.</param>
|
||||
/// <param name="toTag">TagID列表.</param>
|
||||
/// <param name="safe">否是保密消息.</param>
|
||||
/// <param name="timeOut">代理请求超时时间(毫秒).</param>
|
||||
/// <returns></returns>
|
||||
public bool SendVoice(string agentId, string mediaId, string toUser, string toParty = null, string toTag = null, int safe = 0, int timeOut = 10000)
|
||||
{
|
||||
var result = MassApi.SendVoice(accessToken, agentId, mediaId, toUser, toParty, toTag, safe);
|
||||
if (result.errcode == 0)
|
||||
{
|
||||
return true;
|
||||
}
|
||||
else
|
||||
{
|
||||
throw new Exception(result.errmsg);
|
||||
}
|
||||
}
|
||||
|
||||
#endregion
|
||||
}
|
||||
Reference in New Issue
Block a user