/// <summary> /// 获取h5签名 /// </summary> /// <param name="ticket"></param> /// <returns></returns> internal string Sign(string ticket, H5Sign config) { // 注意这里参数名必须全部小写,且必须有序 string input = $"jsapi_ticket={ ticket }&noncestr={ config.NonceStr }×tamp={ config.Timestamp }&url={config.url}"; SHA1 sHA1 = SHA1.Create(); byte[] buffer = sHA1.ComputeHash(Encoding.UTF8.GetBytes(input)); return(BitConverter.ToString(buffer).Replace("-", string.Empty).ToString().ToLower()); }
public ResultBase GetH5Signature(string code = "", string url = "https://activity.topcn.xin/index.html") { ActivityInfoService activityInfoService = new ActivityInfoService(); H5Sign resq = new H5Sign(); try { if (!_memoryCache.TryGetValue("Cache_H5Ticket", out string ticket)) { ticket = activityInfoService.GetH5Ticket(code); _memoryCache.Set("Cache_H5Ticket", ticket, DateTimeOffset.Now.AddHours(1.5)); } if (Request.Headers.TryGetValue("Referer", out StringValues value) && value.Count > 0) { resq.url = value[0]; } else { resq.url = url; } Console.WriteLine("SignRequestUrl:" + resq.url); resq.AppId = "wx3283d85d64449029"; resq.Signature = activityInfoService.Sign(ticket, resq); } catch (Exception ex) { return(new ResultBase { IsSuccess = false, Code = CodeConstant.ServerError, Message = ex.Message + ex.StackTrace }); } if (resq != null && !string.IsNullOrEmpty(resq.Signature)) { return(new ResultBase { IsSuccess = true, Code = CodeConstant.Success, Data = resq }); } else { return(new ResultBase { IsSuccess = false, Code = CodeConstant.DataNull }); } }