public void SaveLogin(LoginModule login) { string sql = string.Format(@"DELETE APP_LOGIN_CONFIG;INSERT INTO [APP_LOGIN_CONFIG] ( [CREATEDATE] ,[CREATEUSER] ,[WXLOGIN] ,[WXID] ,[WXAGENTID] ,[WXSECRET] ,[DDLOGIN] ,[DDID] ,[DDAGENTID] ,[DDSECRET] ,[OLOGIN], [DDCORPID],[WXLINKSQL],[DDLINKSQL]) VALUES ('{0}' ,'{1}' ,'{2}' ,'{3}' ,'{4}' ,'{5}','{6}','{7}','{8}','{9}','{10}','{11}','{12}','{13}')", DateTime.Now.ToString(), YZAuthHelper.LoginUserAccount, login.WxLogin, login.WxId, login.WxAgentId, login.WxSecret, login.DdLogin, login.DdId, login.DdAgentId, login.DdSecret, login.OLogin, login.DdCorpId, login.WxLinkSql, login.DdLinkSql); DBUtil_APP.ExecuteSqlWithGoUseTran(sql); }
public virtual JObject DingTalkLogin(HttpContext context) { YZRequest request = new YZRequest(context); string code = request.GetString("code"); string corpId = request.GetString("corpId"); string appSecret = request.GetString("appSecret"); string lang = request.GetString("lang", "zh-chs"); string accesstoken = DingTalkManager.Instance.GetAccessToken(corpId, appSecret); string uid = DingTalkManager.Instance.TryGetUserIdFromCode(accesstoken, code); string regularAccount = null; string linsql = ""; using (IYZAppAdminProvider applogin = IYZAppAdminProviderManager.DefaultProvider) { YZAppAdmin.LoginModule lm = applogin.LoadLogin(); linsql = lm.DdLinkSql; } if (!string.IsNullOrEmpty(linsql)) { string sql = string.Format(linsql, uid); uid = Convert.ToString(DBUtil_APP.GetSingle(sql)); } using (BPMConnection cn = new BPMConnection()) { cn.WebOpenAnonymous(); if (!User.IsAccountExist(cn, uid, ref regularAccount)) { throw new Exception(String.Format("当前钉钉登录用户{0},不是有效的BPM账号!", uid)); } YZAuthHelper.SetAuthCookie(regularAccount); } YZAuthHelper.SetLangSession(YZCultureInfoParse.Parse(lang, YZCultureInfoParse.DefauleCultureInfo).LCID); JObject rv = this.GenLoginResult(regularAccount, false); return(rv); }
protected void Page_Load(object sender, EventArgs e) { string code = this.Request.Params["code"]; string app = this.Request.Params["app"]; string linsql = ""; using (IYZAppAdminProvider applogin = IYZAppAdminProviderManager.DefaultProvider) { YZAppAdmin.LoginModule lm = applogin.LoadLogin(); if (lm.WxLogin != "1") { this.Response.Clear(); this.Response.Write("<script>alert('未开启微信登陆')</script>"); return; } wechat.corpId = lm.WxId; wechat.agentId = lm.WxAgentId; wechat.secret = lm.WxSecret; linsql = lm.WxLinkSql; } if (String.IsNullOrEmpty(app)) { app = "main"; } if (String.IsNullOrEmpty(code)) { YZUrlBuilder uri = new YZUrlBuilder("https://open.weixin.qq.com/connect/oauth2/authorize"); uri.QueryString["appid"] = wechat.corpId; uri.QueryString["response_type"] = "code"; uri.QueryString["redirect_uri"] = this.Request.Url.ToString(); uri.QueryString["scope"] = "SCOPE"; uri.QueryString["state"] = "STATE#wechat_redirect"; this.Response.Redirect(uri.ToString()); } else { try { JObject jApp = jApps[app] as JObject; string accesstoken = WeChatManager.Instance.GetAccessToken(wechat.corpId, wechat.secret); string userid = WeChatManager.Instance.TryGetUserIdFromCode(accesstoken, code); string ticket = WeChatManager.Instance.GetJSapiTicket(accesstoken); string timeStamp = WeChatManager.Instance.GetTimeStamp(); string nonceStr = YZSecurityHelper.SecurityKey; string url = this.Request.Url.ToString(); string signature = WeChatManager.Instance.GenSigurate(nonceStr, timeStamp, ticket, url); if (String.IsNullOrEmpty(userid)) { throw new Exception("非企业号用户!"); } if (!string.IsNullOrEmpty(linsql)) { string sql = string.Format(linsql, userid); userid = Convert.ToString(DBUtil_APP.GetSingle(sql)); } using (BPMConnection cn = new BPMConnection()) { cn.WebOpenAnonymous(); string regularAccount = null; if (!BPM.Client.User.IsAccountExist(cn, userid, ref regularAccount)) { throw new Exception(String.Format("当前企业号登录用户{0},不是有效的BPM账号!", userid)); } YZAuthHelper.SetAuthCookie(regularAccount); this.Title = (string)jApp["title"]; JObject jAppResult = new JObject(); jAppResult["app"] = app; jAppResult["agentId"] = wechat.agentId; jAppResult["secret"] = wechat.secret; jAppResult["title"] = jApp["title"]; jAppResult["corpId"] = corpId; jAppResult["timeStamp"] = timeStamp; jAppResult["nonceStr"] = nonceStr; jAppResult["signature"] = signature; jAppResult["jsApiList"] = jApp["jsApiList"]; jAppResult["xclass"] = jApp["xclass"]; JObject jConfig = jApp["config"] == null ? new JObject() : JObject.FromObject(jApp["config"]); jAppResult["config"] = jConfig; foreach (string key in this.Request.QueryString.Keys) { jConfig[key] = this.Request.QueryString[key]; } this._litApp.Text = jAppResult.ToString(Formatting.Indented, YZJsonHelper.Converters); } } catch (Exception exp) { if (exp.Message.Contains("query?e=40029")) { YZUrlBuilder uri = new YZUrlBuilder("https://open.weixin.qq.com/connect/oauth2/authorize"); uri.QueryString["appid"] = wechat.corpId; uri.QueryString["response_type"] = "code"; string url = this.Request.Url.ToString(); int code2 = url.IndexOf("code"); url = url.Substring(0, code2 - 1); uri.QueryString["redirect_uri"] = url; uri.QueryString["scope"] = "SCOPE"; uri.QueryString["state"] = "STATE#wechat_redirect"; this.Response.Redirect(uri.ToString()); } else { this.Response.Redirect("~/YZSoft/assist/AspxError/default.aspx?err=" + HttpUtility.UrlEncode(exp.Message)); } } } }
//http://blog.csdn.net/jeryjeryjery/article/details/53199992 //https://github.com/injekt/openapi-demo-java/blob/master/WebContent/javascripts/demo.js?spm=a219a.7629140.0.0.nWbroF&file=demo.js protected void Page_Load(object sender, EventArgs e) { try { string code = this.Request.Params["code"]; string app = this.Request.Params["app"]; using (IYZAppAdminProvider applogin = IYZAppAdminProviderManager.DefaultProvider) { YZAppAdmin.LoginModule lm = applogin.LoadLogin(); if (lm.DdLogin != "1") { this.Response.Clear(); this.Response.Write("<script>alert('未开启钉钉登陆')</script>"); return; } dingtalk.appkey = lm.DdId; dingtalk.secret = lm.DdSecret; dingtalk.agentId = lm.DdAgentId; dingtalk.corpId = lm.DdCorpId; } if (String.IsNullOrEmpty(app)) { app = "main"; } JObject jApp = jApps[app] as JObject; string corpId = dingtalk.corpId; string appSecret = dingtalk.secret; string accesstoken = DingTalkManager.Instance.GetAccessToken(appkey, appSecret); string ticket = DingTalkManager.Instance.GetJSapiTicket(accesstoken); string timeStamp = DingTalkManager.Instance.GetTimeStamp(); string nonceStr = YZSecurityHelper.SecurityKey; string url = this.Request.Url.ToString(); string signature = DingTalkManager.Instance.GenSigurate(nonceStr, timeStamp, ticket, url); this.Title = (string)jApp["title"]; JObject jAppResult = new JObject(); jAppResult["app"] = app; jAppResult["agentId"] = dingtalk.agentId; jAppResult["secret"] = dingtalk.secret; jAppResult["title"] = jApp["title"]; jAppResult["corpId"] = corpId; jAppResult["timeStamp"] = timeStamp; jAppResult["nonceStr"] = nonceStr; jAppResult["signature"] = signature; jAppResult["jsApiList"] = jApp["jsApiList"]; jAppResult["xclass"] = jApp["xclass"]; JObject jConfig = jApp["config"] == null ? new JObject() : JObject.FromObject(jApp["config"]); jAppResult["config"] = jConfig; foreach (string key in this.Request.QueryString.Keys) { jConfig[key] = this.Request.QueryString[key]; } this._litApp.Text = jAppResult.ToString(Formatting.Indented, YZJsonHelper.Converters); } catch (Exception exp) { this.Response.Redirect("~/YZSoft/assist/AspxError/default.aspx?err=" + HttpUtility.UrlEncode(exp.Message)); } }