码迷,mamicode.com
首页 > 微信 > 详细

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

时间:2014-11-04 18:50:20      阅读:513      评论:0      收藏:0      [点我收藏+]

标签:des   http   io   ar   os   sp   on   cti   代码   

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代码

标签:des   http   io   ar   os   sp   on   cti   代码   

原文地址:http://www.cnblogs.com/Wen-yu-jing/p/4074032.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!