在微信浏览器里获取Cookie,获取微信用户的openId

来源:互联网 发布:squid windows 编辑:程序博客网 时间:2024/05/13 01:58
通过下面截取微信发送过来的cookie值,获取微信用户openId,以便在微信软件中用户点击一个链接时,在脱离微信软件的平台,也可以确定到底是哪个用户在操作,以便后台记录。(其实就是确认微信用户身份)
<html><head><meta http-equiv="Content-Type" content="text/html; charset=utf-8"/><script type="text/javascript">function getCookie() { var url = location.search; //获取url中"?"符后的字串   var theRequest = new Object();   if (url.indexOf("?") != -1) {      var str = url.substr(1);      strs = str.split("%26");      theRequest[strs[0].split("=")[0]]=(strs[0].split("=")[1]);   }activityId=theRequest["activityId"];c_openId="openId";if (document.cookie.length > 0) {c_start = document.cookie.indexOf(c_openId + "=");if (c_start != -1) {c_start = c_start + c_openId.length + 1;c_end = document.cookie.indexOf(";", c_start);if (c_end == -1)c_end = document.cookie.length;openId=unescape(document.cookie.substring(c_start, c_end));//通过截取字符串,获取到openId。window.location.href = "joinActivity.jsf?openId="+openId+"&activityId="+activityId;//获取openId之//后再跳转到指定页面,把该openId放置到浏览器链接中。然后后台可以随时的从链接中确定是该用户在操作。}}window.location.href = "joinActivity.jsf?activityId="+activityId;}</script></head><body onload="getCookie()"></body></html>

0 0
原创粉丝点击