Example #1
0
        /// <summary>
        /// 根据公众号用户信息,添加相应的QrCode
        /// </summary>
        /// <param name="userProfile"></param>
        /// <returns></returns>
        private QrCode AddQrCode(UserProfile userProfile)
        {
            lock (_object)
            {
                var expireSpan = new TimeSpan(0, 12, 0); //过期时间
                var token = AccessTokenContainer.TryGetToken(userProfile.AppId, userProfile.AppSecret);
                var sceneId = "1" + DateTime.Now.ToString("HHmmssff");
                var createQrCodeResult = QrCodeApi.Create(token, sceneId, Convert.ToInt32(expireSpan.TotalSeconds));
                var qrcodeUrl = QrCodeApi.GetShowQrCodeUrl(createQrCodeResult.ticket);

                #region 保存二维码

                if (!string.IsNullOrEmpty(qrcodeUrl))
                {
                    var qrCode = new QrCode
                    {
                        SceneId = sceneId,
                        UserId = userProfile.UserId,
                        Type = OrCodeType.Award,
                        QrCodeUrl = qrcodeUrl,
                        ExpireTime = DateTime.Now.Add(expireSpan)
                    };

                    _qrCodeRepository.Add(qrCode);
                    _qrCodeRepository.Context.Commit();
                    return qrCode;
                }

                #endregion

                throw new Exception("生成二维码失败");
            }
        }
Example #2
0
        public ResponseMessageBase GetResponseMessage(RequestMessageEventBase requestMessage)
        {
            UserProfile up = new UserProfile();
            var Buttons = up.Buttons;
            ResponseMessageBase responseMessage = null;
            switch (requestMessage.Event)
            {
                case Event.ENTER:
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        strongResponseMessage.Content = "您刚才发送了ENTER事件请求。";
                        responseMessage = strongResponseMessage;
                        break;
                    }
                case Event.LOCATION:
                    throw new Exception("暂不可用");
                //break;
                case Event.subscribe://订阅
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();

                        //获取Senparc.Weixin.MP.dll版本信息
                        var fileVersionInfo = FileVersionInfo.GetVersionInfo(HttpContext.Current.Server.MapPath("~/bin/EasyWeixin.dll"));
                        var version = fileVersionInfo.FileVersion;
                        strongResponseMessage.Content = string.Format(
                            "欢迎关注【Senparc.Weixin.MP 微信公众平台SDK】,当前运行版本:v{0}。\r\n您还可以发送【位置】【图片】【语音】信息,查看不同格式的回复。\r\nSDK官方地址:http://weixin.senparc.com",
                            version);
                        responseMessage = strongResponseMessage;
                        break;
                    }
                case Event.unsubscribe://退订
                    {
                        //实际上用户无法收到非订阅账号的消息,所以这里可以随便写。
                        //unsubscribe事件的意义在于及时删除网站应用中已经记录的OpenID绑定,消除冗余数据。
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        strongResponseMessage.Content = "有空再来";
                        responseMessage = strongResponseMessage;
                        break;
                    }
                case Event.CLICK://菜单点击事件,根据自己需要修改
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        foreach (var Button in Buttons)
                        {
                            if (Button.SubButtons.Count == 0)
                            {
                                if (Button.key == requestMessage.EventKey)
                                {
                                }
                            }
                            else
                            {
                                foreach (var Subitem in Button.SubButtons)
                                {
                                    if (Subitem.key == requestMessage.EventKey)
                                    {
                                    }
                                }
                            }
                        }

                        //throw new Exception("Demo中还没有加入CLICK的测试!");
                        break;
                    }
                case Event.VIEW://菜单点击事件,根据自己需要修改
                    {
                        var strongResponseMessage = requestMessage.CreateResponseMessage<ResponseMessageText>();
                        //requestMessage.EventKey

                        break;
                    }
                //break;
                default:
                    throw new ArgumentOutOfRangeException();
            }

            return responseMessage;
        }
Example #3
0
 //first:构造函数
 //seconed:testInintialize
 //thried:testMethod
 public UnitTest1()
 {
     _userRepo = _container.Resolve(typeof(UserProfileRepository)) as IUserProfileRepository;
     _qrCodeRepo = _container.Resolve(typeof(QrCodeRepository)) as IQrCodeRepository;
     _userProfile = _userRepo.FindAll().Single(s => s.UserName == "ipow");
 }