public string InstallNotify() { string authCode = Request["auth_code"]; int storeId = WebHelper.GetQueryInt("storeid", 0); //获取ticket var ticket = SuiteTicketManager.GetSuiteTicket(2); //获取套餐凭证 var suiteToken = BossHelper.Get_Suite_Token(ticket.SuiteTicket); //获取永久授权码以及授权信息 var pCode = WorkWeiXinSDK.Get_Permanent_Code(authCode, suiteToken); var agent_info = pCode.auth_info.Agent[0]; var auth_corp = pCode.auth_corp_info; var model = new PermanentCodeInfo() { StoreId = storeId, permanent_code = pCode.permanent_code, //永久授权码 access_token = pCode.access_token, //企业的access_token last_expires = DateTime.Now, //access_token 的获取时间 agentid = agent_info.agentid, app_name = agent_info.name, corpid = auth_corp.corpid, corp_full_name = auth_corp.corp_full_name, AddTime = DateTime.Now }; PermanentCodeManager.Add(model); Redirect(WorkContext.MallConfig.SiteUrl); return(string.Empty); }
/// <summary> /// 安装企业微信的应用 /// </summary> public void Install() { int storeId = WebHelper.GetQueryInt("storeid", 0); if (storeId < 1) { Response.Write("授权失败:请选择店铺<script>setTimeout(function () { window.location.href = 'http://weadmin.711688.net.cn/storeadmin' }, 2000)</script>"); return; } //获取ticket var ticket = SuiteTicketManager.GetSuiteTicket(2); //获取套餐凭证 var suiteToken = BossHelper.Get_Suite_Token(ticket.SuiteTicket); //获取预授权码 var authCode = WorkWeiXinSDK.Get_Pre_Auth_Code(suiteToken); //设置授权配置 WorkWeiXinSDK.set_session_info(suiteToken, authCode, 1); //用户标识 string state = ""; //返回安装路径 string url = BossHelper.GetInstallUrl(authCode, state, storeId.ToString()); Response.Redirect(url); }
public void InstallNotifyByUser() { string authCode = Request["auth_code"]; int storeId = WebHelper.GetQueryInt("storeid", 0); //获取ticket var ticket = SuiteTicketManager.GetSuiteTicket(1); //获取套餐凭证 Suite_Token suiteToken = UserHelper.Get_Suite_Token(ticket.SuiteTicket); //获取永久授权码以及授权信息 PermanentCode pCode = WorkWeiXinSDK.Get_Permanent_Code(authCode, suiteToken); Agent_Info agent_info = pCode.auth_info.Agent[0]; Auth_Corp_Info auth_corp = pCode.auth_corp_info; var model = new PermanentCodeInfo() { StoreId = storeId, permanent_code = pCode.permanent_code, //永久授权码 access_token = pCode.access_token, //企业的access_token last_expires = DateTime.Now, //access_token 的获取时间 agentid = agent_info.agentid, app_name = agent_info.name, corpid = auth_corp.corpid, corp_full_name = auth_corp.corp_full_name, AddTime = DateTime.Now }; PermanentCodeManager.Add(model); }
public void OauthCallback(string code = "") { //第二步:根据code获取token失败 //获取ticket var ticket = SuiteTicketManager.GetSuiteTicket(1); //获取套餐凭证 Suite_Token suiteToken = BossHelper.Get_Suite_Token(ticket.SuiteTicket); var json = WorkWeiXinSDK.GetOauthUser(suiteToken.suite_access_token, code); if (json == null || json.errcode != 0) { //错误页面 Response.Redirect(string.Format("/admin_wjk/pages/error.html?msg=登录授权失败,{0}", json.errmsg)); } if (string.IsNullOrEmpty(json.UserId)) { //找不到用户 Response.Redirect("/admin_wjk/pages/error.html?msg=找不到用户"); } var perCode = PermanentCodeManager.GetByCorpid(json.CorpId); if (perCode == null) { //找不到授权企业 Response.Redirect("/admin_wjk/pages/error.html?msg=找不到授权企业"); } var staff = StaffManager.GetByWxUserId(perCode.StoreId, json.UserId); if (staff == null) { //找不到成员 Response.Redirect("/admin_wjk/pages/error.html?msg=找不到公司成员"); } if (staff.AiState != 1) { Response.Redirect("/admin_wjk/pages/error.html?msg=未开通AI雷达"); } WebHelper.SetCookie("wjk_staff", "storeid", staff.StoreId.ToString(), 90); WebHelper.SetCookie("wjk_staff", "staffid", staff.Id.ToString(), 90); WebHelper.SetCookie("wjk_staff", "uid", staff.Uid.ToString(), 90); WebHelper.SetCookie("wjk_staff", "aistate", staff.AiState.ToString(), 90); WebHelper.SetCookie("wjk_staff", "bossstate", staff.BossState.ToString(), 90); Response.Redirect("/admin_wjk/pages/bossRadarIndex.html?rand=" + new Random().Next(100000, 999999)); }