Ejemplo n.º 1
0
        public ApiResult GetJsApiConfig(string strUrl)
        {
            string      appId       = _accessToken.GetAppId();
            DateTime    dt          = DateTime.Now;
            string      nonceStr    = Guid.NewGuid().ToString();
            var         accessToken = _accessToken.GetToken();
            TicketModel signature   = _accessToken.GetJsApiTicket(dt);
            string      timestamp   = _accessToken.ConvertDateTimeInt(dt).ToString();
            string      url         = strUrl;

            String[] arr = new String[] { accessToken, timestamp, nonceStr, url };
            // 将token、timestamp、nonce三个参数进行字典序排序
            Array.Sort <String>(arr);

            StringBuilder content = new StringBuilder();

            for (int i = 0; i < arr.Length; i++)
            {
                content.Append(arr[i]);
            }

            var string1Builder = new StringBuilder();

            string1Builder.Append("jsapi_ticket=").Append(signature.ticket).Append("&")
            .Append("noncestr=").Append(nonceStr).Append("&")
            .Append("timestamp=").Append(timestamp).Append("&")
            .Append("url=").Append(url.IndexOf("#") >= 0 ? url.Substring(0, url.IndexOf("#")) : url);
            var string1 = string1Builder.ToString();
            //return Util.Sha1(string1);
            var tmpStr1 = FormsAuthentication.HashPasswordForStoringInConfigFile(string1, "SHA1");


            //String tmpStr = SHA1_Encrypt(content.ToString());
            //加密/校验流程:
            //1. 将token、timestamp、nonce三个参数进行字典序排序
            //string[] ArrTmp = { Token, timestamp, nonce };
            //Array.Sort(ArrTmp);//字典排序
            //                   //2.将三个参数字符串拼接成一个字符串进行sha1加密
            //string tmpStr = string.Join("", ArrTmp);
            //var tmpStr = FormsAuthentication.HashPasswordForStoringInConfigFile(content.ToString(), "SHA1");
            //tmpStr = tmpStr.ToLower();

            var result = new ApiResult();

            result.SetData(new
            {
                appId        = appId,
                timestamp    = timestamp,
                nonceStr     = nonceStr,
                jsapi_ticket = signature.ticket,
                url          = url,
                signature    = tmpStr1,
                signature1   = string1,
            });
            return(result);
        }