weixin.js 4.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131
  1. var lineLink = window.location.href;
  2. var desc = '点击进入:在线720°鉴赏精品文物';
  3. var projectName = 'DG';
  4. var getQueryVariable = function(variable){
  5. var query = window.location.search.substring(1);
  6. var vars = query.split("&");
  7. for (var i=0;i<vars.length;i++) {
  8. var pair = vars[i].split("=");
  9. if(pair[0] == variable){return pair[1];}
  10. }
  11. return(false);
  12. };
  13. let param = getQueryVariable('m');
  14. // let desc = param?;
  15. function jssdk() {
  16. $.ajax({
  17. url:'http://www.4dage.com/wechat/jssdk/share/',
  18. type: "post",
  19. data : {
  20. 'uri' : location.href.split('#')[0],
  21. 'name': '厦门四维时代微信公众号'
  22. },
  23. dataType:"jsonp",
  24. jsonpCallback:"success_jsonp",
  25. success:function(data,textStatus){
  26. wx.config({
  27. // debug : true,
  28. appId : data.appId,
  29. timestamp : data.timestamp,
  30. nonceStr : data.nonceStr,
  31. signature : data.signature,
  32. jsApiList : [ 'checkJsApi', 'onMenuShareTimeline',
  33. 'onMenuShareAppMessage', 'onMenuShareQQ',
  34. 'onMenuShareWeibo', 'hideMenuItems',
  35. 'showMenuItems', 'hideAllNonBaseMenuItem',
  36. 'showAllNonBaseMenuItem', 'translateVoice',
  37. 'startRecord', 'stopRecord', 'onRecordEnd',
  38. 'playVoice', 'pauseVoice', 'stopVoice',
  39. 'uploadVoice', 'downloadVoice', 'chooseImage',
  40. 'previewImage', 'uploadImage', 'downloadImage',
  41. 'getNetworkType', 'openLocation', 'getLocation',
  42. 'hideOptionMenu', 'showOptionMenu', 'closeWindow',
  43. 'scanQRCode', 'chooseWXPay',
  44. 'openProductSpecificView', 'addCard', 'chooseCard',
  45. 'openCard' ]
  46. });
  47. },
  48. error:function(XMLHttpRequest,textStatus,errorThrown){
  49. console.log("jsonp.error:"+textStatus);
  50. }
  51. });
  52. var success_jsonp = function(json){
  53. console.log(json);
  54. };
  55. }
  56. wx.ready(function(){
  57. // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行〿
  58. //对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中〿
  59. //分享到朋友圈
  60. wx.onMenuShareTimeline({
  61. title: document.querySelector("head title").innerHTML, // 分享标题
  62. link: lineLink, // 分享链接
  63. imgUrl: 'http://model3d.4dage.com/3D/2018/model/'+projectName+'/images/weixin/'+getQueryVariable("m")+'.jpg', // 分享图标
  64. desc: desc
  65. });
  66. //获取“分享给朋友”按钮点击状态及自定义分享内容接叿
  67. wx.onMenuShareAppMessage({
  68. title: '义乌博物馆', // 分享标题
  69. desc: param?modelData[param].CN_Name:'', // 分享描述
  70. link: lineLink + '?t=' + new Date().getTime(), // 分享链接
  71. // imgUrl: 'http://model3d.4dage.com/3D/2018/model/'+projectName+'/images/weixin/'+getQueryVariable("m")+'.jpg', // 分享图标
  72. imgUrl: 'https://model3d.4dage.com/3D/2018/model/sh/images/bg.jpg', // 分享图标
  73. type: '', // 分享类型,music、video或link,不填默认为link
  74. dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
  75. success: function () {
  76. },
  77. });
  78. });
  79. wx.onMenuShareWeibo({
  80. title: document.querySelector("head title").innerHTML, // 分享标题
  81. desc: desc, // 分享描述
  82. link: lineLink, // 分享链接
  83. imgUrl: 'http://model3d.4dage.com/3D/2018/model/'+projectName+'/images/weixin/'+getQueryVariable("m")+'.jpg', // 分享图标
  84. success: function () {
  85. // 用户确认分享后执行的回调函数
  86. },
  87. cancel: function () {
  88. // 用户取消分享后执行的回调函数
  89. }
  90. });
  91. wx.onMenuShareQZone({
  92. title: document.querySelector("head title").innerHTML, // 分享标题
  93. desc: desc, // 分享描述
  94. link: lineLink, // 分享链接
  95. imgUrl: 'http://model3d.4dage.com/3D/2018/model/'+projectName+'/images/weixin/'+getQueryVariable("m")+'.jpg', // 分享图标
  96. success: function () {
  97. // 用户确认分享后执行的回调函数
  98. },
  99. cancel: function () {
  100. // 用户取消分享后执行的回调函数
  101. }
  102. });
  103. wx.onMenuShareQQ({
  104. title: document.querySelector("head title").innerHTML, // 分享标题
  105. desc: desc, // 分享描述
  106. link: lineLink, // 分享链接
  107. imgUrl: 'http://model3d.4dage.com/3D/2018/model/'+projectName+'/images/weixin/'+getQueryVariable("m")+'.jpg', // 分享图标
  108. success: function () {
  109. // 用户确认分享后执行的回调函数
  110. },
  111. cancel: function () {
  112. // 用户取消分享后执行的回调函数
  113. }
  114. });
  115. wx.error(function(res){
  116. // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名〿
  117. });
  118. jssdk();