微信分享设置 步骤 参考:http://blog.csdn.net/ty_hf/article/details/50585727
微信分享js文档:
http://qydev.weixin.qq.com/wiki/index.php?title=%E5%BE%AE%E4%BF%A1JS%E6%8E%A5%E5%8F%A3#.E6.AD.A5.E9.AA.A4.E4.B8.80.EF.BC.9A.E5.BC.95.E5.85.A5JS.E6.96.87.E4.BB.B6
一、java代码
<!-- 微信开发包 -->
<dependency> <groupId>com.github.sd4324530</groupId> <artifactId>fastweixin</artifactId> <version>1.3.10</version> </dependency>
/** */
private ApiConfig config = null; try { if (config == null) { config = new ApiConfig("wxffa365b8d84f7496", "2473273961eeff7ee825463248aa7c51", true); } JsAPI jsApi = new JsAPI(config); String url = req.getRequestURL().toString(); if (StringUtils.isNotBlank(req.getQueryString()) == true) { url = url + "?" + req.getQueryString(); } GetSignatureResponse signatureResponse = jsApi.getSignature(url); // logger.info(url + "\r\n" + // FastJSONUtils.toJsonString(signatureResponse)); modelMap.addAttribute("signatureResponse", signatureResponse); modelMap.addAttribute("weixinAppId", config.getAppid()); } catch (Exception ex) { logger.error("", ex); }二、jsp代码
<%@ page language="java" pageEncoding="UTF-8"%>
<%@ include file="../../commons/taglibs.jsp"%> <script type="text/javascript" src="http://res.wx.qq.com/open/js/jweixin-1.2.0.js"></script><script type="text/javascript">
wx.config({ debug : false, appId : '${weixinAppId}', timestamp : '${signatureResponse.timestamp}', nonceStr : '${signatureResponse.noncestr}', signature : '${signatureResponse.signature}', jsApiList : [ 'checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo', 'hideMenuItems' ] }); wx.ready(function() { wx.checkJsApi({ jsApiList : [ 'getNetworkType', 'previewImage', 'checkJsApi', 'onMenuShareTimeline', 'onMenuShareAppMessage', 'onMenuShareQQ', 'onMenuShareWeibo' ], success : function(res) { } }); var shareData = { title : shareTitle(), desc : shareDescription(), link : addUrlPara(), imgUrl : "${mimeBase}/images/pub/qibao.jpg", success : function() { // 用户确认分享后执行的回调函数 shareSuccess(3); }, cancel : function() { // 用户取消分享后执行的回调函数 } }; wx.onMenuShareAppMessage(shareData); wx.onMenuShareTimeline(shareData); wx.onMenuShareQQ(shareData); wx.onMenuShareWeibo(shareData); wx.hideMenuItems({ menuList : [ 'menuItem:copyUrl' ] }); }); wx.error(function(res) { console.log(res); }); function addUrlPara() { //传入地址 var href = window.location.href.split('#')[0]; return href; }function shareSuccess(type) {
}function shareDescription() {
var m = $("meta[name='description']"); return m.attr("content"); }function shareTitle() {
return $("title").html(); } </script>