Пример #1
0
        public Task <HttpResponseMessage> GetBigImage(BigImage bigImage)
        {
            ResponseBase <string> response = new ResponseBase <string>();

            try
            {
                UploadFileObj uploadFileObj = new UploadFileObj()
                {
                    MsgId          = bigImage.MsgId,
                    MsgType        = 3,
                    WxId           = bigImage.WxId,
                    ToWxId         = bigImage.ToWxId,
                    LongDataLength = bigImage.LongDataLength,
                };
                string mchId = RedisCache.CreateInstance().Get(ConstCacheKey.GetMchIdKey(uploadFileObj.WxId));
                if (string.IsNullOrEmpty(mchId))
                {
                    throw new Exception("未初始化商户Ip");
                }
                string objName = $"{FileStorageHelper.GetObjectName(mchId)}{uploadFileObj.MsgId}.png";

                var     producer = RocketMqHelper.CreateDefaultMQProducer(MqConst.UploadOssProducerGroup);
                var     buffer   = Encoding.UTF8.GetBytes(uploadFileObj.ToJson());
                Message message  = new Message(MqConst.UploadOssTopic, buffer);
                producer.SendMessage(message);



                response.Data = objName;
            }
            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(response.ToHttpResponseAsync());
        }
Пример #2
0
        public ConsumeConcurrentlyStatus consumeMessage(java.util.List list, ConsumeConcurrentlyContext ccc)
        {
            Iterator iterator = list.iterator();

            while (iterator.hasNext())
            {
                try
                {
                    var messageClientExt = iterator.next() as org.apache.rocketmq.common.message.MessageClientExt;

                    var content = Encoding.UTF8.GetString(messageClientExt.getBody());

                    UploadFileObj uploadFileObj = content.ToObj <UploadFileObj>();

                    string objName = null;
                    string mchId   = RedisCache.CreateInstance().Get(ConstCacheKey.GetMchIdKey(uploadFileObj.WxId));
                    if (string.IsNullOrEmpty(mchId))
                    {
                        throw new Exception("未初始化商户Ip");
                    }
                    WechatHelper wechatHelper = new WechatHelper();
                    //图片
                    if (uploadFileObj.MsgType == 3)
                    {
                        byte[] buffer = wechatHelper.GetMsgBigImg(uploadFileObj.LongDataLength, uploadFileObj.MsgId, uploadFileObj.WxId, uploadFileObj.ToWxId, 0, (int)uploadFileObj.LongDataLength);
                        if (buffer != null)
                        {
                            objName = FileStorageHelper.GetObjectName(mchId);
                            FileStorageHelper.Upload(buffer, $"{objName}{uploadFileObj.MsgId}.png");
                        }
                    }
                    //语音
                    else if (uploadFileObj.MsgType == 34)
                    {
                        if (uploadFileObj.Buffer != null)
                        {
                            objName = FileStorageHelper.GetObjectName(mchId);
                            FileStorageHelper.Upload(uploadFileObj.Buffer, $"{objName}{uploadFileObj.MsgId}.silk");
                        }
                    }
                    //视频
                    else if (uploadFileObj.MsgType == 43)
                    {
                        byte[] buffer = wechatHelper.GetVideo(uploadFileObj.WxId, uploadFileObj.ToWxId, uploadFileObj.MsgId, uploadFileObj.LongDataLength, 0, (int)uploadFileObj.LongDataLength);

                        if (buffer != null)
                        {
                            objName = FileStorageHelper.GetObjectName(mchId);
                            FileStorageHelper.Upload(buffer, $"{objName}{uploadFileObj.MsgId}.mp4");
                        }
                    }
                    //Util.Log.Logger.GetLog<UploadOssMessageListener>().Info($"消费Id:{messageClientExt.getMsgId()}--数据:{content}");
                }
                catch (Exception ex)
                {
                    Util.Log.Logger.GetLog <UploadOssMessageListener>().Error(ex);
                    return(ConsumeConcurrentlyStatus.RECONSUME_LATER);
                }
            }



            return(ConsumeConcurrentlyStatus.CONSUME_SUCCESS);
        }