微信公众平台开发(30)微信接口调用

 

原文: http://www.cnblogs.com/imaker/p/5491433.html

微信接口调用代码:
 
var weixinUrl = ‘http://www.yc.cn/weixin/share.do‘,
appId = ‘wxf4466017457b72fa‘,
url = encodeURIComponent(pet.url.split("#")[0]),
wxData = {
title: document.querySelector(‘title‘).innerText,
desc: ‘今日的萧索映衬着昨日的繁荣,梨园狗市在兴衰中显露出一个行业的发展故事。‘,
img: "http://res.ycw.com/app/magazine/zazhizhoukan/imgs8/fenxiang.jpg",
link: pet.url
};
/*微信分享*/
function wechatShare() {
if (pet.isWeixin()) {
var wxShare = function() {
$.ajax({
dataType: "jsonp",
url: weixinUrl + "?url=" + url + "&jsonCallback=?",
success: function(data) {
pet.loadFile("http://res.wx.qq.com/open/js/jweixin-1.0.0.js", function() {
var shareData = eval(data);
//配置信息
wx.config({
debug: false,
appId: appId,
timestamp: shareData.timestamp,
nonceStr: shareData.nonceStr,
signature: shareData.signature,
jsApiList: [
‘onMenuShareTimeline‘,
‘onMenuShareAppMessage‘,
‘onMenuShareQQ‘,
‘onMenuShareWeibo‘,
‘onMenuShareQZone‘
]
});
 
//分享到...
wx.ready(function() {
wx.onMenuShareTimeline({
title: wxData.title,
link: wxData.link,
imgUrl: wxData.img,
success: function() {},
cancel: function() {}
});
wx.onMenuShareQZone({
title: wxData.title,
desc: wxData.desc,
link: wxData.link,
imgUrl: wxData.img,
success: function() {
// 用户确认分享后执行的回调函数
},
cancel: function() {
// 用户取消分享后执行的回调函数
}
});
wx.onMenuShareAppMessage({
title: wxData.title,
desc: wxData.desc,
link: wxData.link,
imgUrl: wxData.img,
type: ‘‘,
dataUrl: ‘‘,
success: function() {},
cancel: function() {}
});
wx.onMenuShareQQ({
title: wxData.title,
desc: wxData.desc,
link: wxData.link,
imgUrl: wxData.img,
success: function() {},
cancel: function() {}
});
wx.onMenuShareWeibo({
title: wxData.title,
desc: wxData.desc,
link: wxData.link,
imgUrl: wxData.img,
success: function() {},
cancel: function() {}
});
});
 
})
},
error: function(xhr, type) {
console.log(‘Ajax error!‘)
}
});
};
wxShare();
}
}
wechatShare();
var topicShare = function() {
location.href = "youchong://sns/shareNew?title=" + encodeURIComponent(wxData.title) + "&content=" + encodeURIComponent(wxData.desc) + "&icon=" + encodeURIComponent(wxData.img) + "&url=" + encodeURIComponent(pet.url);
};
 
 
正式服:weixinUrl = ‘http://www.yc.cn/weixin/share.do‘,
appId = ‘wxf4466017457b72fa‘,
 
测试服:weixinUrl = ‘http://activity.ycnuli.com/weixin/share.do‘,
appId = ‘wx58e3e94f8313e300‘,
 

微信接口调用

posted @ 2017-01-14 08:04  贝创工作室  阅读(830)  评论(0编辑  收藏  举报