Beispiel #1
0
    private void GetConfig()
    {
        appId  = Config.EAgentID;
        corpId = Config.ECorpId;
        string corpSecret = Config.ECorpSecret;

        nonceStr  = Helper.randNonce();
        timestamp = Helper.timeStamp();
        string url = Request.Url.ToString();

        //这里重新实现
        string accessToken = EnterpriseBusiness.GetToken(corpId, corpSecret).access_token;
        string jsApiTicket = EnterpriseBusiness.GetTickets(accessToken);


        Helper.WriteLog("nonceStr:" + nonceStr);
        Helper.WriteLog("timestamp:" + timestamp);
        Helper.WriteLog("url:" + url);
        Helper.WriteLog("accessToken:" + accessToken);
        Helper.WriteLog("jsApiTicket:" + jsApiTicket);



        string string1 = "jsapi_ticket={0}&noncestr={1}&timestamp={2}&url={3}";

        string1 = string.Format(string1, jsApiTicket, nonceStr, timestamp, url);
        Helper.WriteLog("signature not sha1:" + string1);

        string signature = FormsAuthentication.HashPasswordForStoringInConfigFile(string1, "SHA1").ToLower();

        Helper.WriteLog("signature sha1:" + signature);
    }
    protected void Page_Load(object sender, EventArgs e)
    {
        string code = Request["code"];

        //根据CropId与cropSecret去换取AccessToken
        //这里的AccessToken的主要含义是企业令牌,它的意思是说依靠这个令牌可以去拿取与企业相关的数据,
        //根据官方文档介绍这里的有效期是7200秒,
        var tokenModel   = EnterpriseBusiness.GetToken(Config.ECorpId, Config.ECorpSecret);
        var access_token = tokenModel.access_token;

        /*
         * 这里拿到企业令牌后,可以将其保存到数据库中,同时设定它的过期时间为当前时间+7200秒,
         * 每次使有令牌时判断当前时间是否已经超过了有效期,如果超过了有效期,请重新获取新的令牌
         * 为了安全access_token在实际的开发过程当中不建议放到客户端,这个令牌一般禁止用户接触到,一般可放在服务器端的session里
         */
        Helper.WriteLog("access_token:" + access_token);


        //---------------利用access_token和code去换取当前用户
        var userModel = EnterpriseBusiness.GetCurrentUser(access_token, code);

        Helper.WriteLog("userId:" + userModel.userid);


        //拿到access_token之后。可以参照钉钉开发文档中的-服务端开发文档进行其它api的测试。关于服务端的回调接口,将在isv的开发中提到具体的用法。
        //这里只写一个接口测试。
        string url      = "https://oapi.dingtalk.com/department/create?access_token=" + access_token;
        string param    = "{\"access_token\":\"" + access_token + "\",\"name\":\"新增部门测试\",\"parentid\":\"1\",\"order\":\"3\",\"createDeptGroup\":\"false\"}";
        string callback = HttpHelper.Post(url, param);

        Helper.WriteLog("创建部门:" + callback);
    }
Beispiel #3
0
        /// <summary>
        /// 获取accesstoken
        /// </summary>
        /// <returns></returns>
        private string GetaccessToken()
        {
            appId  = DingConfig.EAgentID;
            corpId = DingConfig.ECorpId;
            string corpSecret = DingConfig.ECorpSecret;

            nonceStr  = Tools.randNonce();
            timestamp = Tools.timeStamp();
            string url = Request.Url.ToString();

            //这里重新实现
            string accessToken = EnterpriseBusiness.GetToken(corpId, corpSecret).access_token;

            return(accessToken);
            //CreateUser(accessToken, userModel);
        }