前端代碼:
wx.ready(function () {
// wx.ready(function () { //需在用戶可能點擊分享按鈕前就先調用
wx.onMenuShareTimeline({
title: ''+vm.tradeName, // 分享標題
link: location.protocol+'//'+location.host+'/wechat/shareServer/collageDetail/'+vm.shareOrdId+'/'+storeId+'/'+userId, // 分享鏈接,該鏈接域名或路徑必須與當前頁面對應的公衆號JS安全域名一致
imgUrl: '<%=imgBasePath%>'+vm.journeyUrl, // 分享圖標
success: function () {
// 設置成功
// alert("設置成功");
}
}, function(res) {
//這裏是回調函數
alert("分享成功");
})
// });
wx.onMenuShareAppMessage({
title: ''+vm.tradeName, // 分享標題
desc: "目的地:"+vm.destination, // 分享描述
link: location.protocol+'//'+location.host+'/wechat/shareServer/collageDetail/'+vm.shareOrdId+'/'+storeId+'/'+userId, // 分享鏈接,該鏈接域名或路徑必須與當前頁面對應的公衆號JS安全域名一致
imgUrl: '<%=imgBasePath%>'+vm.journeyUrl, // 分享圖標
type: 'link', // 分享類型,music、video或link,不填默認爲link
dataUrl: '', // 如果type是music或video,則要提供數據鏈接,默認爲空
success: function () {
// 用戶點擊了分享後執行的回調函數
// alert("設置成功");
}
}, function(res) {
//這裏是回調函數
alert("分享成功");
})
});
後端代碼:
//辦事處拼單列表-詳情-分享跳轉(解決微信分享不能帶參問題)
@RequestMapping("collageDetail/{id}/{storeId}/{userId}")
public ModelAndView collageDetailPush(@PathVariable("id") Long id
,@PathVariable("storeId")String storeId,@PathVariable("userId")String userId
,String code, String state, HttpServletRequest request, HttpServletResponse response){
ModelAndView mv = new ModelAndView("wechat/shareServer/shareOrd/collageDetail");
try {
User user = this.getUserByUserIdInSession(request, response);
if(user==null){
wxAuthorize(code,state,request,response);
}
String contextPath = request.getContextPath();
ShareOrd shareOrd = shareOrdService.selectByPrimaryKey(id);
if(shareOrd.getIsLocal()==1){
response.sendRedirect(contextPath+"/wechat/shareServer/collageDetail?id="+id+"&userId="+userId+"&storeId="+storeId);
}else{
response.sendRedirect(contextPath+"/wechat/shareServer/distributorCollageDetail?id="+id+"&userId="+userId+"&storeId="+storeId);
}
// request.getRequestDispatcher("collageDetail?id="+id).forward(request,response);
}catch (Exception e){
LOGGER.error("release--error",e);
}
return mv;
}
@RequestMapping("collageDetail")
public ModelAndView collageDetail(String code, String state, HttpServletRequest request, HttpServletResponse response,String userId,String storeId){
ModelAndView mv = new ModelAndView("wechat/shareServer/shareOrd/collageDetail");
try {
User user = this.getUserByUserIdInSession(request, response);
if(user==null){
wxAuthorize(code,state,request,response);
}
// mv.addObject("user", user);
if(StringUtils.isNotEmpty(userId)&&StringUtils.isNotEmpty(storeId)){
User user1 =userService.selectUserById(Long.valueOf(userId));
Store store=storeService.selectStoreById(Long.valueOf(storeId));
mv.addObject("name",store.getName());
mv.addObject("manager",store.getManager());
mv.addObject("phone",store.getPhone());
mv.addObject("headImg",user1.getHeadImgUrl());
}
}catch (Exception e){
LOGGER.error("release--error",e);
}
return mv;
}