public string GetOpenLoginUrl(string returnUrl) { ReturnUrl = returnUrl; OAuthWXConfigInfo config = ConfigService <OAuthWXConfigInfo> .GetConfig(WXWorkDirectory + "\\Config\\OAuthWXConfig.config"); OAuthRule rule = ConfigService <OAuthRule> .GetConfig(WXWorkDirectory + "\\Config\\OAuthUrl.config"); if (string.IsNullOrEmpty(returnUrl)) { throw new PluginException("未传入回调地址!"); } if (string.IsNullOrEmpty(config.AppId)) { throw new PluginException("未设置AppId!"); } if (string.IsNullOrEmpty(config.AppSecret)) { throw new PluginException("未设置AppSecret!"); } if (string.IsNullOrEmpty(rule.GetCodeUrl)) { throw new PluginException("未设置微信接口地址!"); } string strGetCodeUrl = string.Format(rule.GetCodeUrl, config.AppId, ReturnUrl); return(strGetCodeUrl); }
public void CheckCanEnable() { OAuthWXConfigInfo config = ConfigService <OAuthWXConfigInfo> .GetConfig(WXWorkDirectory + "\\Config\\OAuthWXConfig.config"); OAuthRule rule = ConfigService <OAuthRule> .GetConfig(WXWorkDirectory + "\\Config\\OAuthUrl.config"); if (string.IsNullOrEmpty(config.AppId)) { throw new PluginException("未设置AppId!"); } if (string.IsNullOrEmpty(config.AppSecret)) { throw new PluginException("未设置AppSecret!"); } if (string.IsNullOrEmpty(rule.GetCodeUrl)) { throw new PluginException("未设置微信接口地址!"); } }
public static UserInfo GetUserInfo(string code, string appid, string appsecret) { UserInfo responseResult = null; OAuthRule config = ConfigService <OAuthRule> .GetConfig(string.Concat(WXLoginPlugin.WXWorkDirectory, "\\Config\\OAuthUrl.config")); if (string.IsNullOrEmpty(config.GetTokenUrl)) { throw new MissingFieldException("未设置微信接口地址:GetTokenUrl"); } if (string.IsNullOrEmpty(config.GetUserInfoUrl)) { throw new MissingFieldException("未设置微信接口地址:GetUserInfoUrl"); } string str = string.Format(config.GetTokenUrl, appid, appsecret, code); HttpHandler.ClientRequest clientRequest = new HttpHandler.ClientRequest(str) { HttpMethod = "get" }; ErrResult errResult = new ErrResult(); TokenResult tokenResult = HttpHandler.GetResponseResult <TokenResult, ErrResult>(clientRequest, errResult); if (errResult.errcode > 0) { throw new PluginException(string.Concat("微信登录接口GetToken出错: ", errResult.errmsg)); } if (string.IsNullOrEmpty(tokenResult.access_token)) { throw new PluginException("微信登录接口返回access_Token为空"); } str = string.Format(config.GetUserInfoUrl, tokenResult.access_token, tokenResult.openid); HttpHandler.ClientRequest clientRequest1 = new HttpHandler.ClientRequest(str) { HttpMethod = "get" }; responseResult = HttpHandler.GetResponseResult <UserInfo, ErrResult>(clientRequest1, errResult); if (errResult.errcode > 0) { throw new PluginException(string.Concat("微信登录接口GetUserInfo出错: ", errResult.errmsg)); } return(responseResult); }
public static UserInfo GetUserInfo(string code, string appid, string appsecret) { UserInfo userinfo = null; OAuthRule rule = ConfigService <OAuthRule> .GetConfig(WXLoginPlugin.WXWorkDirectory + "\\Config\\OAuthUrl.config"); if (string.IsNullOrEmpty(rule.GetTokenUrl)) { throw new System.MissingFieldException("未设置微信接口地址:GetTokenUrl"); } if (string.IsNullOrEmpty(rule.GetUserInfoUrl)) { throw new System.MissingFieldException("未设置微信接口地址:GetUserInfoUrl"); } string url = string.Format(rule.GetTokenUrl, appid, appsecret, code); HttpHandler.ClientRequest clientRequest = new HttpHandler.ClientRequest(url); clientRequest.HttpMethod = "get"; ErrResult err = new ErrResult(); TokenResult tokenResult = HttpHandler.GetResponseResult <TokenResult, ErrResult>(clientRequest, err); if (err.errcode > 0) { throw new Mall.Core.Plugins.PluginException("微信登录接口GetToken出错: " + err.errmsg); } if (string.IsNullOrEmpty(tokenResult.access_token)) { throw new Mall.Core.Plugins.PluginException("微信登录接口返回access_Token为空"); } url = string.Format(rule.GetUserInfoUrl, tokenResult.access_token, tokenResult.openid); HttpHandler.ClientRequest GetUserRequest = new HttpHandler.ClientRequest(url); GetUserRequest.HttpMethod = "get"; userinfo = HttpHandler.GetResponseResult <UserInfo, ErrResult>(GetUserRequest, err); if (err.errcode > 0) { throw new Mall.Core.Plugins.PluginException("微信登录接口GetUserInfo出错: " + err.errmsg); } //if (tokenResult.access_token) return(userinfo); }