common2.js 4.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123
  1. function signCallback(data){
  2. wx.config({
  3. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  4. appId: 'wx1da54372a98911ec', // 必填,公众号的唯一标识
  5. timestamp: data.timestamp, // 必填,生成签名的时间戳
  6. nonceStr: data.nonceStr, // 必填,生成签名的随机串
  7. signature: data.signature,// 必填,签名,见附录1
  8. jsApiList: ["onMenuShareTimeline","onMenuShareAppMessage","onMenuShareQQ","onMenuShareWeibo"] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
  9. });
  10. wx.ready(function(){
  11. window.shareData = window.shareData || {
  12. title: document.title, // 分享标题
  13. link: window.location.href, // 分享链接
  14. imgUrl: '', // 分享图标
  15. desc : ""
  16. };
  17. WeixinJSBridge.on('menu:share:appmessage', function (argv) {
  18. WeixinJSBridge.invoke('sendAppMessage', {
  19. "img_url": window.shareData.imgUrl,
  20. "link": window.shareData.link,
  21. "desc": window.shareData.desc,
  22. "title": window.shareData.title
  23. }, function (res) {
  24. //window.shareData.callback();
  25. })
  26. });
  27. WeixinJSBridge.on('menu:share:timeline', function (argv) {
  28. WeixinJSBridge.invoke('shareTimeline', {
  29. "img_url": window.shareData.imgUrl,
  30. "link": window.shareData.link,
  31. "desc": window.shareData.desc,
  32. "title": window.shareData.desc
  33. }, function (res) {
  34. //window.shareData.callback();
  35. });
  36. });
  37. WeixinJSBridge.on('menu:share:weibo', function (argv) {
  38. WeixinJSBridge.invoke('shareWeibo', {
  39. "content": window.shareData.desc,
  40. "url": window.shareData.link
  41. }, function (res) {
  42. //window.shareData.callback();
  43. });
  44. });
  45. WeixinJSBridge.on('menu:share:qq', function (argv) {
  46. WeixinJSBridge.invoke('shareQQ', {
  47. "img_url": window.shareData.imgUrl,
  48. "link": window.shareData.link,
  49. "desc": window.shareData.desc,
  50. "title": window.shareData.title
  51. }, function (res) {
  52. //window.shareData.callback();
  53. });
  54. });
  55. /*
  56. wx.onMenuShareTimeline({
  57. title: window.shareData.desc, // 分享标题
  58. link: window.shareData.link, // 分享链接
  59. imgUrl: window.shareData.imgUrl, // 分享图标
  60. success: function () {
  61. // 用户确认分享后执行的回调函数
  62. },
  63. cancel: function () {
  64. // 用户取消分享后执行的回调函数
  65. }
  66. });
  67. wx.onMenuShareAppMessage({
  68. title: window.shareData.title, // 分享标题
  69. desc: window.shareData.desc, // 分享描述
  70. link: window.shareData.link, // 分享链接
  71. imgUrl: window.shareData.imgUrl, // 分享图标
  72. type: 'link', // 分享类型,music、video或link,不填默认为link
  73. dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
  74. success: function () {
  75. // 用户确认分享后执行的回调函数
  76. },
  77. cancel: function () {
  78. // 用户取消分享后执行的回调函数
  79. }
  80. });
  81. wx.onMenuShareQQ({
  82. title: window.shareData.title, // 分享标题
  83. desc: window.shareData.desc, // 分享描述
  84. link: window.shareData.link, // 分享链接
  85. imgUrl: window.shareData.imgUrl, // 分享图标
  86. success: function () {
  87. // 用户确认分享后执行的回调函数
  88. },
  89. cancel: function () {
  90. // 用户取消分享后执行的回调函数
  91. }
  92. });
  93. wx.onMenuShareWeibo({
  94. title: window.shareData.title, // 分享标题
  95. desc: window.shareData.desc, // 分享描述
  96. link: window.shareData.link, // 分享链接
  97. imgUrl: window.shareData.imgUrl, // 分享图标
  98. success: function () {
  99. // 用户确认分享后执行的回调函数
  100. },
  101. cancel: function () {
  102. // 用户取消分享后执行的回调函数
  103. }
  104. });
  105. */
  106. });
  107. }
  108. ;(function(){
  109. var _scri = document.createElement("script");
  110. var _loca = window.location.href;
  111. _scri.src="http://ts.html5youxi.com/weixin/signature/" + encodeURIComponent(encodeURIComponent(_loca));
  112. document.getElementsByTagName("head")[0].appendChild(_scri);
  113. })();