global.js 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117
  1. //网关对应地址
  2. var api = "http://gateway.js-dctech.com/api/";
  3. // var api = "http://192.168.2.35:8080/api/";
  4. //批次号
  5. var batch = getUrlParam("batch");
  6. //列序号
  7. var columnSort = getUrlParam("columnSort");
  8. //二维码值
  9. var qrCode = getUrlParam("qrCode");
  10. //当前url
  11. var currentUrl = location.href.split('#')[0];
  12. //缓存中的accessToken
  13. var accessToken = localStorage.getItem("access_token") || "";
  14. //封装ajax请求,自动在请求头中加入access_token
  15. jQuery.extend({
  16. authAjax: function (options) {
  17. if (accessToken == "" && (typeof(options.data) == "undefined" || options.data.oauthCode == null)) {
  18. alert("accessToken失效,请重新扫码");
  19. return false;
  20. }
  21. var data = options.data || {};
  22. data.batch = batch;
  23. data.columnSort = columnSort;
  24. data.qrCode = qrCode;
  25. options.data = data;
  26. return $.ajax($.extend({
  27. headers: {"access_token":accessToken}
  28. },options));
  29. }
  30. });
  31. //获取url中的参数
  32. function getUrlParam(name) {
  33. var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)"); //构造一个含有目标参数的正则表达式对象
  34. var r = window.location.search.substr(1).match(reg); //匹配目标参数
  35. if(r != null){
  36. return decodeURIComponent(r[2]);//路径后面的参数形式为参数名=参数值,而第一个字符为参数名,第二个为=,第三个就为参数值
  37. }
  38. return null;//返回参数值
  39. }
  40. //获取js-sdk签名
  41. function createJsapiSignature(url) {
  42. $.authAjax({
  43. type : "GET",
  44. url : api+"marketing/weixin/createJsapiSignature",
  45. async: false,
  46. data: {url: url},
  47. dataType:"json",
  48. success : function(data) {
  49. wx.config({
  50. beta: true,// 必须这么写,否则wx.invoke调用形式的jsapi会有问题
  51. // debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  52. appId: data.appId, // 必填,企业微信的corpID
  53. timestamp: data.timestamp, // 必填,生成签名的时间戳
  54. nonceStr: data.nonceStr, // 必填,生成签名的随机串
  55. signature: data.signature,// 必填,签名,见附录1
  56. jsApiList: [
  57. 'checkJsApi',
  58. 'openLocation',// 使用微信内置地图查看地理位置接口
  59. 'getLocation' // 获取地理位置接口
  60. ]
  61. });
  62. }
  63. });
  64. }
  65. //获取用户位置
  66. function getLocation(successFun, cancelFun) {
  67. wx.getLocation({
  68. success : function(res) {
  69. var latitude = res.latitude; // 纬度,浮点数,范围为90 ~ -90
  70. var longitude = res.longitude; // 经度,浮点数,范围为180 ~ -180。
  71. var speed = res.speed; // 速度,以米/每秒计
  72. var accuracy = res.accuracy; // 位置精度
  73. successFun(latitude,longitude);
  74. },
  75. cancel : function (res) {
  76. if(typeof cancelFun != 'undefined' && cancelFun instanceof Function){
  77. cancelFun();
  78. }
  79. },
  80. fail : function(res) {
  81. $.hideLoading();
  82. alert("获取位置失败");
  83. }
  84. });
  85. }
  86. //回首页
  87. function hrefIndex() {
  88. $.authAjax({
  89. url: api+"marketing/weixin/redirectUrl",
  90. async: false,
  91. success: function (res) {
  92. location.href = res;
  93. }
  94. })
  95. // location.href = api+"marketing/weixin/redirectAuthUrl?batch="+batch+"&columnSort="+columnSort+"&qrCode="+qrCode;
  96. }
  97. //拼接url
  98. function spliceUrl(url) {
  99. return url + "batch="+batch+"&columnSort="+columnSort+"&qrCode="+qrCode;
  100. }