protected string GetTimeStamp_Str=""; protected string nonceStr_Str = ""; protected string signature_Str = ""; protected void Page_Load(object sender, EventArgs e) { GetTimeStamp_Str = GetTimeStamp(); //nonceStr_Str = new Guid().ToString("N"); var GetTakenStr = HttpHelper.HttpGetConnectToServer("https://api.weixin.qq.com/cgi-bin/token", "grant_type=client_credential&appid=wx6596bfb9388cc63c&secret=eb0c0d643d4e7bd3a43b61fd1031a2f2");//get Taken_Model taken_Model=JsonHelper.DeserializeObject(GetTakenStr); var jsapi_ticket_Str = HttpHelper.HttpGetConnectToServer("https://api.weixin.qq.com/cgi-bin/ticket/getticket", "access_token=" + taken_Model.access_token + "&type=jsapi");//get Jsapi_Ticket jsapi_ticket = JsonHelper.DeserializeObject (jsapi_ticket_Str); TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); var tstem = GetTimeStamp_Str;// Convert.ToInt64(ts.TotalSeconds).ToString(); var noncestr = "tianpeng"; //var jsapi_ticket = "sM4AOVdWfPE4DxkXGEs8VF-YEiVh31f4b2Z4rz5E1kuduFEPIz0RgvSnRKebdULuK-yWvsNB_21vVh3IhyR1yg"; var jmdata = "jsapi_ticket={0}&noncestr={1}×tamp={2}&url={3}"; jmdata = string.Format(jmdata, jsapi_ticket.ticket, noncestr, tstem, "http://hstwx.wisdom-gps.com:52539/SignUp/SignUp.aspx"); signature_Str = System.Web.Security.FormsAuthentication.HashPasswordForStoringInConfigFile(jmdata, "sha1"); nonceStr_Str = noncestr; } protected void btn_Login_Click(object sender, EventArgs e) { } public static string GetTimeStamp() { TimeSpan ts = DateTime.UtcNow - new DateTime(1970, 1, 1, 0, 0, 0, 0); return Convert.ToInt64(ts.TotalSeconds).ToString(); } } public class Taken_Model { public string access_token { get; set; } public int expires_in { get; set; } } public class Jsapi_Ticket { public int errcode { get; set; } public string errmsg { get; set; } public string ticket { get; set; } public int expires_in { get; set; } } 前端的写法
前端的写法
如果
signature不合法的话 可以在测试地址中比对http://mp.weixin.qq.com/debug/cgi-bin/sandbox?t=jsapisign 如果url不合法的话 在js安全域名里面处理 JS接口安全域名 hstwx.wisdom-gps.com:52539 成功~~~~~(前端还要加个引用) 测试地址:http://mp.weixin.qq.com/debug/cgi-bin/sandboxinfo?action=showinfo&t=sandbox/index