/// <summary> /// 根据传递进来的终端ID和token,调用Sha-1签名并返回 /// </summary> /// <param name="lomoPrinter"></param> /// <returns></returns> private static PermaisuriCMS.Model.LomoPrinter DoSignature(PermaisuriCMS.Model.LomoPrinter lomoPrinter) { var rd = new Random(); var nonce = rd.Next(100, 10000); lomoPrinter.nonce = nonce; var timestamp = CMSUtilityTools.DateTime2Unix(DateTime.Now); lomoPrinter.timestamp = timestamp; var str1 = lomoPrinter.terminal_id.ToString() + lomoPrinter.terminal_token + lomoPrinter.nonce.ToString() + lomoPrinter.timestamp.ToString(); //建立SHA1对象 using (SHA1 sha1 = new SHA1CryptoServiceProvider()) { var enc = new ASCIIEncoding(); var dataToHash = enc.GetBytes(str1); //Hash运算 var dataHashed = sha1.ComputeHash(dataToHash); //将运算结果转换成string var signature = BitConverter.ToString(dataHashed).ToLower().Replace("-", ""); lomoPrinter.signature = signature; // Releases all resources used by the System.Security.Cryptography.HashAlgorithm. sha1.Clear(); } return(lomoPrinter); }
public ActionResult GetTuoZongFans() { const string tzFansUrl = TuoZongFansUrl; try { var httpBase = new HttpBase(); var listFnas = new List <TuoZongFans> { new TuoZongFans { openid = "oX52ujpOaC5DKfhVjGxSDuIjY3fU", lasttime = CMSUtilityTools.DateTime2Unix(new DateTime(2014, 10, 30)) } }; var tzParams = new JavaScriptSerializer().Serialize(new TuoZongFansParams { merchant_id = "9929", fans = listFnas.ToArray() }); //var str1 = httpBase.GetResponseText(tzFansUrl, "POST", tzParams); var postData = "&merchant_id=9929"; var i = 0; foreach (var tzFan in listFnas) { postData += "&fans[" + i + "][lasttime]=" + tzFan.lasttime; postData += "&fans[" + i + "][openid]=" + tzFan.openid; i++; } //var str1 = HttpHelp.Post(tzFansUrl, "&merchant_id=9929&fans[0][lasttime]=1415698101&fans[0][openid]=of3jzt8hXEhOlO-MgoiPMg0wU1AM&fans[1][lasttime]=1415698101&fans[1][openid]=of3jzt1yKVNYtcUTVNHBffddY7h4"); var str1 = HttpHelp.Post(tzFansUrl, postData); return(Json(new { postData, result = str1 })); } catch (Exception ex) { return(Json(new { result = ex.Message })); } }