var url =location.href.split('#')[0];
var imgurl = 'http://www.audio160.com/image/logo_share.jpg';
var title = document.title;
var desc = '感谢使用中投传媒旗下垂直门户分享应用';
var meta = document.getElementsByTagName('meta');
for(i in meta){
if(typeof meta[i].name!="undefined"&&meta[i].name.toLowerCase()=="description"&&meta[i].content!==''){
desc = meta[i].content;
}
}
if(typeof sharetitle!="undefined"){title = sharetitle;}
if(typeof sharedesc!="undefined"){desc = sharedesc;}
if(typeof shareimgurl!="undefined"){imgurl = shareimgurl;}
var string1='jsapi_ticket=sM4AOVdWfPE4DxkXGEs8VIZgPgfOes48znCHA-b_1nx5VfAEVLzocluVjb0Zb71HxgJgIr6MJcqpP-CBJumYuQ&noncestr=avchinaW×tamp=1738290901&url='+url;
var tsignature=SHA1(string1);
//alert(SHA1(tsignature));
//根据AppID和AppSecret获得access token 有效期7200秒,开发者必须在自己的服务全局缓存access_token
//https://api.weixin.qq.com/cgi-bin/token?grant_type=client_credential&appid=wx1d8b4635cb902ce1&secret=cabf001a0640975fa4e62210206e6d68
//返回 正确"access_token":"ACCESS_TOKEN", 错误:errcode
//https://api.weixin.qq.com/cgi-bin/ticket/getticket?access_token=11_IGhLESRdACms3yiDqUSpRzBhKSyTUimOoXxqmS9M2qmnYwPnU0aIxh1t1fPvbHwOl9z_H62m9c0rMFPCChfdQF9QkhMMqrplv4WRkprmA20EK24N-Dly-EU92uFeHD6pyhuT97oZAm5FPtk5TEUdAEAMXN&type=jsapi
//获得jsapi_ticket之后,就可以生成JS-SDK权限验证的签名了
//signature=sha1(string1)
//string1为 jsapi_ticket=HoagFKDcsGMVCIY2vOjf9gCMMVTewlVQx5AbOcM27XCj-2cbeLlcy2STFSbksN7ytf3zqjQKbqPW3J9WDAMR0w&noncestr=avchinaW×tamp=1414587457&url=http://ke.ty360.com/ke/2018/2018_128.htm
wx.config({
debug: false, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
appId: 'wx871bf665df1a86cd', // 必填,公众号的唯一标识
timestamp: '1738290901', // 必填,生成签名的时间戳
nonceStr: 'avchinaW', // 必填,生成签名的随机串
signature: tsignature,// 必填,签名,见附录1
jsApiList: ["onMenuShareTimeline", "onMenuShareAppMessage", "onMenuShareQQ"] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
})
wx.ready(function(){
wx.onMenuShareTimeline({
title: title, // 分享标题
desc: desc, // 分享描述
link: url, // 分享链接
imgUrl: imgurl, // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
})
wx.onMenuShareAppMessage({
title: title, // 分享标题
desc: desc, // 分享描述
link: url, // 分享链接
imgUrl: imgurl, // 分享图标
type: '', // 分享类型,music、video或link,不填默认为link
dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
success: function () {
// 用户确认分享后执行的回调函数
//alert('ok')
},
cancel: function () {
// 用户取消分享后执行的回调函数
//alert('cancel')
}
})
wx.onMenuShareQQ({
title: title, // 分享标题
desc: desc, // 分享描述
link: url, // 分享链接
imgUrl: imgurl, // 分享图标
success: function () {
// 用户确认分享后执行的回调函数
},
cancel: function () {
// 用户取消分享后执行的回调函数
}
});
})
// SHA1 //////////////////////////////////
function add(x, y) {
return((x & 0x7FFFFFFF) + (y & 0x7FFFFFFF)) ^ (x & 0x80000000) ^ (y & 0x80000000);
}
function SHA1hex(num) {
var sHEXChars = "0123456789abcdef";
var str = "";
for(var j = 7; j >= 0; j--)
str += sHEXChars.charAt((num >> (j * 4)) & 0x0F);
return str;
}
function AlignSHA1(sIn) {
var nblk = ((sIn.length + 8) >> 6) + 1,
blks = new Array(nblk * 16);
for(var i = 0; i < nblk * 16; i++) blks[i] = 0;
for(i = 0; i < sIn.length; i++)
blks[i >> 2] |= sIn.charCodeAt(i) << (24 - (i & 3) * 8);
blks[i >> 2] |= 0x80 << (24 - (i & 3) * 8);
blks[nblk * 16 - 1] = sIn.length * 8;
return blks;
}
function rol(num, cnt) {
return(num << cnt) | (num >>> (32 - cnt));
}
function ft(t, b, c, d) {
if(t < 20) return(b & c) | ((~b) & d);
if(t < 40) return b ^ c ^ d;
if(t < 60) return(b & c) | (b & d) | (c & d);
return b ^ c ^ d;
}
function kt(t) {
return(t < 20) ? 1518500249 : (t < 40) ? 1859775393 :
(t < 60) ? -1894007588 : -899497514;
}
function SHA1(sIn) {
var x = AlignSHA1(sIn);
var w = new Array(80);
var a = 1732584193;
var b = -271733879;
var c = -1732584194;
var d = 271733878;
var e = -1009589776;
for(var i = 0; i < x.length; i += 16) {
var olda = a;
var oldb = b;
var oldc = c;
var oldd = d;
var olde = e;
for(var j = 0; j < 80; j++) {
if(j < 16) w[j] = x[i + j];
else w[j] = rol(w[j - 3] ^ w[j - 8] ^ w[j - 14] ^ w[j - 16], 1);
t = add(add(rol(a, 5), ft(j, b, c, d)), add(add(e, w[j]), kt(j)));
e = d;
d = c;
c = rol(b, 30);
b = a;
a = t;
}
a = add(a, olda);
b = add(b, oldb);
c = add(c, oldc);
d = add(d, oldd);
e = add(e, olde);
}
SHA1Value = SHA1hex(a) + SHA1hex(b) + SHA1hex(c) + SHA1hex(d) + SHA1hex(e);
return SHA1Value.toUpperCase();
}
function SHA2(sIn) {
return SHA1(sIn).toLowerCase();
}
//sha1 end