/// <summary>
        /// 验证微信签名
        /// </summary>
        private static bool CheckSignature(string token, string signature, string timestamp, string nonce)
        {
            string[] arrTmp = { token, timestamp, nonce };

            Array.Sort(arrTmp);
            string tmpStr = string.Join("", arrTmp);

            tmpStr = SecurityCommon.Sha1(tmpStr);
            tmpStr = tmpStr.ToLower();
            if (tmpStr == signature)
            {
                return(true);
            }

            return(false);
        }
Esempio n. 2
0
        /// <summary>
        ///
        /// </summary>
        /// <param name="tickCacheKey"></param>
        /// <param name="tokenCacheKey"></param>
        /// <param name="url"></param>
        /// <returns></returns>
        public JsSdkConfig GetConfig(string tickCacheKey, string tokenCacheKey, string url)
        {
            string ticket = GetJsApiTicket(tickCacheKey, tokenCacheKey);

            string nonceStr = Guid.NewGuid().ToString().Replace("-", "");

            long timestamp = DateTime.Now.ToUnixTimestamp(TimestampType.Second);

            JsSdkConfig config = new JsSdkConfig()
            {
                AppId     = _config.AppId,
                TimeStamp = timestamp,
                NonceStr  = nonceStr
            };

            string valueTeam = "jsapi_ticket=" + ticket + "&noncestr=" + nonceStr + "&timestamp=" + timestamp +
                               "&url=" + url;

            config.Signature = SecurityCommon.Sha1(valueTeam).ToLower();

            return(config);
        }
Esempio n. 3
0
 /// <summary>
 /// Sha1
 /// </summary>
 /// <param name="bytes"></param>
 /// <param name="isUpper">是否转大写</param>
 /// <returns></returns>
 public static string Sha1(this byte[] bytes, bool isUpper = true)
 {
     return(SecurityCommon.Sha1(bytes, isUpper));
 }
Esempio n. 4
0
 /// <summary>
 /// Sha1
 /// </summary>
 /// <param name="stream"></param>
 /// <param name="isUpper">是否转大写</param>
 /// <returns></returns>
 public static string Sha1(this Stream stream, bool isUpper = true)
 {
     return(SecurityCommon.Sha1(stream, isUpper));
 }
Esempio n. 5
0
 /// <summary>
 /// Sha1
 /// </summary>
 /// <param name="str"></param>
 /// <param name="isUpper">是否转大写</param>
 /// <returns></returns>
 public static string Sha1(this string str, bool isUpper = true)
 {
     return(SecurityCommon.Sha1(str, isUpper));
 }