Skip to content

Commit

Permalink
first commit
Browse files Browse the repository at this point in the history
  • Loading branch information
benjhz committed Sep 28, 2015
1 parent 1c361bb commit b30d16c
Show file tree
Hide file tree
Showing 2 changed files with 116 additions and 0 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
# Logs
logs
*.log
.idea/

# Runtime data
pids
Expand Down
115 changes: 115 additions & 0 deletions WechatJs.js
Original file line number Diff line number Diff line change
@@ -0,0 +1,115 @@
/**
* Created by zhangjianhua on 15/9/28.
*/
/**
* Created by zhangjianhua on 15/9/16.
*/
function WechatJS(option) {
var self = this;
var opt = $.extend({
weixinJsUrl: 'http://res.wx.qq.com/open/js/jweixin-1.0.0.js',
wxConfig: {
debug: false,
appId: '',
timestamp: '',
nonceStr: '',
signature: '',
jsApiList: [
'checkJsApi',
'onMenuShareTimeline',
'onMenuShareAppMessage',
'onMenuShareQQ',
'onMenuShareWeibo',
'getNetworkType',
'hideOptionMenu',
'showOptionMenu',
'chooseWXPay'

]
},
shareImg: '',
shareLink: '',
getShareTitle: function () {
return "分享标题";
},
getShareDescription: function () {
return "分享描述";
},
shareCallback: function () {
},
initShare : true //初始化分享配置
}, option);

self.init = function () {
wx.config(opt.wxConfig);
wx.ready(function () {
if(opt.initShare){
initShareContent();
}
});

wx.error(function (res) {
//alert(JSON.stringify(res));
});
};


//加载文件
function loadWeixinJs(callback) {
addScript(opt.weixinJsUrl, callback);
}

function addScript(src, onload) {
var head = document.getElementsByTagName('head')[0];
var script = document.createElement('script');
script.type = 'text/javascript';
script.src = src;
script.onload = onload || null;
head.appendChild(script);
}

//初始化分享内容
function initShareContent() {
var title = opt.getShareTitle();
var desc = opt.getShareDescription();
self.setShareOptions(title, desc);
}

//设置分享参数
self.setShareOptions = function(title, description) {
var title = title || '范冰冰邀您玩游戏';
var link = opt.shareLink;
var imgUrl = opt.shareImg;
var shareCallback = opt.shareCallback;
wx.onMenuShareTimeline({
title: title, // 分享标题
link: link,
imgUrl: imgUrl, // 分享图标
success: shareCallback,
cancel: function () {
}
});
wx.onMenuShareAppMessage({
title: title, // 分享标题
desc: description, // 分享描述
link: link, // 分享链接
imgUrl: imgUrl, // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: shareCallback,
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
wx.onMenuShareWeibo({
title: title, // 分享标题
desc: description, // 分享描述
link: link, // 分享链接
imgUrl: imgUrl, // 分享图标
success: shareCallback,
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
}
}

0 comments on commit b30d16c

Please sign in to comment.