コード例 #1
0
ファイル: ChatHelper.cs プロジェクト: TravelerJ/myProject
        /// <summary>
        /// 验证是否对接iris
        /// </summary>
        /// <param name="bgNo"></param>
        /// <returns></returns>
        public bool IsToIris(string bgNo)
        {
            var config = _wxHelper.GetBasConfig(bgNo);

            if (string.IsNullOrEmpty(config.Id))
            {
                return(false);
            }
            if (config.IS_IRIS == 1)//是否推送iris
            {
                return(true);
            }
            return(false);
        }
コード例 #2
0
ファイル: CommonService.cs プロジェクト: TravelerJ/myProject
        /// <summary>
        /// 获取微信跳转链接
        /// </summary>
        /// <param name="url"></param>
        /// <param name="appId"></param>
        /// <param name="code"></param>
        /// <param name="log"></param>
        /// <returns></returns>
        public string GetWeChatUrl(string url, string appId, string code, Log log)
        {
            string openId    = "";
            string secret    = "";
            string accessUrl = "";

            #region 获取openId
            var paInfo = _wxHelper.GetPaInfo(1, c => c.PA_APPID == appId && c.DEL_FLAG == 1);
            if (paInfo == null)
            {
                log.Write("未找到公众号信息," + appId + "");
                return(url);
            }
            var config = _wxHelper.GetBasConfig(paInfo.BG_NO);
            if (config == null)
            {
                log.Write("请先维护微信基础配置");
                return(openId);
            }
            if (config.OPEN_IS_ENABLED == 0)
            {
                secret    = paInfo.PA_APPSECRET;
                accessUrl = "https://api.weixin.qq.com/sns/oauth2/access_token?appId="
                            + appId + "&secret="
                            + secret + "&code="
                            + code + "&grant_type=authorization_code";
            }
            else
            {
                var componentAppId = _configuration["AppSettings:ComponentWeixinAppID"];
                var comToken       = _wctOpTokenRepository.FirstOrDefault(c => c.DEL_FLAG == 1);
                accessUrl = string.Format(
                    "https://api.weixin.qq.com/sns/oauth2/component/access_token?appid={0}&code={1}&grant_type={2}&component_appid={3}&component_access_token={4}",
                    appId, code, "authorization_code", componentAppId, comToken.COMPONENT_ACCESS_TOKEN);
            }

            string accessRet = _wxHelper.GetUrl(accessUrl);
            log.Write("accessUrl:" + accessUrl + ";accessRet:" + accessRet);
            Dictionary <string, object> dicRet = new Dictionary <string, object>();
            try
            {
                dicRet = JsonConvert.DeserializeObject <Dictionary <string, object> >(accessRet);
                object value;
                if (dicRet.TryGetValue("openid", out value))
                {
                    openId = value.ToString();
                }

                TimeSpan ts           = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0);
                int      TimestampNow = (int)ts.TotalSeconds;
                url += "appId=" + appId + "&unitId=" + paInfo.PA_ID_NO + "&bgNo=" + paInfo.BG_NO + "" + "&openId=" + openId + "&vs=" + TimestampNow + "";
            }
            catch (Exception ex)
            {
                log.Write("Exception:" + ex.Message);
            }
            #endregion
            return(url);
        }
コード例 #3
0
        /// <summary>
        /// 处理队列预约消息
        /// </summary>
        public void ExcuteCustomerApt()
        {
            var log      = new Log("ExcuteCustomerApt");
            var aptQueue = _configuration["AptQueue"];

            try
            {
                using (var channel = _mqHelper.GetConnection().CreateModel())
                {
                    channel.QueueDeclare(aptQueue, true, false, false, null);
                    consumber = new EventingBasicConsumer(channel);
                    channel.BasicQos(0, 1, false);
                    consumber.Received += (sender, c) =>
                    {
                        try
                        {
                            var apt      = JsonConvert.DeserializeObject <AptInfo>(Encoding.UTF8.GetString(c.Body));
                            var config   = _wxHelper.GetBasConfig(apt.BG_NO);
                            var redisNum = Convert.ToInt32(config.REDIS_NUM);
                            var key      = apt.orgNo + "-" + apt.APT_CLASS + "-" + apt.CUS_PHONE_NO + "-" + apt.APT_DATE.ToString("yyyy-MM-dd") + "-" + apt.APT_TIMESPAN;
                            var redis    = _redisHelper.GetRedisClient(redisNum);
                            var flag     = _redisHelper.GetRedisClient(redisNum).Incr(key);
                            log = new Log("ExcuteCustomerApt/" + apt.BG_NO + "");
                            log.Write("开始处理队列消息");
                            redis.Expire(key, 120);
                            if (flag == 1)//用户的第一次请求,为有效请求
                            {
                                var aptNum = Convert.ToInt32(redis.GetValue(apt.orgNo + "-" + apt.APT_CLASS + "-" + apt.APT_DATE.ToString("yyyy-MM-dd") + "-" + apt.APT_TIMESPAN));
                                if (aptNum > 0 || apt.aptConfigNum == 0)
                                {
                                    log.Write("客户预约手机号:" + apt.CUS_PHONE_NO + "");
                                    var ret = InsertCRM_APT_Info(apt, log);
                                    if (!ret)
                                    {
                                        log.Write("客户:" + apt.CUS_PHONE_NO + ",预约失败");
                                    }
                                    else
                                    {
                                        log.Write("客户:" + apt.CUS_PHONE_NO + ",预约成功");
                                        if (aptNum != 0)
                                        {
                                            aptNum = aptNum - 1;
                                            redis.Set(apt.orgNo + "-" + apt.APT_CLASS + "-" + apt.APT_DATE.ToString("yyyy-MM-dd") + "-" + apt.APT_TIMESPAN, aptNum);
                                            log.Write("更改预约设置人数:" + aptNum + "");
                                        }
                                    }
                                }
                                else
                                {
                                    var ret = WxToErrMessage(apt, log);
                                    if (!ret)
                                    {
                                        log.Write("客户:" + apt.CUS_PHONE_NO + ",消息推送失败");
                                    }
                                    log.Write("预约人数已满");
                                }
                            }
                            //用户的N次请求,为无效请求
                            channel.BasicAck(c.DeliveryTag, false);
                        }
                        catch (Exception ex)
                        {
                            log.Write(ex.Message);
                        }
                    };
                    channel.BasicConsume(aptQueue, false, consumber);

                    System.Threading.Thread.Sleep(1000);
                }
            }
            catch (Exception ex)
            {
                log.Write("队列初始化异常:" + ex.Message + "");
            }
        }