wechat.js 2.0 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071
  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. })();