/// <summary> /// 获取用户网页授权的地址 /// </summary> /// <param name="userName">公众号</param> /// <param name="redirectUrl">用户授权之后的回调地址</param> /// <param name="scope">应用授权作用域</param> /// <param name="state">重定向之后的state参数</param> /// <returns>返回用户网页授权的地址;如果获取公众号信息失败或者参数错误,返回空字符串。</returns> public static string GetOAuthUrl(string userName, string redirectUrl, OAuthScopeEnum scope, string state = null) { string url = string.Empty; AccountInfo account = AccountInfoCollection.GetAccountInfo(userName); if (account == null) { return(url); } if (string.IsNullOrWhiteSpace(redirectUrl)) { return(url); } if (state == null) { state = string.Empty; } if (state.Length > maxStateLength) { return(url); } foreach (char c in state) { if (!char.IsLetterOrDigit(c)) { return(url); } } url = string.Format(urlForGettingOAuthUrl, account.AppId, HttpUtility.UrlEncode(redirectUrl), scope.ToString("g"), state); return(url); }
/// <summary> /// 返回XML格式的响应消息 /// </summary> /// <param name="encryptType">消息加密类型</param> /// <returns>返回XML格式的响应消息</returns> public string ToXml(MessageEncryptTypeEnum encryptType) { int WXBizMsgCrypt_OK = 0; //得到未加密的XML响应消息 string xml = ToXml(); //如果需要加密,加密消息 if (encryptType == MessageEncryptTypeEnum.aes) { int timeStamp = Utility.ToWeixinTime(CreateTime); Random random = new Random(); string nonce = random.Next().ToString(); AccountInfo account = AccountInfoCollection.GetAccountInfo(FromUserName); if (account != null) { WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(account.Token, account.EncodingAESKey, account.AppId); string xmlEncrypt = ""; //加密消息 if (wxcpt.EncryptMsg(xml, timeStamp.ToString(), nonce, ref xmlEncrypt) == WXBizMsgCrypt_OK) { return(xmlEncrypt); } } } return(xml); }
static void DeleteAllAccounts() { var coll = new AccountInfoCollection(); coll.LoadAll(); coll.MarkAllAsDeleted(); coll.Save(); }
static void PrintAllAccount() { var acc = new AccountInfoCollection(); if (acc.LoadAll()) { foreach (AccountInfo empp in acc) { Console.WriteLine(empp.Address); } } }
static void AddAccount(AccountInfo account) { var coll = new AccountInfoCollection(); AccountInfo emp = coll.AddNew(); emp.Name = account.Name; emp.Id = account.Id; emp.Address = account.Address; emp.Age = account.Age; coll.Save(); }
static void DeleteAccount(Guid id) { var accountColl = new AccountInfoCollection(); accountColl.LoadAll(); AccountInfo emp = accountColl.FindByPrimaryKey(id); if (emp != null) { emp.MarkAsDeleted(); accountColl.Save(); } }
protected void Application_Start() { Application["OnLineUserCount"] = 0; AreaRegistration.RegisterAllAreas(); WebApiConfig.Register(GlobalConfiguration.Configuration); FilterConfig.RegisterGlobalFilters(GlobalFilters.Filters); RouteConfig.RegisterRoutes(RouteTable.Routes); BundleConfig.RegisterBundles(BundleTable.Bundles); DirParent = Server.MapPath("~/"); DirSiteFile = DirParent + "ErrorDetailLog\\"; Log.LogWritePath = string.Format(DirSiteFile + "Error\\{{0:ddHHmm}}.txt"); WangZhanPath._DirSiteFile = DirSiteFile; //加入测试公众号 AccountInfoCollection.SetAccountInfo(new AccountInfo("测试公众号", "wxbf1387e25455a9e3", "a680e1ecaa818a7a25f9516ffe457c48", "cjwFreedom", "45oa1QcJZ5tcmDEA6N1BzJLmHasol8tfPKEAlnj5bVv", "测试公众号")); //个人订阅号 //AccountInfoCollection.SetAccountInfo(new AccountInfo("第一维", "wx1d85b4b8b1daa55c", "7ae69a5f17c19340dde77bd017f4ca2e ", "cjwFreedom", "45oa1QcJZ5tcmDEA6N1BzJLmHasol8tfPKEAlnj5bVv", "第一维")); }
/// <summary> /// 验证消息的有效性 /// </summary> /// <param name="context"></param> /// <returns>如果消息有效,返回true;否则返回false。</returns> private bool Validate() { string username = "******"; //在接口配置的URL中加入了username参数,表示哪个微信公众号 AccountInfo account = AccountInfoCollection.GetAccountInfo(username); if (account == null) { return(false); } string token = account.Token; string signature = RequestEx.TryGetQueryString("signature"); string timestamp = RequestEx.TryGetQueryString("timestamp"); string nonce = RequestEx.TryGetQueryString("nonce"); if (string.IsNullOrWhiteSpace(signature) || string.IsNullOrWhiteSpace(timestamp) || string.IsNullOrWhiteSpace(nonce)) { return(false); } return(Utility.CheckSignature(signature, token, timestamp, nonce)); }
/// <summary> /// 解密消息 /// </summary> /// <returns>返回解密之后的消息</returns> private string DecryptMessage(string content) { string msg = ""; XmlDocument doc = new XmlDocument(); doc.LoadXml(content); XmlNode root = doc.FirstChild; string userName = root["ToUserName"].InnerText; AccountInfo account = AccountInfoCollection.GetAccountInfo(userName); if (account == null) { return(msg); } WXBizMsgCrypt wxcpt = new WXBizMsgCrypt(account.Token, account.EncodingAESKey, account.AppId); string msg_signature = RequestEx.TryGetQueryString("msg_signature", "", request); string timestamp = RequestEx.TryGetQueryString("timestamp", "", request); string nonce = RequestEx.TryGetQueryString("nonce", "", request); wxcpt.DecryptMsg(msg_signature, timestamp, nonce, content, ref msg); return(msg); }
/// <summary> /// 刷新access token /// </summary> /// <param name="userName">公众号</param> /// <param name="refreshToken">用户刷新token</param> /// <param name="errorMessage">返回获取是否成功</param> /// <returns>返回access token;如果获取失败,返回null。</returns> public static OAuthAccessToken Refresh(string userName, string refreshToken, out ErrorMessage errorMessage) { OAuthAccessToken token = null; if (string.IsNullOrWhiteSpace(refreshToken)) { errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "用户刷新token不能为空。"); return(token); } AccountInfo account = AccountInfoCollection.GetAccountInfo(userName); if (account == null) { errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "获取公众号信息失败。"); return(token); } string url = string.Format(urlForRefreshingAccessToken, account.AppId, refreshToken); string responseContent; if (!HttpHelper.Request(url, out responseContent, httpMethod, (string)null)) { errorMessage = new ErrorMessage(ErrorMessage.ExceptionCode, "从微信服务器获取响应失败。"); } else if (ErrorMessage.IsErrorMessage(responseContent)) { errorMessage = ErrorMessage.Parse(responseContent); } else { var result = JsonConvert.DeserializeAnonymousType(responseContent, new { access_token = "", expires_in = 0, refresh_token = "", openid = "", scope = "" }); token = new OAuthAccessToken(result.access_token, result.expires_in, result.refresh_token, result.openid, result.scope); errorMessage = new ErrorMessage(ErrorMessage.SuccessCode, "获取access token成功。"); } return(token); }
public ApplicationData() { #if DEBUG if (_uniqueInstance != null) { //you used the wrong binding //use: //<properties:ApplicationData x:Key="ApplicationData" /> //{Binding Databases, Source={x:Static p:ApplicationData.Instance}} //{Binding Source={x:Static p:ApplicationData.Instance}, Path=ActiveDatabase.GeocacheCollection} System.Diagnostics.Debugger.Break(); } #endif this.Logger = new Core.Logger(); string s = Settings.Default.AccountInfos; //s = ""; if (string.IsNullOrEmpty(s)) { AccountInfos = new AccountInfoCollection(); } else { Type[] itemTypes = { typeof(AccountInfo) }; XmlSerializer serializer = new XmlSerializer(typeof(AccountInfoCollection), itemTypes); using (StringReader r = new StringReader(s)) { AccountInfos = serializer.Deserialize(r) as AccountInfoCollection; } } GeocacheAttributes = new GeocacheAttributeCollection(); Databases = new Storage.DatabaseCollection(); GeocacheTypes = new GeocacheTypeCollection(); GeocacheContainers = new GeocacheContainerCollection(); WaypointTypes = new WaypointTypeCollection(); LogTypes = new LogTypeCollection(); HomeLocation = new Location(Settings.Default.HomeLocationLat, Settings.Default.HomeLocationLon); CenterLocation = new Location(Settings.Default.CenterLocationLat, Settings.Default.CenterLocationLon); HomeLocation.PropertyChanged += HomeLocation_PropertyChanged; CenterLocation.PropertyChanged += CenterLocation_PropertyChanged; AccountInfos.CollectionChanged += AccountInfos_CollectionChanged; string[] accountPrefixes = new string[] { "GC", "OX", "OB", "OC", "MZ", "OU", "OP", "GS" }; foreach (string acc in accountPrefixes) { if (AccountInfos.GetAccountInfo(acc) == null) { AccountInfos.Add(new AccountInfo(acc, "")); } } addCacheType(0, "Not present"); addCacheType(2, "Traditional Cache"); addCacheType(3, "Multi-cache"); addCacheType(4, "Virtual Cache"); addCacheType(5, "Letterbox Hybrid"); addCacheType(6, "Event Cache"); addCacheType(8, "Unknown (Mystery) Cache", "Unknown Cache"); addCacheType(9, "Project APE Cache"); addCacheType(11, "Webcam Cache"); addCacheType(12, "Locationless (Reverse) Cache"); addCacheType(13, "Cache In Trash Out Event"); addCacheType(137, "Earthcache"); addCacheType(453, "Mega-Event Cache"); addCacheType(605, "Geocache Course"); addCacheType(1304, "GPS Adventures Exhibit"); addCacheType(1858, "Wherigo Cache"); addCacheType(3653, "Lost and Found Event Cache"); addCacheType(3773, "Groundspeak HQ"); addCacheType(3774, "Groundspeak Lost and Found Celebration"); addCacheType(4738, "Groundspeak Block Party"); addCacheType(7005, "Giga-Event Cache"); addCacheType(95342, "Munzee", Core.Settings.Default.MunzeeGPXTagMunzee); addCacheType(95343, "Virtual Munzee", Core.Settings.Default.MunzeeGPXTagVirtual); addCacheType(95344, "Maintenance Munzee", Core.Settings.Default.MunzeeGPXTagMaintenance); addCacheType(95345, "Business Munzee", Core.Settings.Default.MunzeeGPXTagBusiness); addCacheType(95346, "Mystery Munzee", Core.Settings.Default.MunzeeGPXTagMystery); addCacheType(95347, "NFC Munzee", Core.Settings.Default.MunzeeGPXTagNFC); addCacheType(95348, "Premium Munzee", Core.Settings.Default.MunzeeGPXTagPremium); addCacheType(96001, "OC Traditional Cache", "Traditional Cache"); addCacheType(96002, "OC Multi-cache", "Multi-cache"); addCacheType(96003, "OC Virtual Cache", "Virtual Cache"); addCacheType(96004, "OC Event Cache", "Event Cache"); addCacheType(96005, "OC Unknown (Mystery) Cache", "Unknown Cache"); addCacheType(96006, "OC Webcam Cache", "Webcam Cache"); addCacheType(96007, "OC Moving Cache", "Locationless (Reverse) Cache"); addCacheType(96008, "OC Quiz Cache", "Unknown Cache"); addCacheType(96009, "OC Drive-in Cache", "Traditional Cache"); addCacheType(97001, "Civil", Core.Settings.Default.GeoSpyGPXTagCivil); addCacheType(97002, "Historic and religious", Core.Settings.Default.GeoSpyGPXTagHistoricAndReligious); addCacheType(97003, "Natural", Core.Settings.Default.GeoSpyGPXTagNatural); addCacheType(97004, "Technical", Core.Settings.Default.GeoSpyGPXTagTechnical); addCacheType(97005, "Military", Core.Settings.Default.GeoSpyGPXTagMilitary); addCacheContainer(0, "Unknown"); addCacheContainer(1, "Not chosen"); addCacheContainer(2, "Micro"); addCacheContainer(3, "Regular"); addCacheContainer(4, "Large"); addCacheContainer(5, "Virtual"); addCacheContainer(6, "Other"); addCacheContainer(8, "Small"); addLogType(0, "Unknown", false); addLogType(1, "Unarchive", false); addLogType(2, "Found it", true); addLogType(3, "Didn't find it", false); addLogType(4, "Write note", false); addLogType(5, "Archive", false); addLogType(6, "Archive", false); addLogType(7, "Needs Archived", false); addLogType(8, "Mark Destroyed", false); addLogType(9, "Will Attend", false); addLogType(10, "Attended", true); addLogType(11, "Webcam Photo Taken", true); addLogType(12, "Unarchive", false); addLogType(13, "Retrieve It from a Cache", false); addLogType(14, "Dropped Off", false); addLogType(15, "Transfer", false); addLogType(16, "Mark Missing", false); addLogType(17, "Recovered", false); addLogType(18, "Post Reviewer Note", false); addLogType(19, "Grab It (Not from a Cache)", false); addLogType(20, "Write Jeep 4x4 Contest Essay", false); addLogType(21, "Upload Jeep 4x4 Contest Photo", false); addLogType(22, "Temporarily Disable Listing", false); addLogType(23, "Enable Listing", false); addLogType(24, "Publish Listing", false); addLogType(25, "Retract Listing", false); addLogType(30, "Uploaded Goal Photo for \"A True Original\"", false); addLogType(31, "Uploaded Goal Photo for \"Yellow Jeep Wrangler\"", false); addLogType(32, "Uploaded Goal Photo for \"Construction Site\"", false); addLogType(33, "Uploaded Goal Photo for \"State Symbol\"", false); addLogType(34, "Uploaded Goal Photo for \"American Flag\"", false); addLogType(35, "Uploaded Goal Photo for \"Landmark/Memorial\"", false); addLogType(36, "Uploaded Goal Photo for \"Camping\"", false); addLogType(37, "Uploaded Goal Photo for \"Peaks and Valleys\"", false); addLogType(38, "Uploaded Goal Photo for \"Hiking\"", false); addLogType(39, "Uploaded Goal Photo for \"Ground Clearance\"", false); addLogType(40, "Uploaded Goal Photo for \"Water Fording\"", false); addLogType(41, "Uploaded Goal Photo for \"Traction\"", false); addLogType(42, "Uploaded Goal Photo for \"Tow Package\"", false); addLogType(43, "Uploaded Goal Photo for \"Ultimate Makeover\"", false); addLogType(44, "Uploaded Goal Photo for \"Paint Job\"", false); addLogType(45, "Needs Maintenance", false); addLogType(46, "Owner Maintenance", false); addLogType(47, "Update Coordinates", false); addLogType(48, "Discovered It", false); addLogType(49, "Uploaded Goal Photo for \"Discovery\"", false); addLogType(50, "Uploaded Goal Photo for \"Freedom\"", false); addLogType(51, "Uploaded Goal Photo for \"Adventure\"", false); addLogType(52, "Uploaded Goal Photo for \"Camaraderie\"", false); addLogType(53, "Uploaded Goal Photo for \"Heritage\"", false); addLogType(54, "Reviewer Note", false); addLogType(55, "Lock User (Ban)", false); addLogType(56, "Unlock User (Unban)", false); addLogType(57, "Groundspeak Note", false); addLogType(58, "Uploaded Goal Photo for \"Fun\"", false); addLogType(59, "Uploaded Goal Photo for \"Fitness\"", false); addLogType(60, "Uploaded Goal Photo for \"Fighting Diabetes\"", false); addLogType(61, "Uploaded Goal Photo for \"American Heritage\"", false); addLogType(62, "Uploaded Goal Photo for \"No Boundaries\"", false); addLogType(63, "Uploaded Goal Photo for \"Only in a Jeep\"", false); addLogType(64, "Uploaded Goal Photo for \"Discover New Places\"", false); addLogType(65, "Uploaded Goal Photo for \"Definition of Freedom\"", false); addLogType(66, "Uploaded Goal Photo for \"Adventure Starts Here\"", false); addLogType(67, "Needs Attention", false); addLogType(68, "Post Reviewer Note", false); addLogType(69, "Move To Collection", false); addLogType(70, "Move To Inventory", false); addLogType(71, "Throttle User", false); addLogType(72, "Enter CAPTCHA", false); addLogType(73, "Change Username", false); addLogType(74, "Announcement", false); addLogType(75, "Visited", false); addWaypointType(0, "Unknown"); addWaypointType(217, "Parking Area"); addWaypointType(220, "Final Location"); addWaypointType(218, "Question to Answer"); addWaypointType(452, "Reference Point"); addWaypointType(219, "Stages of a Multicache"); addWaypointType(221, "Trailhead"); addCacheAttribute(0, "Unknown"); addCacheAttribute(1, "Dogs"); addCacheAttribute(2, "Access or parking fee"); addCacheAttribute(3, "Climbing gear"); addCacheAttribute(4, "Boat"); addCacheAttribute(5, "Scuba gear"); addCacheAttribute(6, "Recommended for kids"); addCacheAttribute(7, "Takes less than an hour"); addCacheAttribute(8, "Scenic view"); addCacheAttribute(9, "Significant Hike"); addCacheAttribute(10, "Difficult climbing"); addCacheAttribute(11, "May require wading"); addCacheAttribute(12, "May require swimming"); addCacheAttribute(13, "Available at all times"); addCacheAttribute(14, "Recommended at night"); addCacheAttribute(15, "Available during winter"); addCacheAttribute(16, "Cactus"); addCacheAttribute(17, "Poison plants"); addCacheAttribute(18, "Dangerous Animals"); addCacheAttribute(19, "Ticks"); addCacheAttribute(20, "Abandoned mines"); addCacheAttribute(21, "Cliff / falling rocks"); addCacheAttribute(22, "Hunting"); addCacheAttribute(23, "Dangerous area"); addCacheAttribute(24, "Wheelchair accessible"); addCacheAttribute(25, "Parking available"); addCacheAttribute(26, "Public transportation"); addCacheAttribute(27, "Drinking water nearby"); addCacheAttribute(28, "Public restrooms nearby"); addCacheAttribute(29, "Telephone nearby"); addCacheAttribute(30, "Picnic tables nearby"); addCacheAttribute(31, "Camping available"); addCacheAttribute(32, "Bicycles"); addCacheAttribute(33, "Motorcycles"); addCacheAttribute(34, "Quads"); addCacheAttribute(35, "Off-road vehicles"); addCacheAttribute(36, "Snowmobiles"); addCacheAttribute(37, "Horses"); addCacheAttribute(38, "Campfires"); addCacheAttribute(39, "Thorns"); addCacheAttribute(40, "Stealth required"); addCacheAttribute(41, "Stroller accessible"); addCacheAttribute(42, "Needs maintenance"); addCacheAttribute(43, "Watch for livestock"); addCacheAttribute(44, "Flashlight required"); addCacheAttribute(45, "Lost And Found Tour"); addCacheAttribute(46, "Truck Driver/RV"); addCacheAttribute(47, "Field Puzzle"); addCacheAttribute(48, "UV Light Required"); addCacheAttribute(49, "Snowshoes"); addCacheAttribute(50, "Cross Country Skis"); addCacheAttribute(51, "Special Tool Required"); addCacheAttribute(52, "Night Cache"); addCacheAttribute(53, "Park and Grab"); addCacheAttribute(54, "Abandoned Structure"); addCacheAttribute(55, "Short hike (less than 1km)"); addCacheAttribute(56, "Medium hike (1km-10km)"); addCacheAttribute(57, "Long Hike (+10km)"); addCacheAttribute(58, "Fuel Nearby"); addCacheAttribute(59, "Food Nearby"); addCacheAttribute(60, "Wireless Beacon"); addCacheAttribute(61, "Partnership Cache"); addCacheAttribute(62, "Seasonal Access"); addCacheAttribute(63, "Tourist Friendly"); addCacheAttribute(64, "Tree Climbing"); addCacheAttribute(65, "Front Yard (Private Residence)"); addCacheAttribute(66, "Teamwork Required"); addCacheAttribute(106, "Only loggable at Opencaching"); addCacheAttribute(108, "Letterbox (needs stamp)"); addCacheAttribute(123, "First aid available"); addCacheAttribute(125, "Long walk"); addCacheAttribute(127, "Hilly area"); addCacheAttribute(130, "Point of interest"); addCacheAttribute(132, "Webcam"); addCacheAttribute(133, "Within enclosed rooms (caves, buildings etc."); addCacheAttribute(134, "In the water"); addCacheAttribute(135, "Without GPS (letterboxes, cistes, compass juggling ...)"); addCacheAttribute(137, "Overnight stay necessary"); addCacheAttribute(139, "Only available at specified times"); addCacheAttribute(140, "By day only"); addCacheAttribute(141, "Tide"); addCacheAttribute(142, "All seasons"); addCacheAttribute(143, "Breeding season / protected nature"); addCacheAttribute(147, "Compass"); addCacheAttribute(150, "Cave equipment"); addCacheAttribute(153, "Aircraft"); addCacheAttribute(154, "Investigation"); addCacheAttribute(156, "Arithmetical problem"); addCacheAttribute(157, "Other cache type"); addCacheAttribute(158, "Ask owner for start conditions"); List <Core.Data.GeocacheAttribute> attrs = (from a in this.GeocacheAttributes select a).ToList(); foreach (Core.Data.GeocacheAttribute a in attrs) { if (a.ID > 0) { addCacheAttribute(-a.ID, a.Name); } } }
/************************************************************************/ #region Constructor (internal) /// <summary> /// Initializes a new instance of the <see cref="InformationMessageSet"/> class. /// </summary> /// <param name="xmlDoc">The xml document</param> /// <param name="messageSetVersion">The message set version to use.</param> internal InformationMessageSet(XmlDocument xmlDoc, int messageSetVersion) : base(messageSetVersion) { Payees = new PayeeCollection(GetNestedNode(xmlDoc.FirstChild, MessageSetName1)); AccountInfo = new AccountInfoCollection(GetNestedNode(xmlDoc.FirstChild, MessageSetName2)); }