Ajax微信公众平台开发(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:
‘前些天的无声烘托着明天的繁荣,梨园狗市在兴衰中显表露2个行当的迈入故事。‘,

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() {}

});

Ajax,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‘,

 

微信接口调用

相关文章