public OAuthUserInfo GetUserInfo(NameValueCollection queryString) { OAuthUserInfo oAuthUser = new OAuthUserInfo(); string strCode = string.Empty; string strState = string.Empty; OAuthWXConfigInfo config = ConfigService <OAuthWXConfigInfo> .GetConfig(WXWorkDirectory + "\\Config\\OAuthWXConfig.config"); if (queryString["code"] != null && queryString["state"] != null) { strCode = queryString["code"]; strState = queryString["state"]; if (string.IsNullOrEmpty(config.AppSecret)) { throw new System.MissingFieldException("未设置AppSecret!"); } UserInfo userinfo = WeiXinApi.GetUserInfo(strCode, config.AppId, config.AppSecret); oAuthUser.OpenId = userinfo.openid; oAuthUser.NickName = userinfo.nickname; oAuthUser.UnionId = userinfo.unionid; oAuthUser.IsMale = userinfo.sex == 0 ? false : true; } return(oAuthUser); }
public FormData GetFormData() { OAuthWXConfigInfo config = ConfigService <OAuthWXConfigInfo> .GetConfig(WXWorkDirectory + "\\Config\\OAuthWXConfig.config"); return(new FormData() { Items = new Core.Plugins.FormData.FormItem[] { //AppId new Core.Plugins.FormData.FormItem() { DisplayName = "AppId", Name = "AppId", IsRequired = true, Type = Core.Plugins.FormData.FormItemType.text, Value = config.AppId }, //AppKey new Core.Plugins.FormData.FormItem() { DisplayName = "AppSecret", Name = "AppSecret", IsRequired = true, Type = Core.Plugins.FormData.FormItemType.text, Value = config.AppSecret } } }); }
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 void SetFormValues(IEnumerable <KeyValuePair <string, string> > values) { KeyValuePair <string, string> keyValuePair = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "AppId"); if (string.IsNullOrWhiteSpace(keyValuePair.Value)) { throw new PluginException("Appid不能为空"); } KeyValuePair <string, string> keyValuePair1 = values.FirstOrDefault((KeyValuePair <string, string> item) => item.Key == "AppSecret"); if (string.IsNullOrWhiteSpace(keyValuePair1.Value)) { throw new PluginException("AppSecret不能为空"); } OAuthWXConfigInfo oAuthWXConfigInfo = new OAuthWXConfigInfo() { AppId = keyValuePair.Value, AppSecret = keyValuePair1.Value }; ConfigService <OAuthWXConfigInfo> .SaveConfig(oAuthWXConfigInfo, string.Concat(WXLoginPlugin.WXWorkDirectory, "\\Config\\OAuthWXConfig.config")); }
public OAuthUserInfo GetUserInfo(NameValueCollection queryString) { OAuthUserInfo oAuthUserInfo = new OAuthUserInfo(); string empty = string.Empty; string item = string.Empty; OAuthWXConfigInfo config = ConfigService <OAuthWXConfigInfo> .GetConfig(string.Concat(WXLoginPlugin.WXWorkDirectory, "\\Config\\OAuthWXConfig.config")); if ((queryString["code"] == null ? false : queryString["state"] != null)) { empty = queryString["code"]; item = queryString["state"]; if (string.IsNullOrEmpty(config.AppSecret)) { throw new MissingFieldException("未设置AppSecret!"); } UserInfo userInfo = WeiXinApi.GetUserInfo(empty, config.AppId, config.AppSecret); oAuthUserInfo.OpenId = (string.IsNullOrWhiteSpace(userInfo.unionid) ? userInfo.openid : userInfo.unionid); oAuthUserInfo.NickName = userInfo.nickname; oAuthUserInfo.IsMale = new bool?((userInfo.sex == 0 ? false : true)); } return(oAuthUserInfo); }
public void SetFormValues(IEnumerable <KeyValuePair <string, string> > values) { KeyValuePair <string, string> appid = values.FirstOrDefault(item => item.Key == "AppId"); if (string.IsNullOrWhiteSpace(appid.Value)) { throw new PluginException("Appid不能为空"); } KeyValuePair <string, string> appsecret = values.FirstOrDefault(item => item.Key == "AppSecret"); if (string.IsNullOrWhiteSpace(appsecret.Value)) { throw new PluginException("AppSecret不能为空"); } OAuthWXConfigInfo config = new OAuthWXConfigInfo(); config.AppId = appid.Value; config.AppSecret = appsecret.Value; ConfigService <OAuthWXConfigInfo> .SaveConfig(config, WXWorkDirectory + "\\Config\\OAuthWXConfig.config"); //ConfigService<OAuthWXConfigInfo>.SaveConfig() }
public FormData GetFormData() { OAuthWXConfigInfo config = ConfigService <OAuthWXConfigInfo> .GetConfig(string.Concat(WXLoginPlugin.WXWorkDirectory, "\\Config\\OAuthWXConfig.config")); FormData formDatum = new FormData(); FormData.FormItem[] formItemArray = new FormData.FormItem[2]; FormData.FormItem formItem = new FormData.FormItem(); formItem.DisplayName = "AppId"; formItem.Name = "AppId"; formItem.IsRequired = true; formItem.Type = FormData.FormItemType.text; formItem.Value = config.AppId; formItemArray[0] = formItem; FormData.FormItem formItem1 = new FormData.FormItem(); formItem1.DisplayName = "AppSecret"; formItem1.Name = "AppSecret"; formItem1.IsRequired = true; formItem1.Type = FormData.FormItemType.text; formItem1.Value = config.AppSecret; formItemArray[1] = formItem1; formDatum.Items = formItemArray; return(formDatum); }