微信 分享朋友圈 发送好友 js代码

function loadBless(){
document.addEventListener(‘WeixinJSBridgeReady‘, function onBridgeReady() {
var redirectsingleurl = encodeMyStr("http://10.3.172.189:8080/OlaPushHtml/publish/wx/bless/homepage?from=singlemessage&isappinstalled=0");
var redirectTimelineurl= encodeMyStr("http://10.3.172.189:8080/OlaPushHtml/publish/wx/bless/homepage?from=timeline&isappinstalled=0");
var timelineLink ="https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7c5e6aef953f4268&redirect_uri="+redirectsingleurl+"&response_type=code&scope=snsapi_base&state=123#wechat_redirect";
var sendFriendLink = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=wx7c5e6aef953f4268&redirect_uri="+redirectTimelineurl+"&response_type=code&scope=snsapi_base&state=123#wechat_redirect";

window.shareData = {
"imgUrl": "http://api.olavoice.com/olaweb/activities/resource/activity-lottery-1.png",
"timeLineLink": redirectTimelineurl,
"sendFriendLink": redirectsingleurl,
"weiboLink": "http://10.3.172.189/olaweb/wx/bless/homepage",
"tTitle": "我在活动,你也一起来参加",
"tContent": "我在活动,你也一起来参加!",
"fTitle": "我在活动,你也一起来参加",
"fContent": "我在活动,你也一起来参加!",
"wContent": "我在活动,你也一起来参加!"
};
//发送给好友
WeixinJSBridge.on(‘menu:share:appmessage‘, function (argv) {

if( _flag == "sendgift"){
_timestamp = new Date().getTime();
var redirectsingleUrl2 = "http://10.3.172.189:8080/OlaPushHtml/publish/wx/bless/viewgift?user="+_openid+"&id="+_id+"&from=singlemessage&isappinstalled=0&timestamp="+_timestamp;
var redirecttimelineUrl2 = "http://10.3.172.189:8080/OlaPushHtml/publish/wx/bless/viewgift?user="+_openid+"&id="+_id+"&from=timeline&isappinstalled=0";
var content = _recvname+",给你发送了一个祝福,快来查看吧!";
sendFrinds(redirectsingleUrl2,redirecttimelineUrl2,content);
} else {
_id="";
_timestamp="";
_openid="";
var redirectsingleUrl2 = "http://10.3.172.189:8080/OlaPushHtml/publish/wx/bless/homepage?from=singlemessage&isappinstalled=0";
var redirecttimelineUrl2 = "http://10.3.172.189:8080/OlaPushHtml/publish/wx/bless/homepage?from=timeline&isappinstalled=0";
var content = "我在加了送祝福活动,你也一起来参加";
sendFrinds(redirectsingleUrl2,redirecttimelineUrl2,content);
}
WeixinJSBridge.invoke(‘sendAppMessage‘, {
"img_url": window.shareData.imgUrl,
"img_width": "640",
"img_height": "640",
"link": window.shareData.sendFriendLink,
"desc": window.shareData.fContent,
"title":window.shareData.fTitle
}, function (res) {
$.post("saveblessrecordinfo",{id:_id,openid:_openid,recvname:_recvname,timestamp:_timestamp},function(data){
shareActivity("appmessage");
_report(‘send_msg‘, res.err_msg);

},"json");
});
});
// 分享到朋友圈
WeixinJSBridge.on(‘menu:share:timeline‘, function (argv) {
shareActivity("sharefriend");
WeixinJSBridge.invoke(‘shareTimeline‘, {
"img_url": window.shareData.imgUrl,
"img_width": "640",
"img_height": "640",
"link": window.shareData.timeLineLink,
"desc": window.shareData.tContent,
"title": window.shareData.tTitle
}, function (res) {
_report(‘timeline‘, res.err_msg);
});
});

});
}
function shareActivity(message){
$.ajax({
cache : false,
type: "POST",
url : "activity",
data : {
sharemessage : message
},
dataType : "json",
error : function(data) {
running = false;
sAlert("亲,网络好像不给力哦!");
clearInterval(timer);
return;
},
timeout : 40000
});
};

function encodeMyStr(str) {
var strTmp=encodeURI(str);
strTmp=strTmp.replace(/\+/g,"%2B");
return strTmp;
}

微信 分享朋友圈 发送好友 js代码

上一篇:CSS文件的三种引入方式


下一篇:12.标准标签库(JSTL)