Esempio n. 1
0
        public async Task <HttpResponseMessage> SendVideoMessage(VideoMessage videoMessage)
        {
            ResponseBase <IList <MMPro.MM.UploadVideoResponse> > response = new ResponseBase <IList <MMPro.MM.UploadVideoResponse> >();

            try
            {
                IList <MMPro.MM.UploadVideoResponse> list = new List <MMPro.MM.UploadVideoResponse>();
                byte[] buffer = await FileStorageHelper.DownloadToBufferAsync(videoMessage.ObjectName);

                byte[] imageBuffer = await FileStorageHelper.DownloadToBufferAsync(videoMessage.ImageObjectName);

                foreach (var item in videoMessage.ToWxIds)
                {
                    var result = wechat.SendVideoMessage(videoMessage.WxId, item, videoMessage.PlayLength, buffer, imageBuffer);
                    list.Add(result);
                }
                response.Data = list;
            }
            catch (ExpiredException ex)
            {
                response.Success = false;
                response.Code    = "401";
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Code    = "500";
                response.Message = ex.Message;
            }
            return(await response.ToHttpResponseAsync());
        }
Esempio n. 2
0
        public async Task <HttpResponseMessage> SendVoiceMessage(VoiceMessage voiceMessage)
        {
            ResponseBase <IList <MMPro.MM.UploadVoiceResponse> > response = new ResponseBase <IList <MMPro.MM.UploadVoiceResponse> >();

            try
            {
                IList <MMPro.MM.UploadVoiceResponse> list = new List <MMPro.MM.UploadVoiceResponse>();
                byte[] buffer = await FileStorageHelper.DownloadToBufferAsync(voiceMessage.ObjectName);

                foreach (var item in voiceMessage.ToWxIds)
                {
                    var result = wechat.SendVoiceMessage(voiceMessage.WxId, item, buffer, voiceMessage.FileName.GetVoiceType(), voiceMessage.VoiceSecond * 100);
                    list.Add(result);
                }
                response.Data = list;
            }
            catch (ExpiredException ex)
            {
                response.Success = false;
                response.Code    = "401";
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Code    = "500";
                response.Message = ex.Message;
            }
            return(await response.ToHttpResponseAsync());
        }
Esempio n. 3
0
        public async Task <HttpResponseMessage> SendFriendCircleImage(SendFriendCircleImage sendFriendCircleImage)
        {
            ResponseBase <IList <micromsg.SnsUploadResponse> > response = new ResponseBase <IList <micromsg.SnsUploadResponse> >();

            try
            {
                IList <micromsg.SnsUploadResponse> list = new List <micromsg.SnsUploadResponse>();
                foreach (var item in sendFriendCircleImage.ObjectNames)
                {
                    var buffer = await FileStorageHelper.DownloadToBufferAsync(item);

                    var result = wechat.SnsUpload(sendFriendCircleImage.WxId, new MemoryStream(buffer));
                    if (result == null)
                    {
                        throw new Exception("上传失败");
                    }
                    list.Add(result);
                }
                response.Data    = list;
                response.Message = "上传成功";
            }
            catch (ExpiredException ex)
            {
                response.Success = false;
                response.Code    = "401";
                response.Message = ex.Message;
            }
            catch (Exception ex)
            {
                response.Success = false;
                response.Code    = "500";
                response.Message = ex.Message;
            }
            return(await response.ToHttpResponseAsync());
        }