Exemplo n.º 1
0
        public void Text(string messageId, string appId, string openId, string content, PerformContext context)
        {
            var messageStatus = new MessageStatus(_redis, messageId);

            messageStatus.Sended(openId);
            context.WriteLine("向用户「{0}」@「{1}」发送文本消息...", openId, appId);
            var accessToken = _redis.StringGet(CacheKey.UserAccessTokenPrefix + appId);

            if (accessToken.HasValue)
            {
                var resp = MessageApi.SendText(accessToken, openId, content);
                if (resp.ErrCode == 0)
                {
                    messageStatus.Success(openId);
                    context.WriteLine("消息发送成功...");
                }
                else
                {
                    messageStatus.SendError(openId);
                    context.WriteLine("消息发送失败:{0}...", resp.ErrMsg);
                    throw new ServiceException(resp.ErrCode, resp.ErrMsg);
                }
            }
            else
            {
                messageStatus.SendError(openId);
                context.WriteLine("消息发送失败:无法获取AccessToken...");
                throw new ServiceException(-1, "消息发送失败:无法获取AccessToken...");
            }
        }
Exemplo n.º 2
0
 public MessageResult SendText(string message, string toUser)
 {
     return(MessageApi.SendText(AppConfig.CorpId, AppConfig.Secret, AppConfig.AgentId, message, toUser));
 }