自定义微信发送给好友,分享到朋友圈的缩略图

dd_action("wp_head","wpjam_weixin_robot_share_head",99);
function wpjam_weixin_robot_share_head(){
	if(is_singular() && is_weixin()){
	global $post;
?>
<script type="text/javascript">
var dataForWeixin={
	appId:	"",
	img:	"<?php echo get_post_weixin_thumb($post,array(120,120)); ?>", // get_post_weixin_thumb 为微信机器人高级版中的函数
	url:	"<?php the_permalink($post->ID);?>",
	title:	"<?php echo $post->post_title; ?>",
	desc:	"<?php echo get_post_excerpt($post); ?>",
	fakeid:	"",
};
(function(){
	var onBridgeReady=function(){
		// 发送给好友;
		WeixinJSBridge.on('menu:share:appmessage', function(argv){
			WeixinJSBridge.invoke('sendAppMessage',{
				"appid":		dataForWeixin.appId,
				"img_url":		dataForWeixin.img,
				"img_width":	"120",
				"img_height":	"120",
				"link":				dataForWeixin.url,
				"desc":				dataForWeixin.desc,
				"title":			dataForWeixin.title
			}, function(res){<?php do_action('weixin_share','SendAppMessage');?>});
		});
		// 分享到朋友圈;
		WeixinJSBridge.on('menu:share:timeline', function(argv){
			WeixinJSBridge.invoke('shareTimeline',{
			"img_url":dataForWeixin.img,
			"img_width":"120",
			"img_height":"120",
			"link":dataForWeixin.url,
			"desc":dataForWeixin.desc,
			"title":dataForWeixin.title
			}, function(res){<?php do_action('weixin_share','ShareTimeline');?>});
		});
		// 分享到微博;
		WeixinJSBridge.on('menu:share:weibo', function(argv){
			WeixinJSBridge.invoke('shareWeibo',{
			"content":dataForWeixin.title+' '+dataForWeixin.url,
			"url":dataForWeixin.url
			}, function(res){<?php do_action('weixin_share','ShareWeibo');?>});
		});
		// 分享到Facebook
		WeixinJSBridge.on('menu:share:facebook', function(argv){
			WeixinJSBridge.invoke('shareFB',{
			"img_url":dataForWeixin.img,
			"img_width":"120",
			"img_height":"120",
			"link":dataForWeixin.url,
			"desc":dataForWeixin.desc,
			"title":dataForWeixin.title
			}, function(res){<?php do_action('weixin_share','ShareFB');?>});
		});
	};
	if(document.addEventListener){
		document.addEventListener('WeixinJSBridgeReady', onBridgeReady, false);
	}else if(document.attachEvent){
		document.attachEvent('WeixinJSBridgeReady'   , onBridgeReady);
		document.attachEvent('onWeixinJSBridgeReady' , onBridgeReady);
	}
})();
</script>
<?php
	}
}

有话要说