public static string Handle <APP>(string code, string state, IWxAuthorize wxAuthorize) where APP : new()
        {
            var cfg       = (IWxApp) new APP();
            var returnUrl = state;
            //获取令牌
            var url = cfg.UrlAccessToken +
                      "?appid=" + cfg.AppId +
                      "&secret=" + cfg.AppSecret +
                      "&code=" + code +
                      "&grant_type=authorization_code";
            var m = HttpGet <AccessTokenModel>(url);

            //-----------------判断授权模式
            if (!m.scope.HasValue())
            {
                return("");
            }
            //全新授权
            if (m.scope == "snsapi_userinfo")
            {
                var userinfoUrl = cfg.UrlUserinfo +
                                  "?access_token=" + m.access_token +
                                  "&openid=" + m.openid +
                                  "&lang=zh_CN";
                var userInfo = HttpGet <UserInfoModel>(userinfoUrl);
                if (!userInfo.openid.HasValue() || !wxAuthorize.Regist(userInfo))
                {
                    throw new Exception("绑定失败,请重试:request fail to" + userinfoUrl + "\r\n" +
                                        "AccessTokenModel=>" + m.Serialize() + "\r\n" +
                                        "UserInfoModel=>" + userInfo.Serialize() + "\r\n"
                                        );
                }
                return(BackToBll(m.openid, returnUrl, "恭喜绑定成功"));
            }
            //静默授权
            else
            {
                if (wxAuthorize.CheckRegistInfo(m.openid))
                {//注册信息完整,返回业务代码
                    return(BackToBll(m.openid, returnUrl, "老用户"));
                }
                else
                {//注册信息不完整,回滚注册信息并重新授权
                    wxAuthorize.RollbackRegistInfo(m.openid);
                    //重定向到手动授权
                    return(FullAuthorize <APP>(returnUrl));
                }
            }
        }
        public static string HandleDebug <APP>(string type, string returnUrl, string openid, IWxAuthorize wxAuthorize) where APP : new()
        {
            //-----------------判断授权模式

            //全新授权
            if (type == "snsapi_userinfo")
            {
                if (!openid.HasValue() || !wxAuthorize.Regist(new UserInfoModel()
                {
                    openid = openid,
                    nickname = "test-debug"
                }))
                {
                    throw new Exception("绑定失败");
                }
                return(BackToBll(openid, returnUrl, "恭喜绑定成功"));
            }
            //静默授权
            else
            {
                if (wxAuthorize.CheckRegistInfo(openid))
                {//注册信息完整,返回业务代码
                    return(BackToBll(openid, returnUrl, "老用户"));
                }
                else
                {//注册信息不完整,回滚注册信息并重新授权
                    wxAuthorize.RollbackRegistInfo(openid);
                    //重定向到手动授权
                    return(FullAuthorize <APP>(returnUrl));
                }
            }
        }