Oauth.cs 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115
  1. using System;
  2. using System.Collections.Generic;
  3. using System.Linq;
  4. using System.Text;
  5. using System.IO;
  6. using System.Web;
  7. using CP.Cache;
  8. using CP.Common;
  9. using CP.Model;
  10. namespace CP.Business
  11. {
  12. public class Oauth
  13. {
  14. static WMCache cache = WMCache.GetCacheService();
  15. /// <summary>
  16. /// 生成第三方登录数据.
  17. /// </summary>
  18. /// <param name="info"></param>
  19. /// <returns></returns>
  20. public static int CreateOauthInfo(OauthInfo info)
  21. {
  22. return OauthData.CreateOauthInfo(info);
  23. }
  24. /// <summary>
  25. /// 删除某个绑定数据
  26. /// </summary>
  27. /// <param name="id"></param>
  28. public static void DeleteUserOauthInfo(int id, long uid)
  29. {
  30. OauthData.DeleteUserOauthInfo(id, uid);
  31. }
  32. /// <summary>
  33. /// 某个用户的所有绑定信息
  34. /// </summary>
  35. /// <param name="uid"></param>
  36. /// <returns></returns>
  37. public static List<OauthInfo> GetUserOauthList(long uid)
  38. {
  39. return OauthData.GetUserOauthList(uid);
  40. }
  41. /// <summary>
  42. /// 用户第三方登录..
  43. /// </summary>
  44. /// <param name="appuid"></param>
  45. /// <param name="access_token"></param>
  46. /// <param name="oauthtype"></param>
  47. /// <returns></returns>
  48. public static UserInfo UserOauthLogin(string appuid, string access_token, int oauthtype)
  49. {
  50. string ip = Utils.GetRealIP();
  51. return OauthData.UserOauthLogin(appuid, access_token, ip, oauthtype);
  52. }
  53. /// <summary>
  54. /// 读取QQ互联配置数据
  55. /// </summary>
  56. /// <returns></returns>
  57. public static QzoneConfigInfo GetQzoneConfigInfo()
  58. {
  59. string key = CacheKeys.SYSTEM_OAUTH_QQ;
  60. QzoneConfigInfo info = cache.GetObject<QzoneConfigInfo>(key) as QzoneConfigInfo;
  61. if (info == null)
  62. {
  63. try
  64. {
  65. string json = File.ReadAllText(HttpContext.Current.Server.MapPath("~/_data/config/oauth_tencent.conf"));
  66. info = JSONUtil.ParseFormByJson<QzoneConfigInfo>(json);
  67. }
  68. catch (Exception ex)
  69. {
  70. HttpContext.Current.Response.Write(ex.Message);
  71. }
  72. cache.AddObject(key, info, (int)CacheTime.System);
  73. }
  74. return info;
  75. }
  76. /// <summary>
  77. /// 读取Sina互联配置数据
  78. /// </summary>
  79. /// <returns></returns>
  80. public static SinaConfigInfo GetSinaConfigInfo()
  81. {
  82. string key = CacheKeys.SYSTEM_OAUTH_SINA;
  83. SinaConfigInfo info = cache.GetObject<SinaConfigInfo>(key) as SinaConfigInfo;
  84. if (info == null)
  85. {
  86. try
  87. {
  88. string json = File.ReadAllText(HttpContext.Current.Server.MapPath("~/_data/config/oauth_sina.conf"));
  89. info = JSONUtil.ParseFormByJson<SinaConfigInfo>(json);
  90. }
  91. catch
  92. {
  93. }
  94. cache.AddObject(key, info, (int)CacheTime.System);
  95. }
  96. return info;
  97. }
  98. }
  99. }