Esempio n. 1
0
        public void News(string messageId, string appId, string openId, string title, string description, string url, string picUrl, bool isWxApp, 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.SendNews(accessToken, openId, title, description, url, picUrl, isWxApp);
                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...");
            }
        }
Esempio n. 2
0
 public MessageResult SendNews(NewsBody body, string toUser = null, string toParty = null, string toTag = null, int safe = 0)
 {
     return(MessageApi.SendNews(AppKey, AppConfig.AgentId, body, toUser, toParty, toTag, safe));
 }