上代码:
<script>
var pagetUrl = window.location.href;
$(function () {
//--微信JS配置
if (wx != null && wx != undefined) {
if (pagetUrl.indexOf("#") > 0) {
pagetUrl = str.substring(0, pagetUrl.indexOf("#"));
}
$.ajax({
url: "wx.aspx",
type: "post",
data: {},
dataType: "json",
success: function (data) {
var ticket = data.ticket;
var timestamp = new Date().getTime();
var noncestr = timestamp.toString().substring(4);
var url = location.href;
var imgUrl = "http://www.house8.net/ziyundongqu/images/heading.png";
var sgin = getSign(ticket, url, timestamp, noncestr);
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: 'wxbf2cee2f63e13903', // 必填,公众号的唯一标识
timestamp: timestamp, // 必填,生成签名的时间戳
nonceStr: noncestr, // 必填,生成签名的随机串
signature: sgin,// 必填,签名,见附录1
jsApiList: ['onMenuShareTimeline', 'onMenuShareAppMessage']
// 必填,需要使用的JS接口列表,所有JS接口列表见附录2
});
wx.ready(function () {
wx.onMenuShareTimeline({
title: "紫云东区",
link: url,
imgUrl: imgUrl,
success: function () {
//alert("分享成功");
},
fail: function (res) {
alert("分享失败");
}
});
wx.onMenuShareAppMessage({
title: "紫云东区",
desc: "紫云东区二期",
link: url,
imgUrl: imgUrl,
success: function () {
alert("分享成功");
},
fail: function (res) {
alert("分享失败");
}
});
wx.error(function(res) {
alert(res.errMsg);
});
});
},
complete: function (XMLHttpRequest, textStatus) {
if (textStatus == 'timeout') {
var xmlhttp = window.XMLHttpRequest ? new window.XMLHttpRequest() : new ActiveXObject("Microsoft.XMLHttp");
xmlhttp.abort();
$(".box").html("网络超时!");
}
$("#inp").val("点击获取数据");
},
error: function (XMLHttpRequest, textStatus) {
console.log(XMLHttpRequest); //XMLHttpRequest.responseText XMLHttpRequest.status XMLHttpRequest.readyState
console.log(textStatus);
$(".box").html("服务器错误!");
}
});
}
});
</script>
相似问题