Example #1
0
        public async Task <NetEaseIMResult> SendMessager <T>(NetEaseIMMessage <T> model, string functionNumber)
        {
            var _iMServerSetting = new NetEaseIMServerSetting(_dataProvider.Appkey(), _dataProvider.Appsecret());
            var functionmodel    = _dataProvider.GetFunctionModel(functionNumber);
            var interopServices  = new NetEaseIMInteropServices(functionmodel.Url);
            var list             = new List <KeyValuePair <string, string> >();

            list.Add(new KeyValuePair <string, string>("from", model.FromAccId));
            list.Add(new KeyValuePair <string, string>("ope", ((int)model.Ope).ToString()));
            list.Add(new KeyValuePair <string, string>("to", model.ToAccId));
            list.Add(new KeyValuePair <string, string>("type", ((int)model.Kind).ToString()));
            list.Add(new KeyValuePair <string, string>("body", JsonConvert.SerializeObject(model.Body)));
            list.Add(new KeyValuePair <string, string>("option", JsonConvert.SerializeObject(model.Option)));
            list.Add(new KeyValuePair <string, string>("pushcontent", model.Pushcontent));
            list.Add(new KeyValuePair <string, string>("payload", model.Payload));
            list.Add(new KeyValuePair <string, string>("ext", JsonConvert.SerializeObject(model.Ext)));
            await _dataProvider.SaveSendHistory(model, _callId);

            await _dataProvider.SaveRequest(model, _callId);

            var result = await interopServices.IMPostAsync <HttpContent, NetEaseIMResult>(_iMServerSetting, functionmodel.Name, new FormUrlEncodedContent(list));

            await _dataProvider.SaveResponse(result, _callId);

            return(result);
        }
Example #2
0
        public async Task <NetEaseIMAccountVideoTokenResult> IMFindAccountVideoToken(long videoUid, string functionNumber)
        {
            var _iMServerSetting = new NetEaseIMServerSetting(_dataProvider.Appkey(), _dataProvider.Appsecret());
            var functionmodel    = _dataProvider.GetFunctionModel(functionNumber);
            var interopServices  = new NetEaseIMInteropServices(functionmodel.Url);
            var list             = new List <KeyValuePair <string, string> >();

            list.Add(new KeyValuePair <string, string>("uid", videoUid.ToString()));
            await _dataProvider.SaveRequest(videoUid, _callId);

            var result = await interopServices.IMPostAsync <HttpContent, NetEaseIMAccountVideoTokenResult>(_iMServerSetting, functionmodel.Name, new FormUrlEncodedContent(list));

            await _dataProvider.SaveResponse(result, _callId);

            return(result);
        }
Example #3
0
        public async Task <IMMHResult> HistoryMessager(NetEaseIMMessageHistory model, string functionNumber)
        {
            var _iMServerSetting = new NetEaseIMServerSetting(_dataProvider.Appkey(), _dataProvider.Appsecret());
            var functionmodel    = _dataProvider.GetFunctionModel(functionNumber);
            var interopServices  = new NetEaseIMInteropServices(functionmodel.Url);
            var list             = new List <KeyValuePair <string, string> >();

            list.Add(new KeyValuePair <string, string>("from", model.FromAccId));
            list.Add(new KeyValuePair <string, string>("to", model.ToAccId));
            list.Add(new KeyValuePair <string, string>("begintime", model.BeginTime.ToString()));
            list.Add(new KeyValuePair <string, string>("endtime", model.EndTime.ToString()));
            list.Add(new KeyValuePair <string, string>("limit", model.Limit.ToString()));
            list.Add(new KeyValuePair <string, string>("reverse", model.Reverse.ToString()));
            await _dataProvider.SaveRequest(model, _callId);

            var result = await interopServices.IMPostAsync <HttpContent, IMMHResult>(_iMServerSetting, functionmodel.Name, new FormUrlEncodedContent(list));

            await _dataProvider.SaveResponse(result, _callId);

            return(result);
        }
        public async Task <TResult> IMPostAsync <T, TResult>(NetEaseIMServerSetting _iMServerSetting, string functionName, FormUrlEncodedContent value)
        {
            using (var httpClient = new HttpClient()) {
                httpClient.BaseAddress = new Uri(_url);
                httpClient.DefaultRequestHeaders.Add("Nonce", _iMServerSetting.Nonce);
                httpClient.DefaultRequestHeaders.Add("CurTime", _iMServerSetting.Curtime);
                httpClient.DefaultRequestHeaders.Add("CheckSum", _iMServerSetting.CheckSum);
                httpClient.DefaultRequestHeaders.Add("AppKey", _iMServerSetting.AppKey);
                httpClient.DefaultRequestHeaders.Add("ContentType", "application/x-www-form-urlencoded;charset=utf-8");
                var response = await httpClient.PostAsync(functionName, value);

                if (response.IsSuccessStatusCode)
                {
                    return(await response.Content.ReadAsAsync <TResult>());
                }
                else
                {
                    await HandleError(response);
                }

                return(default(TResult));
            }
        }