3,143
社区成员
发帖
与我相关
我的任务
分享
var app = {};
app.appId="";
app.jsApiTicket="";
app.sign = "";
app.nonceStr="";
app.timeStamp="";
app.func={};
var logoUrl = "http://ysj.weilaila.com:8080/demo/img/baby_logo.jpg";
//生成随机字符串
app.func.createRandomStr=function(num){
var s = "0123456789qwertyuiopasdfghjklzxcvbnmQWERTYUIOPASDFGHJKLZXCVBNM";
var r = [];
var x = s.split("");
for(var i = 0; i<num; i++){
var random = parseInt(Math.random()*62);
r.push(x[random]);
}
return r.join("");
};
app.func.getUrl = function(){
return location.href.split("#")[0];
}
//得到js api 接口凭证
app.func.getConfigInfo=function(){
$.ajax({
type:"POST",
url:"user/getjsapisign.jhtml",
data:{
url:app.func.getUrl(),
nonceStr:app.func.createRandomStr()
},
async:false,
success:function(data){
if(data.status=="ok"){
app.jsApiTicket = data.jsApiTicket;
app.appId=data.appId;
app.sign=data.sign;
app.nonceStr = data.nonceStr;
app.timeStamp = data.timeStamp;
app.func.wxconfig();
}
else
{
window.location.reload();
}
},
error:function(){
alert("网络出错,请检查你的网络");
window.location.reload();
}
});
};
/*//生成时间戳
app.func.createTimeStamp=function(){
return Date.parse(new Date())/1000;
};*/
/*//生成签名
app.func.createSign=function(obj){
var str="";
var param = ['jsapi_ticket','noncestr','timestamp','url'];
param.sort();
for(var i = 0; i<param.length;i++){
str+=param[i]+"="+obj[param[i]];
if(i!=param.length-1){
str+="&"
}
}
console.log(str);
return CryptoJS.SHA1(str).toString();
}*/
app.func.wxconfig = function(){
wx.config({
debug:false,
appId:app.appId,
timestamp:app.timeStamp,
nonceStr:app.nonceStr,
signature:app.sign,
jsApiList:[
'onMenuShareTimeline',
'onMenuShareAppMessage',
'hideOptionMenu',
'showOptionMenu',
'hideMenuItems',
'showMenuItems',
'closeWindow'
]
});
wx.ready(function(){
wx.checkJsApi({
jsApiList:['onMenuShareTimeline','onMenuShareAppMessage'],
success:function(res){
if(!res.checkResult.onMenuShareAppMessage||!res.checkResult.onMenuShareTimeline){
alert('你的微信客户端不支持JSSDK,请升级你的客户端');
}
}
});
//*********这里的这些值,可以写死。******************
wx.onMenuShareTimeline({
title:'长得好看的人都来参加花式裹孩纸大赛了,赢取IPHONE6S,不服来战!',//分享标题
link:'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxec524716a0216797&redirect_uri=http%3a%2f%2fysj.weilaila.com%3a8080%2fdemo%2findex.jhtml&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect',//分享链接
imgUrl:logoUrl,//
type:'link',//type是music或者video,link
success:function(){
//以下是给用户加积分的函数请求
addNum();
}
});
wx.onMenuShareAppMessage({
title:'长得好看的人都来参加花式裹孩纸大赛了,赢取IPHONE6S,不服来战!',
desc:'据说只要眼疾手快,你就可以赢得大奖,走向人生巅峰',//分享描述
link:'https://open.weixin.qq.com/connect/oauth2/authorize?appid=wxec524716a0216797&redirect_uri=http%3a%2f%2fysj.weilaila.com%3a8080%2fdemo%2findex.jhtml&response_type=code&scope=snsapi_userinfo&state=STATE#wechat_redirect',
imgUrl:logoUrl,
success:function(){
addNum();
}
});
function addNum(num){
var addscroe = 5;
$.ajax({
type:"POST",
data:{
score:addscroe,
type:1
},
url:"user/addscore.jhtml",
async:true,
success:function(data){
alert("分享成功!");
if(data.error)
window.location.href = "index/rank.jhtml?score=0";
else
window.location.href = "index/rank.jhtml?score="+addscroe;
},
error:function(){
alert('抱歉,网络出错,请重新分享');
}
});
}
});
}
app.func.getConfigInfo();
if(location.search)
location.href=location.origin+location.pathname;
如果你的连接上有其他的参数,需要对照参数名进行过滤