123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209 |
- (function(win) {
- //确认签名已拿到
- if (typeof signPackage != "undefined") {
- wx.config({
- debug: false,
- appId: signPackage.appId,
- timestamp: signPackage.timestamp + "",
- nonceStr: signPackage.nonceStr,
- signature: signPackage.signature,
- jsApiList: [ 'checkJsApi',
- 'onMenuShareTimeline',
- 'onMenuShareAppMessage'
- ]
- });
- wxShare();
- }
- })(window);
- /*
- * 微信JS-SDK 分享类接口
- * @gameOver
- * @param {String} title 分享标题
- * @param {String} desc 分享描述
- * @param {String} link 分享链接
- * @param {String} imgUrl 分享图标
- * @allparam
- */
- function wxShare() {
- wx.ready(function() {
- //分享给朋友
- wx.onMenuShareAppMessage({
- trigger: function(res) {
- this.title = window.shareData.tTitle;
- this.desc = window.shareData.tContent;
- this.link = window.shareData.timeLineLink;
- this.imgUrl = window.shareData.imgUrl;
- },
- success: function() {
- statistics("onShareFriends");
- },
- });
- //分享到朋友圈
- wx.onMenuShareTimeline({
- trigger: function(res) {
- this.title = window.shareData.tTitle;
- this.link = window.shareData.timeLineLink;
- this.imgUrl = window.shareData.imgUrl;
- },
- success: function() {
- statistics("onShareCircle");
- }
- });
- });
- }
- // 判断哪种统计 cnzz , DCAgent
- function statistics(shareName) {
- if (typeof _cnz != "undefined") {
- //cnzz
- if (shareName == "onShareCircle") {
- _czc.push(['_trackEvent', '分享朋友圈']);
- } else {
- _czc.push(['_trackEvent', '分享好友']);
- }
- } else if (typeof DCAgent != "undefined") {
- //dataeye
- if (shareName == "onShareCircle") {
- DCAgent.onEvent("share_timeline", 1, {
- userID: 'null'
- });
- } else {
- DCAgent.onEvent("share_app", 1, {
- userID: 'null'
- });
- }
- }
- }
- //判断是否为微信环境
- function isWeiXin() {
- var ua = window.navigator.userAgent.toLowerCase();
- if (ua.match(/MicroMessenger/i) == 'micromessenger') {
- return true;
- } else {
- return false;
- }
- }
- (function(global) {
- var _wx = {
- /*
- * 配置微信信息
- @param
- config == {
- appId: signPackage.appId,
- timestamp: signPackage.timestamp,
- nonceStr: signPackage.nonceStr,
- signature: signPackage.signature,
- jsApiList: [
- 'onMenuShareTimeline',
- 'onMenuShareAppMessage'
- ]
- }
- */
- init: function(config) {
- wx && wx.config(config);
- return this;
- },
- /*
- * 初始化微信分享数据
- * @param info == { title :'title', desc : 'desc', link : 'link', imgUrl:'imgurl'}
- *
- */
- config: function(info) {
- var me = this;
- this.info = info || {};
- document.title = info.title;
- wx.ready(function() {
- //分享给朋友
- wx.onMenuShareAppMessage({
- trigger: function(res) {
- this.title = info.title;
- this.desc = infot.desc;
- this.link = info.link;
- this.imgUrl = info.imgUrl;
- },
- success: function() {
- me.statistics("onShareFriends");
- },
- });
- //分享到朋友圈
- wx.onMenuShareTimeline({
- trigger: function(res) {
- this.title = info.title;
- this.link = info.link;
- this.imgUrl = info.imgUrl;
- },
- success: function() {
- me.statistics("onShareCircle");
- }
- });
- });
- return this;
- },
- /*
- * 修改分享内容
- * @changeInfo
- * @param key,value 单条内容
- * @param object 内容对象
- * @usage CKShare.wx.changeInfo("url",'http://266.com')
- * @allparam
- */
- changeInfo: function() {
- var arg = arguments,
- len = arg.length;
- if (len > 1) {
- this.info[arg[0]] = arg[1];
- } else if ("[object Object]" == Object.prototype.toString.call(arg[0])) {
- var obj = arg[0],
- i;
- for (i in obj) {
- this.info[i] = obj[i];
- }
- }
- document.title = this.info.title;
- return this;
- },
- /*
- * 统计
- */
- statistics: function(type) {
- if (typeof _cnz != "undefined") {
- //cnzz
- if (type == "onShareCircle") {
- _czc.push(['_trackEvent', 'share_timeline']);
- } else {
- _czc.push(['_trackEvent', 'share_app']);
- }
- } else if (typeof DCAgent != "undefined") {
- //dataeye
- if (type == "onShareCircle") {
- DCAgent.onEvent("share_timeline", 1, {
- userID: 'CK_guest'
- });
- } else {
- DCAgent.onEvent("share_app", 1, {
- userID: 'CK_guest'
- });
- }
- }
- }
- }
- global.CKShare = {
- wx: _wx
- }
- })(window);
|