Esempio n. 1
0
        public void WxAppCard(string messageId, string appId, string openId, string title, string pagePath, string wxAppId, string imageId, PerformContext context = null)
        {
            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.SendWxAppCard(accessToken, openId, title, wxAppId, pagePath, imageId);
                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...");
            }
        }