wechat.js 3.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114
  1. (function(){
  2. var init = {
  3. url:window.location.href.split('#')[0],
  4. share: {
  5. title: '',
  6. desc: '',
  7. imgUrl: './img/share_img.jpg?v=v72',
  8. link:window.location.href.split('#')[0]
  9. }
  10. };
  11. /*
  12. $.ajax({
  13. url:"",
  14. type:"post",
  15. dataType:"json",
  16. data:{
  17. url:encodeURIComponent(init.url),
  18. t: new Date().getTime()
  19. },
  20. success:function(result){
  21. console.log(result);
  22. if(!result){
  23. return false;
  24. }
  25. wx.config({
  26. debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
  27. appId: result.appId, // 必填,公众号的唯一标识
  28. timestamp: result.timestamp, // 必填,生成签名的时间戳
  29. nonceStr: result.nonceStr, // 必填,生成签名的随机串
  30. signature: result.signature,// 必填,签名,见附录1
  31. jsApiList: ['onMenuShareTimeline','onMenuShareAppMessage','closeWindow','checkJsApi','translateVoice']
  32. })
  33. }
  34. });
  35. //绑定微信分享事件
  36. try{
  37. wx.ready(function(){
  38. //设置分享后的回调函数
  39. var callback={
  40. success:function (msg){
  41. msg=JSON.stringify(msg).toLowerCase();
  42. if(msg.indexOf('timeline')>-1){
  43. //分享到朋友圈
  44. }else if(msg.indexOf('message')>-1){
  45. //分享到给朋友
  46. }
  47. }
  48. };
  49. wx.onMenuShareTimeline($.extend({},init.share,callback));
  50. wx.onMenuShareAppMessage($.extend({},init.share,callback));
  51. });
  52. }catch(e){
  53. var msg="错误:微信js-sdk未引用或者错误!";
  54. try{
  55. console.log(msg);
  56. }catch(e){
  57. alert(msg);
  58. }
  59. return;
  60. }
  61. */
  62. })();
  63. function posterShare(href){
  64. //海报页面
  65. $.post("./user/getWxConfigParam?url=" + href, {}, function(resp) {
  66. if (resp.code == 'error') {
  67. console.log(resp.code);
  68. }else{
  69. wx.config({
  70. debug: false,
  71. appId: 'wx749c84daac654e1e',
  72. timestamp: resp.data.timestamp,
  73. nonceStr: resp.data.noncestr,
  74. signature: resp.data.sign,
  75. jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'onMenuShareQZone', 'showOptionMenu', 'hideAllNonBaseMenuItem', 'showAllNonBaseMenuItem']
  76. });
  77. wx.ready(function(){
  78. const share = {
  79. title: "我为你精心准备的美味,快享用吧!",
  80. desc: "",
  81. imgUrl: "http://wx.ttkuaiban.com/minigame/images/share_picture.png",
  82. link: href,
  83. success: function() {
  84. $.post("./prize/luckDrawAddShare", {uid: id}, function(resp) {
  85. if (resp.code == 'error') {
  86. console.log(resp.code);
  87. }else{
  88. window.location.href = "http://wx.ttkuaiban.com/minigame/lottery.html";
  89. }
  90. });
  91. },
  92. cancel: function() {}
  93. };
  94. wx.onMenuShareAppMessage(share);
  95. wx.onMenuShareTimeline(share);
  96. wx.onMenuShareQQ(share);
  97. wx.onMenuShareQZone(share);
  98. wx.onMenuShareWeibo(share);
  99. });
  100. wx.error(function(res){
  101. console.log(res);
  102. });
  103. };
  104. });
  105. }