Example #1
0
 public ApiCommonController()
 {
     _CorpId      = DDHelper.GetCorpId();
     _CorpSecret  = DDHelper.CorpSecret();
     _AgentId     = DDHelper.GetAgentId();
     _accessToken = DDHelper.GetToken( );
 }
Example #2
0
        //
        // GET: /DD/
        //public ActionResult GetUserInfo(string accessToken, string code, bool setCurrentUser = true)
        //{
        //    try
        //    {
        //        string userId = DingDingService.Instance.GetUserId(accessToken, code);
        //        string jsonString = DingDingService.Instance.GetUserDetailJson(accessToken, userId);
        //        UserDetailInfo userInfo = DingDingService.Instance.GetUserDetailFromJson(jsonString);
        //        if (setCurrentUser)
        //        {
        //            Session["AccessToken"] = accessToken;
        //            Session["CurrentUser"] = userInfo;
        //        }
        //        return Content(jsonString);
        //    }
        //    catch (Exception ex)
        //    {
        //        return Content(string.Format("{{'errcode': -1, 'errmsg':'{0}'}}", ex.Message));
        //    }
        //}


        // GET: /UserManager/
        public ActionResult Index()
        {
            string nonceStr = "HELLOWORK";//todo:随机

            ViewBag.NonceStr = nonceStr;
            string accessToken = DingDingService.GetAccessToken();

            ViewBag.AccessToken = accessToken;
            string ticket    = DingDingService.GetJsApiTicket(accessToken);
            long   timeStamp = DDHelper.GetTimeStamp();
            string url       = Request.Url.ToString();
            string signature = DingDingService.GetSign(ticket, nonceStr, timeStamp, url);

            ViewBag.JsApiTicket = ticket;
            ViewBag.Signature   = signature;
            ViewBag.NonceStr    = nonceStr;
            ViewBag.TimeStamp   = timeStamp;
            ViewBag.CorpId      = DDHelper.GetCorpId();
            ViewBag.CorpSecret  = DDHelper.CorpSecret();
            ViewBag.AgentId     = DDHelper.GetAgentId();
            return(View());
        }
Example #3
0
        ///获取审批实例列表
        public Response <bool> GetProcessIntanceList2(string pid, string start_time, string userid)
        {
            var result = new Response <bool>();

            string url = "https://eco.taobao.com/router/rest";

            string[] userlist = { userid };
            Dictionary <string, string> diclist = new Dictionary <string, string>();

            diclist.Add("method", "dingtalk.smartwork.bpms.processinstance.list");

            diclist.Add("session", _accessToken);
            diclist.Add("app_key", DDHelper.GetAgentId());
            diclist.Add("timestamp", DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"));
            diclist.Add("format", "json");
            diclist.Add("v", "2.0");
            diclist.Add("sign_method", "md5");
            diclist.Add("process_code", "pid");
            diclist.Add("userlist", userlist.ToJson());
            diclist.Add("start_time", start_time);
            diclist.Add("end_time", ((DateTime.Now.ToUniversalTime().Ticks - 621355968000000000) / 10000).ToString());
            //diclist.Add("access_token", _accessToken);

            string sign = DDHelper.SignTopRequest(diclist, DDHelper.CorpSecret(), "md5");

            diclist.Add("sign", sign);

            diclist = diclist.OrderBy(o => o.Key).ToDictionary(o => o.Key, p => p.Value.ToString());//对key进行升序
            //遍历元素
            //var data = new
            //{
            //    method = "dingtalk.smartwork.bpms.processinstance.list",
            //    app_key = DDHelper.GetAgentId(),
            //    timestamp = DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss"),
            //    format = "json",
            //    v = "2.0",
            //    sign_method = "md5",
            //    process_code = pid,
            //    start_time = start_time
            //    //end_time = DateTime.Now.Ticks,
            //    // userlist = userlist//080937632339701427
            //};
            string req   = "";
            int    count = 0;

            foreach (var item in diclist)
            {
                count++;
                if (count == diclist.Count)
                {
                    req += item.Key + "=" + item.Value;
                }
                else
                {
                    req += item.Key + "=" + item.Value + "&";
                }
            }

            try
            {
                string response = Infrastructure.Web.WebHelper.HttpWebRequestJson(url + "?" + req, diclist.ToJson());
                result.Code    = 200;
                result.Message = response;
            }
            catch (Exception ex)
            {
                result.Code    = 500;
                result.Message = ex.Message;
            }
            return(result);
        }