分享到朋友圈和分享给朋友

##前端

<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8"> 
	<title>微信js分享接口</title>
	<meta name="viewport" content="width=device-width, initial-scale=1.0, maximum-scale=1.0, user-scalable=no">
	<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>
</head>
<body>

<script>


	wx.config({
    debug: true, // 开启调试模式,调用的所有api的返回值会在客户端alert出来,若要查看传入的参数,可以在pc端打开,参数信息会通过log打出,仅在pc端时才会打印。
    appId: '{$appid}', // 必填,公众号的唯一标识
    timestamp: '{$timestamp}', // 必填,生成签名的时间戳
    nonceStr: '{$noncestr}', // 必填,生成签名的随机串
    signature: '{$signature}',// 必填,签名,见附录1
    jsApiList: [
    'onMenuShareTimeline',
    'onMenuShareAppMessage'
      ] // 必填,需要使用的JS接口列表,所有JS接口列表见附录2
     });

	wx.ready(function(){

    // config信息验证后会执行ready方法,所有接口调用都必须在config接口获得结果之后,config是一个客户端的异步操作,所以如果需要在页面加载时就调用相关接口,则须把相关接口放在ready函数中调用来确保正确执行。对于用户触发时才调用的接口,则可以直接调用,不需要放在ready函数中。

		    wx.onMenuShareTimeline({
		    title: 'king', // 分享标题
		    link: 'http://www.jianshu.com', // 分享链接
		    imgUrl: 'http://upload-images.jianshu.io/upload_images/3404372-1cd93b056c75628c.jpg?imageMogr2/auto-orient/strip%7CimageView2/1/w/300/h/300', // 分享图标
		    success: function () { 
		        // 用户确认分享后执行的回调函数
		    },
		    cancel: function () { 
		        // 用户取消分享后执行的回调函数
		      }
		      });

		    wx.onMenuShareAppMessage({
			    title: 'king', // 分享标题
			    desc: '测试的东西', // 分享描述
			    link: 'http://www.jianshu.com', // 分享链接
			    imgUrl: 'http://upload-images.jianshu.io/upload_images/3404372-1cd93b056c75628c.jpg?imageMogr2/auto-orient/strip%7CimageView2/1/w/300/h/300', // 分享图标
			    type: '', // 分享类型,music、video或link,不填默认为link
			    dataUrl: '', // 如果type是music或video,则要提供数据链接,默认为空
			    success: function () { 
			        // 用户确认分享后执行的回调函数
			    },
			    cancel: function () { 
			        // 用户取消分享后执行的回调函数
			    }
			});

});

wx.error(function(res){

    // config信息验证失败会执行error函数,如签名过期导致验证失败,具体错误信息可以打开config的debug模式查看,也可以在返回的res参数中查看,对于SPA可以在这里更新签名。

});


</script>


</body>
</html>

服务器:

<?php
namespace Home\Controller;
use Think\Controller;
class IndexController extends BaseController {
	
    public function index(){
    	$jsapi=$this->getSignPackage();
          
         $this->appid=$jsapi['appId'];
         $this->noncestr=$jsapi['nonceStr'];
         $this->url=$jsapi['url'];
         $this->signature=$jsapi['signature'];
         $this->timestamp=$jsapi['timestamp'];
    $this->display();
    	
        
    }
}
```

转载于:https://my.oschina.net/2016jyh/blog/785750

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值