/// <summary>
        /// 获取聊天记录
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static GetWeChatMsgListResponse GetWeChatMsgList(GetWeChatMsgListReqeust request)
        {
            var response = new GetWeChatMsgListResponse();

            try
            {
                using (var client = new WeiXinServiceClient())
                {
                    var getResult = client.GetWeChatMsgList(request);
                    if (!getResult.Success)
                    {
                        Logger.Warn($"GetWeChatMsgList,获取聊天记录接口失败,message:{getResult.ErrorMessage}");
                    }
                    else
                    {
                        response = getResult.Result ?? new GetWeChatMsgListResponse();
                    }
                }
            }
            catch (Exception ex)
            {
                Logger.Error($"GetWeChatMsgList 接口异常,异常信息:{ex.Message},堆栈信息:{ex.StackTrace}");
            }
            return(response);
        }
Exemplo n.º 2
0
        /// <summary>
        /// 车友群小程序推送车友群或群主信息
        /// </summary>
        /// <param name="request"></param>
        /// <returns></returns>
        public static async Task <OperationResult <bool> > CarFriendsGroupPushInfoAsync(GetCarFriendsGroupPushInfoRequest request)
        {
            using (var client = new WeiXinServiceClient())
            {
                var consumerServiceRequest = new ConsumerServiceRequest();
                consumerServiceRequest.ToUserName   = "******";
                consumerServiceRequest.FromUserName = request.OpenId;
                consumerServiceRequest.MsgType      = "link";
                consumerServiceRequest.Content      = "";
                consumerServiceRequest.Event        = "event";

                if (request.InfoType == 0)
                {
                    //车友群
                    var carFriendsGroupModel = new CarFriendsGroup();
                    var carFriendsResult     = await GetCarFriendsGroupModelAsync(request.PKID);

                    if (carFriendsResult.Success && carFriendsResult.Result != null && carFriendsResult.Result.groupList != null && carFriendsResult.Result.groupList.Count > 0)
                    {
                        carFriendsGroupModel = carFriendsResult.Result.groupList[0];
                        consumerServiceRequest.Description = "点击加入";
                        consumerServiceRequest.Title       = carFriendsGroupModel.GroupName;
                        consumerServiceRequest.Thumb_url   = carFriendsGroupModel.GroupHeadPortrait;
                        //线下测试
                        //consumerServiceRequest.Url = "https://wxdev.tuhu.work/vue/vueTest/pages/home/index?_project=NaCarFriendsGroup&pkid=" + request.PKID;
                        //ut测试
                        //consumerServiceRequest.Url = "https://wxut.tuhu.cn/vue/vueTest/pages/home/index?_project=NaCarFriendsGroup&pkid=" + request.PKID;
                        //线上地址
                        consumerServiceRequest.Url = "https://wx.tuhu.cn/vue/NaCarFriendsGroup/pages/home/index?pkid=" + request.PKID;
                    }
                    else
                    {
                        return(OperationResult.FromResult(false));
                    }
                }
                else if (request.InfoType == 1)
                {
                    //群主
                    var administratorsModel  = new CarFriendsAdministratorsResponse();
                    var administratorsResult = await GetCarFriendsAdministratorsModelAsync(request.PKID);

                    if (administratorsResult.Success && administratorsResult.Result != null)
                    {
                        administratorsModel = administratorsResult.Result;
                    }
                    consumerServiceRequest.Description = "邀您入群";
                    consumerServiceRequest.Title       = "欢迎加入途虎专属群";
                    consumerServiceRequest.Thumb_url   = administratorsModel.WeChatHeadPortrait;
                    //线下测试
                    //consumerServiceRequest.Url = "https://wxdev.tuhu.work/vue/vueTest/pages/home/index?_project=NaCarFriendsGroup&infoType=1";
                    //ut测试
                    //consumerServiceRequest.Url = "https://wxut.tuhu.cn/vue/vueTest/pages/home/index?_project=NaCarFriendsGroup&infoType=1";
                    //线上地址
                    consumerServiceRequest.Url = "https://wx.tuhu.cn/vue/NaCarFriendsGroup/pages/home/index?infoType=1";
                }
                using (var redisClient = CacheHelper.CreateCounterClient(GlobalConstant.CarFriendsGroupName, TimeSpan.FromMinutes(1)))
                {
                    string key            = string.Format(GlobalConstant.CarFriendsGroupConsumerServiceKey, ":" + request.OpenId + ":" + request.UserId + ":" + request.InfoType + ":" + request.PKID + ":" + request.RandomNumberKey);
                    var    cunsumerResult = await redisClient.IncrementAsync(key);

                    if (cunsumerResult.Success && cunsumerResult.Value == 1)
                    {
                        //车友群小程序客服消息推送
                        var result = client.WechatAppCustomerServiceMessagePush(consumerServiceRequest);
                        result.ThrowIfException(true);
                        if (result.Success && result.Result)
                        {
                        }
                        else
                        {
                            await redisClient.DecrementAsync(key, 1);
                        }
                        Logger.Info(key);
                    }
                }
                return(OperationResult.FromResult(true));
            }
        }