package com.yeshi.fanli.controller; import java.io.PrintWriter; import java.net.URLEncoder; import java.util.ArrayList; import java.util.List; import javax.annotation.Resource; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.HttpSession; import org.springframework.stereotype.Controller; import org.springframework.web.bind.annotation.PathVariable; import org.springframework.web.bind.annotation.RequestMapping; import org.yeshi.utils.HttpUtil; import org.yeshi.utils.JsonUtil; import com.yeshi.fanli.entity.bus.share.UserShareGoodsHistory; import com.yeshi.fanli.entity.bus.user.UserInfo; import com.yeshi.fanli.entity.system.BusinessSystem; import com.yeshi.fanli.entity.system.CustomerContent; import com.yeshi.fanli.entity.system.CustomerName; import com.yeshi.fanli.entity.system.SystemClientParams; import com.yeshi.fanli.entity.taobao.TaoBaoGoodsBrief; import com.yeshi.fanli.exception.share.ShareGoodsException; import com.yeshi.fanli.log.LogHelper; import com.yeshi.fanli.service.inter.config.BusinessSystemService; import com.yeshi.fanli.service.inter.config.ConfigService; import com.yeshi.fanli.service.inter.config.CustomerContentService; import com.yeshi.fanli.service.inter.config.CustomerNameService; import com.yeshi.fanli.service.inter.config.SystemClientParamsService; import com.yeshi.fanli.service.inter.config.SystemConfigService; import com.yeshi.fanli.service.inter.goods.GoodsSecondClassService; import com.yeshi.fanli.service.inter.goods.ShareGoodsService; import com.yeshi.fanli.service.inter.goods.TaoBaoCouponService; import com.yeshi.fanli.service.inter.goods.TaoBaoGoodsBriefService; import com.yeshi.fanli.service.inter.order.config.HongBaoManageService; import com.yeshi.fanli.service.inter.taobao.TaoBaoUnionConfigService; import com.yeshi.fanli.service.inter.user.ShamUserService; import com.yeshi.fanli.service.inter.user.UserInfoService; import com.yeshi.fanli.service.inter.user.UserInviteRecordService; import com.yeshi.fanli.service.inter.user.invite.ThreeSaleSerivce; import com.yeshi.fanli.util.AESUtil; import com.yeshi.fanli.util.Constant; import com.yeshi.fanli.util.RedisManager; import com.yeshi.fanli.util.StringUtil; import com.yeshi.fanli.util.taobao.TaoBaoUtil; import com.yeshi.fanli.util.wx.WXLoginUtil; import net.sf.json.JSONArray; import net.sf.json.JSONObject; /** * 客户端网页接口与微信网页接口 * * @author Administrator * */ @Controller @RequestMapping("/client") public class ClientJspController { @Resource private GoodsSecondClassService goodsSecondClassService; @Resource private ConfigService configService; @Resource private HongBaoManageService hongBaoManageService; @Resource private ShamUserService shamUserService; @Resource private TaoBaoCouponService taoBaoCouponService; @Resource private ThreeSaleSerivce threeSaleSerivce; @Resource private UserInfoService userInfoService; @Resource private BusinessSystemService businessSystemService; @Resource private SystemConfigService systemConfigService; @Resource private SystemClientParamsService systemClientParamsService; @Resource private ShareGoodsService shareGoodsService; @Resource private TaoBaoGoodsBriefService taoBaoGoodsBriefService; @Resource private UserInviteRecordService userInviteRecordService; @Resource private RedisManager redisManager; @Resource private TaoBaoUnionConfigService taoBaoUnionConfigService; @Resource private CustomerNameService customerNameService; @Resource private CustomerContentService customerContentService; private static final String DOWNURL = "http://sj.qq.com/myapp/detail.htm?apkName=" + Constant.systemCommonConfig.getAndroidPackageName(); private static final String DOWNURL2 = "http://121.42.200.138/apk/fanliquan20180124.apk"; @RequestMapping(value = "/new/{uid}") public String threeShareRepNew(@PathVariable String uid, String code, String state, String packages, String platform, String ios, HttpSession httpSession, HttpServletRequest request) { BusinessSystem system = businessSystemService.getBusinessSystem(platform, packages); String wxState = (String) httpSession.getAttribute("wxState"); // 通过配置参数获取 String down = DOWNURL2; SystemClientParams params = systemClientParamsService.getSystemClientParamsBySystemAndKey(system, "download_app_url"); if (params != null) down = params.getValue(); if (state!=null&&!state.equals(wxState)) {// 不是微信返回的! // request.setAttribute("error", "1"); return "redirect:" + down; } // 保存邀请记录 userInviteRecordService.saveInviteRecord(code, uid); return "redirect:" + down; } // 新版分享 @RequestMapping("threeShareNew") public String threeShareNew(HttpServletRequest request, HttpSession session, HttpServletResponse response, long uid) { UserInfo userInfo = userInfoService.getUserById(uid); if (userInfo == null) { return "share/error"; } try { String header = request.getHeader("User-Agent");// MicroMessenger:微信浏览器 String ios = "ios=1"; if (header.contains("iPhone")) { ios = "ios=2"; } String redirect_uri = "http://" + Constant.wxGZConfig.getLoginHost() + "/" + Constant.systemCommonConfig.getProjectName() + "/client/new/" + uid + "?packages=" + Constant.systemCommonConfig.getAndroidPackageName() + "&platform=ANDROID&" + ios; redirect_uri = URLEncoder.encode(redirect_uri, "utf-8"); long currentTimeMillis = java.lang.System.currentTimeMillis(); String md5 = StringUtil.Md5(currentTimeMillis + ""); session.setAttribute("wxState", md5); String baseUrl = "https://open.weixin.qq.com/connect/oauth2/authorize?appid=" + WXLoginUtil.WEXIN_APPID + "&redirect_uri=" + redirect_uri + "&response_type=code&scope=snsapi_userinfo&state=" + md5 + "#wechat_redirect"; response.sendRedirect(baseUrl); } catch (Exception e) { e.printStackTrace(); } return "share2/yaoqing"; } @RequestMapping("getShareGoodsInfo") public void getShareGoodsInfo(HttpServletRequest request, long uid, long id, String sign, PrintWriter out) { if (!StringUtil.Md5("" + uid + id + Constant.WEBPAGE_SIGN_KEY).equalsIgnoreCase(sign)) { out.print(JsonUtil.loadFalseResult(-1, "签名错误")); return; } // 添加分享 try { long startTime = java.lang.System.currentTimeMillis(); UserShareGoodsHistory userShareGoodsHistory = shareGoodsService.addShareGoodsHistory(uid, id); LogHelper.test("生成分享图的总耗时为:" + (java.lang.System.currentTimeMillis() - startTime)); JSONObject data = new JSONObject(); JSONObject shareData = new JSONObject(); JSONArray imgArr = new JSONArray(); String pictures = userShareGoodsHistory.getPictures(); JSONArray pictureArray = JSONArray.fromObject(pictures); for (int i = 0; i < pictureArray.size(); i++) { imgArr.add(pictureArray.optString(i)); } TaoBaoGoodsBrief goods = redisManager.getTaoBaoGoodsBrief(userShareGoodsHistory.getGoodsId()); shareData.put("type", "2"); shareData.put("title", goods.getTitle()); shareData.put("description", goods.getTitle()); shareData.put("imgs", imgArr); try { data.put("wx", StringUtil.getBase64String(shareData.toString())); data.put("wxcircle", StringUtil.getBase64String(shareData.toString())); data.put("tkcode", StringUtil.getBase64String(userShareGoodsHistory.getTkCode())); data.put("qq", StringUtil.getBase64String(shareData.toString())); data.put("qqzone", StringUtil.getBase64String(shareData.toString())); data.put("sina", StringUtil.getBase64String(shareData.toString())); data.put("tishi", StringUtil.getBase64String("分享中...")); data.put("shareGoods", JsonUtil.getSimpleGson().toJson(userShareGoodsHistory)); JSONObject goodsJSON = new JSONObject(); goodsJSON.put("title", goods.getTitle()); goodsJSON.put("zkPrice", goods.getZkPrice()); // 有券 if (!StringUtil.isNullOrEmpty(goods.getCouponInfo())) { goodsJSON.put("finalPrice", TaoBaoUtil.getAfterUseCouplePrice(goods)); } data.put("goods", goodsJSON); String link = String.format("http://%s/%s/client/html/sharegoods/share_detail.html?uid=%s&goodsId=%s", Constant.systemCommonConfig.getProjectHost(), Constant.systemCommonConfig.getProjectName(), AESUtil.encrypt(uid + ""), id + ""); try { String shortLink = HttpUtil.getShortLink(link); data.put("link", shortLink); } catch (Exception e) { data.put("link", link); } out.print(JsonUtil.loadTrueResult(data)); } catch (Exception e) { JSONObject rdata = new JSONObject(); rdata.put("uid", uid); rdata.put("id", id); LogHelper.errorDetailInfo(e, rdata.toString(), request.getRequestURI()); out.print(JsonUtil.loadFalseResult(1001, "未知错误")); } } catch (ShareGoodsException e1) { JSONObject data = new JSONObject(); data.put("uid", uid); data.put("id", id); LogHelper.errorDetailInfo(e1, data.toString(), request.getRequestURI()); out.print(JsonUtil.loadFalseResult(e1.getCode(), e1.getMsg())); } catch (Exception e) { LogHelper.errorDetailInfo(e); } } // 获取帮助中心列表 @RequestMapping("getHelpList") public void getHelpList(PrintWriter out) { List totalList = new ArrayList<>(); int page = 0; List customerNameList = customerNameService.customerNameList(page, "", 1); if (customerNameList != null && customerNameList.size() > 0) totalList.addAll(customerNameList); while (customerNameList != null && customerNameList.size() == Constant.PAGE_SIZE) { page++; customerNameList = customerNameService.customerNameList(page, "", 1); if (customerNameList != null && customerNameList.size() > 0) totalList.addAll(customerNameList); } // 获取每个下面的详情 for (CustomerName cn : totalList) { List contentList = customerContentService.getSecondProblemList(0, "", cn.getId()); cn.setCustomerContentList(contentList); } out.print(JsonUtil.loadTrueResult(JsonUtil.getSimpleGson().toJson(totalList))); } @RequestMapping("getHelpDetail") public void getHelpDetail(long id, PrintWriter out) { List totalList = new ArrayList<>(); CustomerContent customerContent = customerContentService.getCustomerContent(id); out.print(JsonUtil.loadTrueResult(customerContent.getContent().replace("\n", "
"))); } /** * 获取邀请有奖的规则 * * @param callback * @param out */ @RequestMapping("getinviteactivityrules") public void getInviteActivityRules(String callback, PrintWriter out) { String key = "activityRules"; // key值 com.yeshi.fanli.entity.system.BusinessSystem system = new BusinessSystem(); system.setCreatetime(java.lang.System.currentTimeMillis()); system.setPlatform(1); system.setId(4L); SystemClientParams values = systemClientParamsService.getSystemClientParamsBySystemAndKey(system, key); // 转换换行符 给前端 String valueN = values.getValue(); String valueBr = valueN.replace("\n", "

"); if (!StringUtil.isNullOrEmpty(callback)) { out.print(JsonUtil.loadJSONP(callback, JsonUtil.loadTrueResult(valueBr))); } else { out.print(JsonUtil.loadTrueResult(valueBr)); } } }