コード例 #1
0
 /// <summary>
 /// 群发图文消息给openidlsit用户
 /// </summary>
 /// <param name="appId"></param>
 /// <param name="nextOpenId"></param>
 /// <returns></returns>
 public async Task <SendResult> SendNewsToGroupUsersAsync(string appId, string mediaId, string[] opendis)
 {
     return(await GroupMessageApi.SendGroupMessageByOpenIdAsync(appId, GroupMessageType.mpnews, mediaId, null, 1000, opendis));
 }
コード例 #2
0
 public async Task <SendResult> SendGroupTextMessageByOpenIdsAsync(string appId, string content, string clientmsgid, params string[] openIds)
 {
     return(await GroupMessageApi.SendGroupMessageByOpenIdAsync(appId,
                                                                GroupMessageType.text, content, clientmsgid, 10000, openIds));
 }
コード例 #3
0
 public async Task <SendResult> SendGroupImageMessageByOpenIdAsync(string appId, string mediaId, params string[] openIds)
 {
     return(await GroupMessageApi.SendGroupMessageByOpenIdAsync(appId, GroupMessageType.image, mediaId, ""
                                                                , 10000, openIds));
 }
コード例 #4
0
        /// <summary>
        /// 按openid群发
        /// </summary>
        /// <param name="account"></param>
        /// <param name="args"></param>
        /// <param name="openIds"></param>
        /// <returns></returns>
        private async Task <SendResult> SendByOpenIds(MpAccountDto account, MpMessageDto args, string[] openIds, IDBHelper yilidb)
        {
            SendResult result = null;

            if (args.MessageType == MpMessageType.text.ToString())
            {
                try
                {
                    result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken)).access_token, GroupMessageType.text, args.Content, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                }
                catch
                {
                    try
                    {
                        result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken, 1)).access_token, GroupMessageType.text, args.Content, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                    }
                    catch
                    {
                    }
                }
            }
            else if (args.MessageType == MpMessageType.video.ToString())
            {
                var videoId = int.Parse(args.VideoID.ToString());
                var video   = yilidb.FindOne <MpMediaVideo>("SELECT TOP 1 * FROM MpMediaVideos WHERE ID=" + videoId, null, false);
                if (video == null)
                {
                    throw new Exception(string.Format("视频{0}不存在", args.VideoName));
                }
                try
                {
                    result = await GroupMessageApi.SendVideoGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken)).access_token, video.Title, video.Description, args.VideoMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                }
                catch
                {
                    try
                    {
                        result = await GroupMessageApi.SendVideoGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken, 1)).access_token, video.Title, video.Description, args.VideoMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                    }
                    catch
                    {
                    }
                }
            }
            else if (args.MessageType == MpMessageType.voice.ToString())
            {
                try
                {
                    result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken)).access_token, GroupMessageType.voice, args.VoiceMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                }
                catch
                {
                    try
                    {
                        result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken, 1)).access_token, GroupMessageType.voice, args.VoiceMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                    }
                    catch
                    {
                    }
                }
            }
            else if (args.MessageType == MpMessageType.image.ToString())
            {
                try
                {
                    result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken)).access_token, GroupMessageType.image, args.ImageMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                }
                catch
                {
                    try
                    {
                        result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken, 1)).access_token, GroupMessageType.image, args.ImageMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                    }
                    catch
                    {
                    }
                }
            }
            else if (args.MessageType == MpMessageType.mpnews.ToString())
            {
                try
                {
                    result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken)).access_token, GroupMessageType.mpnews, args.ArticleMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                }
                catch
                {
                    try
                    {
                        result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken, 1)).access_token, GroupMessageType.mpnews, args.ArticleMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                    }
                    catch
                    {
                    }
                }
            }
            else if (args.MessageType == MpMessageType.mpmultinews.ToString())
            {
                try
                {
                    result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken)).access_token, GroupMessageType.mpnews, args.ArticleGroupMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                }
                catch
                {
                    try
                    {
                        result = await GroupMessageApi.SendGroupMessageByOpenIdAsync((await StaticObjects.GetAccessToken(account.TaskAccessToken, 1)).access_token, GroupMessageType.mpnews, args.ArticleGroupMediaID, $"MpMessage{args.Id}", Senparc.Weixin.Config.TIME_OUT, openIds.ToArray());
                    }
                    catch
                    {
                    }
                }
            }

            return(result);
        }