微信文章分享代码(PHP版)

1、首先下载SDK包:

下载路径:https://pan.baidu.com/s/10LTgdf6dIsyD8aSb6lawlw

提取码:nq3h

2、登录微信公众平台:

设置JS接口安全域名:

3、以Thinkphp3.2.3 为例,将包放入Verdor 文件夹中,并将插件取名为:jssdk

4、控制器:

 public function read(){
   	
   	    Vendor ('jssdk.jssdk');
		$jssdk = new \JSSDK ('你的APPID','你的APPserver');
		$signPackage = $jssdk->GetsignPackage ();
		
   	   // 获取文章主键 ID
   	   $Int_id = I('id',0,'intval');
   	   if($Int_id === 0){
   	   	   $this->error('ID 错误');
   	   }
   	   $ArticleModel = D('NewsArticle');
   	    // 文章点击数自增一
   	   $ArticleModel->SetInc(['id'=>$Int_id]);
   	   $data = $ArticleModel->getOne(['id'=>$Int_id]);
   	   $this->assign('data',$data);
   	   $this->assign ( 'signPackage', $signPackage );
   	   $this->display('article');
   	   
   }

5、前端页面

<?php
	
$arr = array(
 'appId' => $signPackage["appId"], 
 'nonceStr' => $signPackage["nonceStr"],
 'timestamp' => $signPackage["timestamp"],
 'signature' => $signPackage["signature"]);
?>
<script src="http://res.wx.qq.com/open/js/jweixin-1.0.0.js"></script>  
<script>  
var url=window.location.href;
var img = "{$data['thumb']}";
wx.config({  
debug:false,
appId: "{$arr['appId']}",
timestamp: "{$arr['timestamp']}",
nonceStr: "{$arr['nonceStr']}",
signature: "{$arr['signature']}", 
url:url,
jsApiList: [  
       "onMenuShareTimeline",     //分享给好友  
       "onMenuShareAppMessage",   //分享到朋友圈  
       "onMenuShareQQ",           //分享到QQ  
       "onMenuShareWeibo",        //分享到微博
]
});  
  
  wx.ready(function (){  
  var shareData = {  
  title: "{$data['post_title']}",  
  desc: "{$data['post_excerpt']}",  
  link: url,  
  imgUrl: img,
  };
  wx.onMenuShareAppMessage(shareData);  
  wx.onMenuShareTimeline(shareData);  
  wx.onMenuShareQQ(shareData);  
  wx.onMenuShareWeibo(shareData); 
    });  

</script>  

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值