Authored by rqq

本来生活分享

  1 +/**
  2 + * 微信分享
  3 + * @author: xuqi<qi.xu@yoho.cn>
  4 + * @date: 2015/10/30
  5 + */
  6 +
  7 +var $ = require('jquery');
  8 +
  9 +module.exports = function() {
  10 + var _weChatInterface = 'http://www.yohoshow.com/api/wechat/getSignPackage';
  11 +
  12 + $.getJSON(_weChatInterface + '?pageurl=' +
  13 + encodeURIComponent(location.href.split('#')[0]) + '&callback=?', function(json) {
  14 + var _appId, _timestamp, _nonceStr, _signature;
  15 +
  16 + if (json !== undefined && json !== '') {
  17 + _appId = json.appId.toString();
  18 + _timestamp = json.timestamp;
  19 + _nonceStr = json.nonceStr.toString();
  20 + _signature = json.signature.toString();
  21 +
  22 + wx.config({
  23 + debug: false,
  24 + appId: _appId,
  25 + timestamp: _timestamp,
  26 + nonceStr: _nonceStr,
  27 + signature: _signature,
  28 + jsApiList: [
  29 + 'checkJsApi',
  30 + 'onMenuShareTimeline',
  31 + 'onMenuShareAppMessage',
  32 + 'onMenuShareQQ',
  33 + 'onMenuShareWeibo',
  34 + 'hideMenuItems',
  35 + 'showMenuItems',
  36 + 'hideAllNonBaseMenuItem',
  37 + 'showAllNonBaseMenuItem',
  38 + 'translateVoice',
  39 + 'startRecord',
  40 + 'stopRecord',
  41 + 'onRecordEnd',
  42 + 'playVoice',
  43 + 'pauseVoice',
  44 + 'stopVoice',
  45 + 'uploadVoice',
  46 + 'downloadVoice',
  47 + 'chooseImage',
  48 + 'previewImage',
  49 + 'uploadImage',
  50 + 'downloadImage',
  51 + 'getNetworkType',
  52 + 'openLocation',
  53 + 'getLocation',
  54 + 'hideOptionMenu',
  55 + 'showOptionMenu',
  56 + 'closeWindow',
  57 + 'scanQRCode',
  58 + 'chooseWXPay',
  59 + 'openProductSpecificView',
  60 + 'addCard',
  61 + 'chooseCard',
  62 + 'openCard'
  63 + ]
  64 + });
  65 + }
  66 + });
  67 +
  68 + wx.ready(function() {
  69 + var shareTitle = $('#title').val();
  70 + var shareImg = $('#img').val();
  71 + var shareDesc = $('#desc').val();
  72 + var shareLink = $('#link').val();
  73 + var shareData = {
  74 + title: shareTitle,
  75 + desc: shareDesc,
  76 + imgUrl: shareImg,
  77 + link: shareLink
  78 + };
  79 +
  80 + wx.onMenuShareAppMessage(shareData);
  81 + wx.onMenuShareTimeline(shareData);
  82 + wx.onMenuShareQQ(shareData);
  83 + wx.onMenuShareWeibo(shareData);
  84 + });
  85 +};