deng-jie
使用微信的方法需要先引入微信的sdk
<script src="https://res.wx.qq.com/open/js/jweixin-1.4.0.js"></script>
//判断是否是微信内部环境 
     var ua = navigator.userAgent.toLowerCase();
     var isWeixin = ua.indexOf(\'micromessenger\')!=-1;
     if(isWeixin && opinionParam.title != \'\'){
        //微信分享方法
	wxShare();
     }        

  

//微信的二次分享
    function wxShare(){
    	//需要注意url参数的有效值为#前面那一段
    	var param = {
    		"url":location.href.split(\'#\')[0],
    	};   	
	var pageURL = \'http://soft.thinkive.com/h5/huaanzx/tgwd/index.html#!/personalStore/opinionDetail.html?opinion_id=93\';
    	//先向后台发送请求,获取appId、签名、时间戳、随机串
    	mobileService.getWxKey(param,function(data){
    		if(data && data.error_no==0&&data.results.length>0){
    			var results = data.results[0];
    			//注入权限验证配置
    			wx.config({
    				debug:false,//开始调试模式,调用的所有的api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。移动端会通过弹窗来提示相关信息.如果分享信息配置不正确的话,可以开了看对应报错信息
    				appId:results.appid,//公众号的唯一标识
    				timestamp:results.timestamp,//生成签名的时间戳
    				nonceStr:results.nonceStr,//生成签名的随机串
    				signature:results.signature,//签名
    				jsApiList:[//需要使用的js接口列表,分享默认这几个,如果有其他的功能比如图片上传之类的,需要添加对应的api进来
    					\'checkJsApi\',
    					\'updateAppMessageShareData\',//分享给好友
    					\'updateTimelineShareData\',//分享到朋友圈
    					\'onMenuShareWeibo\',//分享到微博
    					\'onMenuShareQZone\',//分享到QQ空间
					\'onMenuShareQQ\',//分享到QQ
					\'onMenuShareAppMessage\', //分享给好友
					\'onMenuShareTimeline\'//分享给朋友圈
    				]
    			});
    			window.share_config = {
    				"share":{
    					"imgUrl":"http://zmall.hazq.com:8295/m/tgwd/images/huiying.png",
    					"desc":opinionParam.employeename+"的观点",//摘要,分享到朋友圈的话不显示摘要。
    					"title":opinionParam.title,//分享卡片的标题
    					"link":pageURL,//分享出去后的链接,这里可以将链接设置成另外一个页面,必须在同一域名下面
    					"success":function(){//分享成功之后的回调
    						console.log("分享成功")
    					},
    					\'cancel\':function(){//用户取消分享后执行
    						 
    					}
    				}
    			};
    			//通过ready接口处理成功验证
    			wx.ready(function(){
					if(wx.onMenuShareAppMessage){ 	
						wx.onMenuShareAppMessage(share_config.share);
						wx.onMenuShareTimeline(share_config.share);                  
					}else{
						wx.updateAppMessageShareData(share_config.share);
						wx.updateTimelineShareData(share_config.share);
					}
					wx.onMenuShareWeibo(share_config.share);
					wx.onMenuShareQZone(share_config.share);
					wx.onMenuShareQQ(share_config.share);
    			});
    		}
    	});
    }

  

分类:

技术点:

相关文章:

  • 2022-12-23
  • 2021-12-28
  • 2021-12-15
  • 2022-12-23
  • 2022-02-07
猜你喜欢
  • 2021-12-18
  • 2021-08-05
  • 2021-08-11
  • 2022-01-22
  • 2022-12-23
  • 2021-10-01
  • 2021-10-16
相关资源
相似解决方案