public static Dictionary<string,string> jsstr(string url) { //noncestr string noncestr=jssdk.GenerateRandom(16); //timestamp TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); string timestamp = Convert.ToInt64(ts.TotalSeconds).ToString(); //jsapi_ticket 尝试本地读取 //{"ticket":"~~~","expires_in":1432785380} //^^json格式 int i=0; string path=System.Web.HttpContext.Current.Server.MapPath("~/App_Data/jsapi_ticket.txt"); read_jspai: string json=txtdata.txtread(path); string jsapi_ticket=jssdk.rejson(json,"ticket"); string expires_in=jssdk.rejson(json,"expires_in"); //jsapi_ticket 是否超时 if(int.Parse(expires_in)<int.Parse(timestamp)) { //只会调一次接口,避免重复 if(i==0) { //获取最新 jsapi_ticket_get --AppID--AppSecret string info=jssdk.jsapi_ticket_get("!!!!","@@@@"); if(info=="ok") { i=1; goto read_jspai; } } } string signaturestr = "jsapi_ticket=" + jsapi_ticket + "&noncestr=" + noncestr + "×tamp=" + timestamp + "&url=" + url; signaturestr=jssdk.SHA1(signaturestr); Dictionary<string, string> mydic = new Dictionary<string, string>(); mydic.Add("appId","wx5b7c682cca621df2"); mydic.Add("timestamp",timestamp); mydic.Add("nonceStr",noncestr); mydic.Add("signature", signaturestr); return mydic; }
时间: 2024-10-12 15:16:22