| | |
| | | /nbproject/private/ |
| | | /nbbuild/ |
| | | /dist/ |
| | | /logs/ |
| | | /nbdist/ |
| | | /.nb-gradle/ |
| | | build/ |
New file |
| | |
| | | package com.yeshi.buwan.aspect; |
| | | |
| | | import com.yeshi.buwan.util.RedisManager; |
| | | import org.aspectj.lang.ProceedingJoinPoint; |
| | | import org.aspectj.lang.Signature; |
| | | import org.aspectj.lang.annotation.Around; |
| | | import org.aspectj.lang.annotation.Aspect; |
| | | import org.aspectj.lang.reflect.MethodSignature; |
| | | import org.springframework.core.DefaultParameterNameDiscoverer; |
| | | import org.springframework.core.annotation.Order; |
| | | import org.springframework.expression.ExpressionParser; |
| | | import org.springframework.expression.spel.standard.SpelExpressionParser; |
| | | import org.springframework.stereotype.Component; |
| | | import org.springframework.web.context.request.RequestContextHolder; |
| | | import org.springframework.web.context.request.ServletRequestAttributes; |
| | | import org.yeshi.utils.JsonUtil; |
| | | import org.yeshi.utils.SPELExpressionUtil; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.annotation.RequestSerializableByKey; |
| | | import redis.clients.jedis.Jedis; |
| | | import redis.clients.jedis.params.SetParams; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletResponse; |
| | | import java.io.PrintWriter; |
| | | import java.lang.reflect.Method; |
| | | import java.util.HashSet; |
| | | import java.util.Set; |
| | | |
| | | @Component |
| | | @Aspect |
| | | @Order(4) |
| | | public class RequestSerializableAspect { |
| | | @Resource |
| | | private RedisManager redisManager; |
| | | |
| | | private ExpressionParser parser = new SpelExpressionParser(); |
| | | |
| | | private DefaultParameterNameDiscoverer nameDiscoverer = new DefaultParameterNameDiscoverer(); |
| | | |
| | | public static Set<Long> waitingThreadSet = new HashSet<>(); |
| | | |
| | | |
| | | @Around("execution(public * com.yeshi.buwan.controller..*.*(..))") |
| | | public Object requestSerializable(ProceedingJoinPoint joinPoint) throws Throwable { |
| | | Signature signature = joinPoint.getSignature(); |
| | | MethodSignature methodSignature = (MethodSignature) signature; |
| | | Method targetMethod = methodSignature.getMethod(); |
| | | String cacheKey = null; |
| | | try { |
| | | Method realMethod = joinPoint.getTarget().getClass().getDeclaredMethod(joinPoint.getSignature().getName(), |
| | | targetMethod.getParameterTypes()); |
| | | |
| | | if (realMethod.isAnnotationPresent(RequestSerializableByKey.class)) { |
| | | RequestSerializableByKey rs = realMethod.getAnnotation(RequestSerializableByKey.class); |
| | | //EL表达式解析 |
| | | String key = rs.key(); |
| | | cacheKey = SPELExpressionUtil.generateKeyBySpEL(key, joinPoint); |
| | | PrintWriter out = null; |
| | | try {// redis做原子性保护 |
| | | if (!StringUtil.isNullOrEmpty(cacheKey)) { |
| | | cacheKey = joinPoint.getTarget().getClass().getName() + "." + targetMethod.getName() + "-" |
| | | + cacheKey; |
| | | String cacheAlias = cacheKey; |
| | | cacheKey = "rs-" + StringUtil.Md5(cacheKey); |
| | | // jiedis原子性做拦截 |
| | | Jedis jedis = redisManager.getJedis(); |
| | | long threadId = Thread.currentThread().getId(); |
| | | try { |
| | | waitingThreadSet.add(threadId); |
| | | String result = null; |
| | | long startTime = System.currentTimeMillis(); |
| | | // 等待响应 |
| | | while (StringUtil.isNullOrEmpty(result)) { |
| | | |
| | | result = jedis.set(cacheKey, "1", new SetParams().nx().ex(30)); |
| | | if (StringUtil.isNullOrEmpty(result)) { |
| | | try { |
| | | Thread.sleep(50); |
| | | } catch (InterruptedException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | if (System.currentTimeMillis() - startTime > 1000 * 30L) { |
| | | waitingThreadSet.remove(Thread.currentThread().getId()); |
| | | if (out == null) { |
| | | ServletRequestAttributes servletContainer = (ServletRequestAttributes) RequestContextHolder.getRequestAttributes(); |
| | | HttpServletResponse response = servletContainer.getResponse(); |
| | | out = response.getWriter(); |
| | | } |
| | | out.print(JsonUtil.loadFalseResult("连接超时")); |
| | | return null; |
| | | } |
| | | } else { |
| | | break; |
| | | } |
| | | } |
| | | |
| | | if (!StringUtil.isNullOrEmpty(result)) { |
| | | try { |
| | | return joinPoint.proceed(); |
| | | } finally { |
| | | jedis.del(cacheKey); |
| | | waitingThreadSet.remove(Thread.currentThread().getId()); |
| | | } |
| | | } |
| | | } finally { |
| | | jedis.close(); |
| | | } |
| | | } |
| | | } catch (Exception e) {// 原子性保护出错 |
| | | return joinPoint.proceed(); |
| | | } |
| | | } |
| | | |
| | | } catch (NoSuchMethodException e) { |
| | | e.printStackTrace(); |
| | | } catch (SecurityException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | return joinPoint.proceed(); |
| | | } |
| | | |
| | | } |
| | |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | | import com.yeshi.buwan.util.RedisManager; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.log.LoggerUtil; |
| | | import com.yeshi.buwan.util.user.VipUtil; |
| | | import com.yeshi.buwan.util.vip.VIPOrderUtil; |
| | | import org.json.JSONObject; |
| | |
| | | @Controller |
| | | @RequestMapping("alipay") |
| | | public class AlipayController { |
| | | Logger logger = LoggerFactory.getLogger(AlipayController.class); |
| | | Logger logger = LoggerUtil.getVIPLogger(); |
| | | |
| | | @Resource |
| | | private RedisManager redisManager; |
| | |
| | | if (right) { |
| | | //支付成功 |
| | | if ("TRADE_SUCCESS".equalsIgnoreCase(tradeStatus)) { |
| | | AlipayTradeQueryResponse res = AlipayH5PayUtil.queryOrder(app, outTradeNo, null); |
| | | //支付成功 |
| | | if (res.isSuccess() && "TRADE_SUCCESS".equalsIgnoreCase(res.getTradeStatus())) { |
| | | String id = VIPOrderUtil.getIdFromOutOrderNo(outTradeNo); |
| | | try { |
| | | vipService.paySuccess(id, VIPOrderRecord.PAY_WAY_ALIPAY, new BigDecimal(res.getPayAmount()), new Date()); |
| | | } catch (VIPException e) { |
| | | e.printStackTrace(); |
| | | logger.error("支付成功回调出错 id:{}", id, e); |
| | | } |
| | | } |
| | | logger.info("订单ID:{}", id); |
| | | vipService.checkOrderPayState(id); |
| | | } |
| | | response.getWriter().print("success"); |
| | | response.getWriter().close(); |
| | |
| | | package com.yeshi.buwan.controller; |
| | | |
| | | import com.yeshi.buwan.domain.DetailSystem; |
| | | import com.yeshi.buwan.domain.vip.VIPOrderRecord; |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | import com.yeshi.buwan.funtv.FunTVUtil; |
| | | import com.yeshi.buwan.service.imp.ConfigService; |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | import org.springframework.stereotype.Controller; |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.PrintWriter; |
| | | import java.util.Date; |
| | | import java.util.Map; |
| | | |
| | | @Controller |
| | |
| | | |
| | | @Resource |
| | | private FunTVUtil funTVUtil; |
| | | |
| | | |
| | | @Resource |
| | | private VIPService vipService; |
| | | |
| | | Logger logger = LoggerFactory.getLogger(TestController.class); |
| | | |
| | |
| | | out.print("success"); |
| | | } |
| | | |
| | | @RequestMapping("vipPay") |
| | | public void vipPay(String id) { |
| | | VIPOrderRecord record = vipService.getOrderRecord(id); |
| | | try { |
| | | vipService.paySuccess(record.getId(), VIPOrderRecord.PAY_WAY_ALIPAY, record.getMoney(), new Date()); |
| | | } catch (VIPException e) { |
| | | e.printStackTrace(); |
| | | } catch (PPTVException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | package com.yeshi.buwan.controller; |
| | | |
| | | import com.yeshi.buwan.domain.vip.VIPOrderRecord; |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.user.VipUtil; |
| | |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.yeshi.utils.entity.wx.WXAPPInfo; |
| | | import org.yeshi.utils.wx.WXPayV3Util; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.crypto.Cipher; |
| | |
| | | import java.security.InvalidKeyException; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.util.Base64; |
| | | import java.util.Date; |
| | | |
| | | @Controller |
| | | @RequestMapping("wx") |
| | |
| | | String tradeState = decript.optString("trade_state"); |
| | | //支付成功 |
| | | if (tradeState.equalsIgnoreCase("SUCCESS")) { |
| | | boolean isPaySuccess = WXPayV3Util.isPaySuccess(outTradeNo, wxappInfo); |
| | | if (isPaySuccess) { |
| | | BigDecimal money = new BigDecimal(decript.optJSONObject("amount").optInt("total")).divide(new BigDecimal(100), 2, RoundingMode.FLOOR); |
| | | String id = VIPOrderUtil.getIdFromOutOrderNo(outTradeNo); |
| | | try { |
| | | vipService.paySuccess(id, VIPOrderRecord.PAY_WAY_WX, money, new Date()); |
| | | } catch (VIPException e) { |
| | | logger.error("订单支付成功处理出错:{}", id, e); |
| | | vipService.checkOrderPayState(id); |
| | | } |
| | | } |
| | | } |
| | | |
| | | break; |
| | | } |
| | | } |
| | |
| | | private BaiduParser baiduParser; |
| | | |
| | | @Resource |
| | | private VipParser vipParser; |
| | | |
| | | @Resource |
| | | private UserService userService; |
| | | |
| | | @RequestMapping(value = "/ad", method = RequestMethod.POST) |
| | |
| | | out.close(); |
| | | } |
| | | |
| | | @RequestMapping(value = "/vip", method = RequestMethod.POST) |
| | | public void vip(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | @Resource |
| | | private UserVideoParser userVideoParser; |
| | | |
| | | // 配置类接口 |
| | | @RequestMapping(value = "/userVideo", method = RequestMethod.POST) |
| | | public void userVideo(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | String method = request.getParameter("Method"); |
| | | if (StringUtil.isNullOrEmpty(method)) |
| | | return; |
| | | |
| | | if (!Utils.signIsRight(request)) |
| | | out.print(JsonUtil.loadFalseJson("签名错误")); |
| | | |
| | | switch (method) { |
| | | case "buy": |
| | | vipParser.buy(acceptData, request, out); |
| | | case "getWatchHistory": |
| | | userVideoParser.getWatchHistory(acceptData, request, out); |
| | | break; |
| | | case "deleteWatchHistory": |
| | | userVideoParser.deleteWatchHistory(acceptData, request, out); |
| | | break; |
| | | } |
| | | |
| | | out.close(); |
| | | } |
| | | |
| | |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpSession; |
| | | import java.util.Date; |
| | | |
| | | @Controller |
| | | @RequestMapping("api/v2/user") |
| | |
| | | if (extra == null) |
| | | extra = loginUserService.initExtra(loginUid); |
| | | |
| | | //需要初始化VIP信息 |
| | | vipService.initUserVipInfo(loginUid); |
| | | |
| | | UserVIPInfo vipInfo = vipService.getVIPInfo(loginUid); |
| | | UserInfoVO vo = UserInfoVOFactory.create(loginUser, extra, vipInfo); |
| | | return JsonUtil.loadTrueJson(new Gson().toJson(vo)); |
| | |
| | | import org.springframework.stereotype.Controller; |
| | | import org.springframework.web.bind.annotation.RequestMapping; |
| | | import org.springframework.web.bind.annotation.ResponseBody; |
| | | import org.yeshi.utils.annotation.RequestSerializableByKey; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | |
| | | record.setUid(loginUid); |
| | | record.setType(vipPrice.getType()); |
| | | record.setMoney(vipPrice.getPrice()); |
| | | record.setPayWay(payWay); |
| | | record.setState(VIPOrderRecord.STATE_NOT_PAY); |
| | | try { |
| | | vipService.addVIPRecord(record); |
| | |
| | | case VIPOrderRecord |
| | | .PAY_WAY_ALIPAY: { |
| | | //生成支付宝支付订单 |
| | | String form = VipUtil.getVipChargeAlipayForm(orderNo, record.getMoney()); |
| | | String form = VipUtil.getVipChargeAlipayForm(record.getId(), orderNo, record.getMoney()); |
| | | //暂存2分钟 |
| | | String id = StringUtil.Md5(UUID.randomUUID().toString() + "#" + System.currentTimeMillis()); |
| | | redisManager.cacheCommonString(id, form, 120); |
| | | org.json.JSONObject data = new org.json.JSONObject(); |
| | | data.put("payUrl", "http://api.ysdq.yeshitv.com:8089/BuWan/alipay/printPayForm?formId=" + id); |
| | | data.put("payUrl", Constant.HOST + "/BuWan/alipay/printPayForm?formId=" + id); |
| | | data.put("payWay", payWay); |
| | | return JsonUtilV2.loadTrueJson(data.toString()); |
| | | } |
| | |
| | | .PAY_WAY_WX: { |
| | | //生成微信支付订单 |
| | | try { |
| | | String payUrl = VipUtil.createWXOrder(ip, orderNo, vipPrice.getPrice(), "影视大全VIP-" + vipPrice.getType().getName()); |
| | | String payUrl = VipUtil.createWXOrder(record.getId(), ip, orderNo, vipPrice.getPrice(), "影视大全VIP-" + vipPrice.getType().getName()); |
| | | org.json.JSONObject data = new org.json.JSONObject(); |
| | | data.put("payUrl", payUrl); |
| | | data.put("payWay", payWay); |
| | |
| | | return JsonUtilV2.loadFalseJson("请选择支付方式"); |
| | | } |
| | | |
| | | /** |
| | | * 检查是否支付 |
| | | * |
| | | * @param acceptData |
| | | * @param loginUid |
| | | * @param id |
| | | * @return |
| | | */ |
| | | @RequestMapping("checkPay") |
| | | @ResponseBody |
| | | @RequestSerializableByKey(key = "'vip-checkPay-'+#id") |
| | | public String checkPay(AcceptData acceptData, String loginUid, String id) { |
| | | VIPOrderRecord record = vipService.getOrderRecord(id); |
| | | if (record == null || !record.getUid().equalsIgnoreCase(loginUid)) { |
| | | return JsonUtilV2.loadFalseJson("记录不存在/不是您的订单"); |
| | | } |
| | | |
| | | record = vipService.checkOrderPayState(id); |
| | | //未支付 |
| | | if (record != null && record.getState() != VIPOrderRecord.STATE_PAY) { |
| | | return JsonUtilV2.loadFalseJson(1, "支付未完成"); |
| | | } |
| | | |
| | | JSONObject data = new JSONObject(); |
| | | data.put("money", record.getPayMoney() == null ? record.getMoney() : record.getPayMoney()); |
| | | |
| | | return JsonUtilV2.loadTrueJson(data.toString()); |
| | | } |
| | | |
| | | |
| | | } |
| | |
| | | mobile = phone; |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(code)) { |
| | | out.print(JsonUtil.loadFalseJson("code为空")); |
| | | return; |
| | | } |
| | | |
| | | try { |
| | | loginUserService.bindPhone(loginUid + "", mobile); |
| | | out.print(JsonUtil.loadTrueJson("")); |
| | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.xxl.rpc.util.ThreadPoolUtil; |
| | | import com.yeshi.buwan.domain.*; |
| | | import com.yeshi.buwan.domain.video.VideoWatchHistory; |
| | | import com.yeshi.buwan.pptv.PPTVUtil; |
| | | import com.yeshi.buwan.pptv.entity.PPTVSeries; |
| | | import com.yeshi.buwan.service.imp.*; |
| | | import com.yeshi.buwan.service.inter.juhe.PPTVService; |
| | | import com.yeshi.buwan.service.inter.video.VideoWatchHistoryService; |
| | | import com.yeshi.buwan.util.*; |
| | | import com.yeshi.buwan.util.annotation.RequireUid; |
| | | import com.yeshi.buwan.vo.AcceptData; |
| | | import org.apache.commons.httpclient.HttpClient; |
| | |
| | | import org.springframework.stereotype.Controller; |
| | | |
| | | import com.yeshi.buwan.domain.entity.PlayUrl; |
| | | import com.yeshi.buwan.util.CacheUtil; |
| | | import com.yeshi.buwan.util.Constant; |
| | | import com.yeshi.buwan.util.JsonUtil; |
| | | import com.yeshi.buwan.util.JuheVideoUtil; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.TimeUtil; |
| | | import com.yeshi.buwan.util.Utils; |
| | | import com.yeshi.buwan.util.VideoPictureUtil; |
| | | import com.yeshi.buwan.util.JuHe.VideoResourceUtil; |
| | | import com.yeshi.buwan.util.video.VideoDetailUtil; |
| | | import com.yeshi.buwan.util.zhibo.MeiNvZhiBoUtil; |
| | |
| | | |
| | | @Resource |
| | | private PPTVService pptvService; |
| | | |
| | | @Resource |
| | | private VideoWatchHistoryService videoWatchHistoryService; |
| | | |
| | | @RequireUid |
| | | public void getHomeAd(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | |
| | | String resourceId = request.getParameter("ResourceId"); |
| | | String thirdType = request.getParameter("Type"); |
| | | String loginUid = request.getParameter("LoginUid"); |
| | | String position = request.getParameter("Position"); |
| | | |
| | | if (StringUtil.isNullOrEmpty(videoId)) { |
| | | out.print(JsonUtil.loadFalseJson("请上传VideoId")); |
| | |
| | | } |
| | | } |
| | | |
| | | ThreadUtil.run(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | int p = 0; |
| | | if (!StringUtil.isNullOrEmpty(position)) { |
| | | p = Integer.parseInt(position); |
| | | } |
| | | |
| | | VideoWatchHistory history = new VideoWatchHistory(); |
| | | history.setDevice(acceptData.getDevice()); |
| | | history.setVideoId(videoId); |
| | | history.setUid(loginUid); |
| | | history.setPosition(p); |
| | | videoWatchHistoryService.add(history); |
| | | } |
| | | }); |
| | | |
| | | |
| | | //PPTV网页播放 |
| | | if (resourceId != null && Integer.parseInt(resourceId) == PPTVUtil.RESOURCE_ID) { |
| | | JSONObject data = new JSONObject(); |
| | | PPTVSeries series = pptvService.getSeriesDetailByVideoId(videoId); |
| | | String playUrl = PPTVUtil.getPlayUrl(series, series.getSeries().get(0)); |
| | | int p = 0; |
| | | if (!StringUtil.isNullOrEmpty(position)) { |
| | | p = Integer.parseInt(position); |
| | | } |
| | | |
| | | p = p >= series.getSeries().size() ? 0 : p; |
| | | |
| | | String playUrl = PPTVUtil.getPlayUrl(series, series.getSeries().get(p)); |
| | | data.put("videoId", videoId); |
| | | data.put("playUrl", playUrl); |
| | | data.put("pptv", true); |
New file |
| | |
| | | package com.yeshi.buwan.controller.parser; |
| | | |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import com.yeshi.buwan.domain.video.VideoWatchHistory; |
| | | import com.yeshi.buwan.service.imp.VideoService; |
| | | import com.yeshi.buwan.service.inter.video.VideoWatchHistoryService; |
| | | import com.yeshi.buwan.util.Constant; |
| | | import com.yeshi.buwan.util.JsonUtil; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.vo.AcceptData; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | import java.io.PrintWriter; |
| | | import java.util.ArrayList; |
| | | import java.util.HashMap; |
| | | import java.util.List; |
| | | import java.util.Map; |
| | | |
| | | @Component |
| | | public class UserVideoParser { |
| | | |
| | | @Resource |
| | | private VideoWatchHistoryService videoWatchHistoryService; |
| | | |
| | | @Resource |
| | | private VideoService videoService; |
| | | |
| | | public void getWatchHistory(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | |
| | | int page = Integer.parseInt(request.getParameter("Page")); |
| | | page = page == 0 ? 1 : page; |
| | | List<VideoWatchHistory> list = videoWatchHistoryService.listHistory(acceptData.getDevice(), page, Constant.pageCount); |
| | | long count = videoWatchHistoryService.countHistory(acceptData.getDevice()); |
| | | |
| | | List<String> videoIds = new ArrayList<>(); |
| | | if (list != null) |
| | | for (VideoWatchHistory wh : list) { |
| | | videoIds.add(wh.getVideoId()); |
| | | } |
| | | |
| | | List<VideoInfo> videoInfoList = videoService.getVideoInfoList(videoIds); |
| | | Map<String, VideoInfo> videoInfoMap = new HashMap<>(); |
| | | if (videoInfoList != null) |
| | | for (VideoInfo vi : videoInfoList) { |
| | | videoInfoMap.put(vi.getId(), vi); |
| | | } |
| | | for (VideoWatchHistory wh : list) { |
| | | wh.setVideo(videoInfoMap.get(wh.getVideoId())); |
| | | } |
| | | |
| | | |
| | | JSONObject root = new JSONObject(); |
| | | root.put("count", count); |
| | | root.put("list", StringUtil.outPutResultJson(list)); |
| | | out.print(JsonUtil.loadTrueJson(root.toString())); |
| | | } |
| | | |
| | | public void deleteWatchHistory(AcceptData acceptData, HttpServletRequest request, PrintWriter out) { |
| | | String ids = (request.getParameter("Ids")); |
| | | List<String> idList = new ArrayList<>(); |
| | | JSONArray array = JSONArray.fromObject(ids); |
| | | if (array != null) |
| | | for (int i = 0; i < array.size(); i++) { |
| | | idList.add(array.optString(i)); |
| | | } |
| | | videoWatchHistoryService.delete(idList); |
| | | |
| | | out.print(JsonUtil.loadTrueJson("")); |
| | | } |
| | | |
| | | } |
| | |
| | | if (pptvQuery.seriesCode != null) { |
| | | whereList.add(Criteria.where("seriesCode").is(pptvQuery.seriesCode)); |
| | | } |
| | | query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "rank"))); |
| | | Criteria[] wheres = new Criteria[whereList.size()]; |
| | | whereList.toArray(wheres); |
| | | query.addCriteria(new Criteria().andOperator(wheres)); |
| | | query.skip(pptvQuery.start); |
| | | query.limit(pptvQuery.count); |
| | | List<Sort.Order> orders = new ArrayList<>(); |
| | | orders.add(new Sort.Order(Sort.Direction.ASC, "rank")); |
| | | query.with(new Sort(orders)); |
| | | |
| | | return findList(query); |
| | | } |
| | | |
| | |
| | | public PPTVSeriesProgramMap getLatestByInfoId(String infoId) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("infoId").is(infoId)); |
| | | List<Sort.Order> orders = new ArrayList<>(); |
| | | orders.add(new Sort.Order(Sort.Direction.DESC, "rank")); |
| | | query.with(new Sort(orders)); |
| | | query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "rank"))); |
| | | return findOne(query); |
| | | } |
| | | |
New file |
| | |
| | | package com.yeshi.buwan.dao.video; |
| | | |
| | | import com.yeshi.buwan.dao.base.MongodbBaseDao; |
| | | import com.yeshi.buwan.domain.video.AlbumVideoMap; |
| | | import com.yeshi.buwan.domain.video.VideoWatchHistory; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.query.Criteria; |
| | | import org.springframework.data.mongodb.core.query.Query; |
| | | import org.springframework.stereotype.Repository; |
| | | |
| | | import java.util.List; |
| | | |
| | | @Repository |
| | | public class VideoWatchHistoryDao extends MongodbBaseDao<VideoWatchHistory> { |
| | | |
| | | |
| | | public List<VideoWatchHistory> list(String device, int start, int count) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("device").is(device)); |
| | | query.skip(start); |
| | | query.limit(count); |
| | | query.with(new Sort(new Sort.Order(Sort.Direction.DESC, "createTime"))); |
| | | return findList(query); |
| | | } |
| | | |
| | | public long count(String device) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("device").is(device)); |
| | | return count(query); |
| | | } |
| | | |
| | | } |
| | |
| | | |
| | | import com.yeshi.buwan.dao.base.MongodbBaseDao; |
| | | import com.yeshi.buwan.domain.vip.VIPPrice; |
| | | import com.yeshi.buwan.domain.vip.VIPPriceType; |
| | | import javafx.print.Collation; |
| | | import org.springframework.data.domain.Sort; |
| | | import org.springframework.data.mongodb.core.mapping.Document; |
| | |
| | | return findList(query); |
| | | } |
| | | |
| | | /** |
| | | * 根据价格类型查询 |
| | | * |
| | | * @param vipPriceType |
| | | * @return |
| | | */ |
| | | public VIPPrice selectByType(VIPPriceType vipPriceType) { |
| | | Query query = new Query(); |
| | | query.addCriteria(Criteria.where("type").is(vipPriceType)); |
| | | return findOne(query); |
| | | } |
| | | |
| | | } |
New file |
| | |
| | | package com.yeshi.buwan.domain.video; |
| | | |
| | | import com.google.gson.annotations.Expose; |
| | | import com.yeshi.buwan.domain.VideoInfo; |
| | | import org.springframework.data.annotation.Id; |
| | | import org.springframework.data.annotation.Transient; |
| | | import org.springframework.data.mongodb.core.index.Indexed; |
| | | import org.springframework.data.mongodb.core.mapping.Document; |
| | | |
| | | import java.util.Date; |
| | | |
| | | /** |
| | | * 视频观看记录 |
| | | */ |
| | | @Document(collection = "videoWatchHistory") |
| | | public class VideoWatchHistory { |
| | | |
| | | @Expose |
| | | @Id |
| | | private String id; |
| | | @Expose |
| | | private String videoId; |
| | | |
| | | @Indexed |
| | | private String device; |
| | | |
| | | private String uid; |
| | | |
| | | private Integer position; |
| | | |
| | | @Expose |
| | | @Indexed |
| | | private Date createTime; |
| | | |
| | | |
| | | @Expose |
| | | @Transient |
| | | private VideoInfo video; |
| | | |
| | | |
| | | /** |
| | | * 生成主键 |
| | | * |
| | | * @param device |
| | | * @param videoId |
| | | * @return |
| | | */ |
| | | public static String createId(String device, String videoId) { |
| | | |
| | | return device + "_" + videoId; |
| | | } |
| | | |
| | | |
| | | public String getId() { |
| | | return id; |
| | | } |
| | | |
| | | public void setId(String id) { |
| | | this.id = id; |
| | | } |
| | | |
| | | public String getVideoId() { |
| | | return videoId; |
| | | } |
| | | |
| | | public void setVideoId(String videoId) { |
| | | this.videoId = videoId; |
| | | } |
| | | |
| | | public String getDevice() { |
| | | return device; |
| | | } |
| | | |
| | | public void setDevice(String device) { |
| | | this.device = device; |
| | | } |
| | | |
| | | public String getUid() { |
| | | return uid; |
| | | } |
| | | |
| | | public void setUid(String uid) { |
| | | this.uid = uid; |
| | | } |
| | | |
| | | public Date getCreateTime() { |
| | | return createTime; |
| | | } |
| | | |
| | | public void setCreateTime(Date createTime) { |
| | | this.createTime = createTime; |
| | | } |
| | | |
| | | |
| | | public VideoInfo getVideo() { |
| | | return video; |
| | | } |
| | | |
| | | public void setVideo(VideoInfo video) { |
| | | this.video = video; |
| | | } |
| | | |
| | | |
| | | public Integer getPosition() { |
| | | return position; |
| | | } |
| | | |
| | | public void setPosition(Integer position) { |
| | | this.position = position; |
| | | } |
| | | } |
New file |
| | |
| | | package com.yeshi.buwan.exception; |
| | | |
| | | public class PPTVException extends Exception { |
| | | |
| | | private int code; |
| | | private String msg; |
| | | |
| | | public PPTVException(int code, String msg) { |
| | | this.code = code; |
| | | this.msg = msg; |
| | | } |
| | | } |
| | |
| | | String result = baseRequest("https://coapi.pptv.com/coapi-web/api/http/sopRequest", params, "pptv.channel.openid.get"); |
| | | System.out.println(result); |
| | | JSONObject resultJSON = JSONObject.fromObject(result); |
| | | return resultJSON.optJSONObject("response").optJSONObject("body").optString("openId"); |
| | | JSONObject response = resultJSON.optJSONObject("response"); |
| | | if (StringUtil.isNullOrEmpty(response.optString("error_code"))) |
| | | return response.optJSONObject("body").optString("openId"); |
| | | return null; |
| | | } |
| | | |
| | | |
| | | public static void getVIPPriceList() { |
| | | Map<String, String> params = new HashMap<>(); |
| | | String result = baseRequest("https://coapi.pptv.com/coapi-web/api/http/sopRequest", params, "pptv.channel.goods.associator"); |
| | | System.out.println(result); |
| | | } |
| | | |
| | | |
| | |
| | | * |
| | | * @param code |
| | | */ |
| | | public static void login(String code) { |
| | | public static boolean login(String code) { |
| | | String url = String.format("https://coapi.pptv.com/coapi-web/api/getUserToken/%s/%s.htm", APP_KEY, code); |
| | | String result = HttpUtil.get(url); |
| | | |
| | | System.out.println(result); |
| | | // JSONObject resultJSON = JSONObject.fromObject(result); |
| | | // return resultJSON.optJSONObject("response").optJSONObject("body").optString("openId"); |
| | | JSONObject resultJSON = JSONObject.fromObject(result); |
| | | return resultJSON.optInt("errCode") == 1; |
| | | } |
| | | |
| | | |
| | | /** |
| | | * 买商品 |
| | | * |
| | | * @param openId |
| | | * @param orderNo |
| | | * @param goodsNo |
| | | * @param orderTime |
| | | * @return |
| | | */ |
| | | public static boolean buyGoods(String openId, String orderNo, String goodsNo, Date orderTime) { |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("openId", openId); |
| | | params.put("canal", CANAL); |
| | | params.put("channel", "yeshi"); |
| | | params.put("goodsNo", goodsNo); |
| | | params.put("outOrderId", orderNo); |
| | | params.put("orderTime", TimeUtil.getGernalTime(orderTime.getTime(), "yyyy-MM-dd HH:mm:ss")); |
| | | params.put("sign", StringUtil.Md5(String.format("%s&%s&%s&%s", openId, params.get("channel"), orderNo, "2MnD8nCWu7EzbiJ"))); |
| | | String result = get("http://uc.test.pptv.com/cusp/jointMember", params); |
| | | System.out.println(result); |
| | | JSONObject data = JSONObject.fromObject(result); |
| | | if (data.optInt("errorCode") == 0) { |
| | | return true; |
| | | } |
| | | return false; |
| | | } |
| | | |
| | | private static String get(String url, Map<String, String> params) { |
| | | List<String> list = new ArrayList<>(); |
| | | for (Iterator<String> its = params.keySet().iterator(); its.hasNext(); ) { |
| | | String key = its.next(); |
| | | list.add(key + "=" + URLEncoder.encode(params.get(key))); |
| | | } |
| | | url += "?" + org.yeshi.utils.StringUtil.concat(list, "&"); |
| | | System.out.println(url); |
| | | return HttpUtil.get(url); |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | buyGoods("257dfd950c20ad25dee9f99ef926c0f8", "buwan_27", "DA7559531560894", new Date()); |
| | | } |
| | | |
| | | |
| | |
| | | package com.yeshi.buwan.pptv; |
| | | |
| | | import com.yeshi.buwan.domain.user.LoginUserExtra; |
| | | import com.yeshi.buwan.domain.vip.VIPOrderRecord; |
| | | import com.yeshi.buwan.domain.vip.VIPPrice; |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | import com.yeshi.buwan.service.inter.LoginUserService; |
| | | import com.yeshi.buwan.service.inter.vip.VIPPriceService; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import org.springframework.stereotype.Component; |
| | | |
| | | import javax.annotation.Resource; |
| | | |
| | | /** |
| | | * PPTV会员 |
| | |
| | | @Component |
| | | public class PPTVVipManager { |
| | | |
| | | @Resource |
| | | private VIPPriceService vipPriceService; |
| | | |
| | | @Resource |
| | | private LoginUserService loginUserService; |
| | | |
| | | /** |
| | | * 购买VIP |
| | | * @param record |
| | | * @throws PPTVException |
| | | * @throws VIPException |
| | | */ |
| | | public void buyVIP() { |
| | | public void buyVIP(VIPOrderRecord record) throws PPTVException, VIPException { |
| | | if (record.getState() != VIPOrderRecord.STATE_PAY) { |
| | | throw new VIPException(11, "尚未支付成功"); |
| | | } |
| | | VIPPrice price = vipPriceService.selectByType(record.getType()); |
| | | if (price == null) { |
| | | throw new VIPException(12, "无法获取价格套餐"); |
| | | } |
| | | |
| | | LoginUserExtra extra = loginUserService.getExtra(record.getUid()); |
| | | if (extra == null) { |
| | | throw new VIPException(13, "用户信息获取失败"); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(extra.getPptvUid())) { |
| | | throw new VIPException(14, "pptvuid获取失败"); |
| | | } |
| | | |
| | | if (StringUtil.isNullOrEmpty(extra.getPptvOpenId())) { |
| | | loginUserService.updatePPTVOpenId(record.getUid()); |
| | | } |
| | | |
| | | boolean success = PPTVApiUtil.buyGoods(extra.getPptvOpenId(), "buwan_" + record.getId(), price.getPptvGoodsNo(), record.getPayTime()); |
| | | if (!success) { |
| | | throw new VIPException(21, "PPTV会员购买失败"); |
| | | } |
| | | } |
| | | |
| | | |
| | |
| | | } |
| | | |
| | | @Id |
| | | private Long videoId; |
| | | private String videoId; |
| | | private String infoId; |
| | | private Date createTime; |
| | | |
| | | public Long getVideoId() { |
| | | public String getVideoId() { |
| | | return videoId; |
| | | } |
| | | |
| | | public void setVideoId(Long videoId) { |
| | | public void setVideoId(String videoId) { |
| | | this.videoId = videoId; |
| | | } |
| | | |
| | |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | import com.yeshi.buwan.domain.user.LoginUserExtra; |
| | | import com.yeshi.buwan.exception.LoginUserException; |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | import com.yeshi.buwan.pptv.PPTVApiUtil; |
| | | import com.yeshi.buwan.pptv.PPTVUtil; |
| | | import com.yeshi.buwan.service.inter.LoginUserService; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.StringUtil; |
| | | import org.yeshi.utils.entity.wx.WeiXinUser; |
| | | |
| | | import javax.annotation.Resource; |
| | |
| | | public void updateSelectiveByPrimaryKey(LoginUserExtra extra) { |
| | | loginUserExtraDao.updateSelective(extra); |
| | | } |
| | | |
| | | @Override |
| | | public String updatePPTVOpenId(String uid) throws PPTVException { |
| | | LoginUserExtra extra = getExtra(uid); |
| | | if (extra == null) { |
| | | extra = initExtra(uid); |
| | | } |
| | | String code = PPTVUtil.getPPTVCode(extra.getPptvUid()); |
| | | |
| | | boolean login = PPTVApiUtil.login(code); |
| | | if (!login) { |
| | | throw new PPTVException(101, "登录失败"); |
| | | } |
| | | |
| | | String openId = PPTVApiUtil.getOpenId(extra.getPptvUid()); |
| | | if (StringUtil.isNullOrEmpty(openId)) { |
| | | throw new PPTVException(102, "openId获取失败"); |
| | | } |
| | | LoginUserExtra update=new LoginUserExtra(); |
| | | update.setId(uid); |
| | | update.setPptvOpenId(openId); |
| | | updateSelectiveByPrimaryKey(update); |
| | | return openId; |
| | | } |
| | | } |
| | |
| | | return videoInfoDao.find(VideoInfo.class, id); |
| | | } |
| | | |
| | | |
| | | public List<VideoInfo> getVideoInfoList(List<String> ids) { |
| | | if (ids == null || ids.size() == 0) |
| | | return null; |
| | | List<VideoInfo> list = videoInfoDao.listByVideoIds(ids); |
| | | Map<String, VideoInfo> map = new HashMap<>(); |
| | | for (VideoInfo vi : list) { |
| | | map.put(vi.getId(), vi); |
| | | } |
| | | list.clear(); |
| | | for (String id : ids) { |
| | | list.add(map.get(id)); |
| | | } |
| | | return list; |
| | | } |
| | | |
| | | public List<VideoInfo> getVideoListByClass(int type, int page) { |
| | | String types[] = classServcie.getChildrenType(type); |
| | | String wheres = ""; |
| | |
| | | //加入映射 |
| | | VideoPPTVMap vi = new VideoPPTVMap(); |
| | | vi.setInfoId(series.getInfoID()); |
| | | vi.setVideoId(Long.parseLong(newVideoInfo.getId())); |
| | | vi.setVideoId(newVideoInfo.getId()); |
| | | vi.setCreateTime(new Date()); |
| | | videoPPTVMapDao.save(vi); |
| | | } |
| | |
| | | programList.addAll(tempList); |
| | | } |
| | | } |
| | | Comparator<PPTVProgram> comparator = new Comparator<PPTVProgram>() { |
| | | @Override |
| | | public int compare(PPTVProgram o1, PPTVProgram o2) { |
| | | return o1.getRank() - o2.getRank(); |
| | | } |
| | | }; |
| | | Collections.sort(programList, comparator); |
| | | |
| | | series.setSeries(programList); |
| | | return series; |
| | | } |
New file |
| | |
| | | package com.yeshi.buwan.service.imp.video; |
| | | |
| | | import com.yeshi.buwan.dao.video.VideoWatchHistoryDao; |
| | | import com.yeshi.buwan.domain.video.VideoWatchHistory; |
| | | import com.yeshi.buwan.service.inter.video.VideoWatchHistoryService; |
| | | import org.springframework.data.annotation.Transient; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @Service |
| | | public class VideoWatchHistoryServiceImpl implements VideoWatchHistoryService { |
| | | @Resource |
| | | private VideoWatchHistoryDao videoWatchHistoryDao; |
| | | |
| | | @Override |
| | | public void add(VideoWatchHistory history) { |
| | | if (history.getId() == null) { |
| | | history.setId(VideoWatchHistory.createId(history.getDevice(), history.getVideoId())); |
| | | } |
| | | history.setCreateTime(new Date()); |
| | | videoWatchHistoryDao.save(history); |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void delete(List<String> ids) { |
| | | if (ids == null) |
| | | return; |
| | | for (String id : ids) |
| | | videoWatchHistoryDao.delete(id); |
| | | } |
| | | |
| | | @Override |
| | | public long countHistory(String device) { |
| | | return videoWatchHistoryDao.count(device); |
| | | } |
| | | |
| | | @Override |
| | | public List<VideoWatchHistory> listHistory(String device, int page, int pageSize) { |
| | | return videoWatchHistoryDao.list(device, (page - 1) * pageSize, pageSize); |
| | | } |
| | | } |
| | |
| | | |
| | | import com.yeshi.buwan.dao.vip.VIPPriceDao; |
| | | import com.yeshi.buwan.domain.vip.VIPPrice; |
| | | import com.yeshi.buwan.domain.vip.VIPPriceType; |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | import com.yeshi.buwan.service.inter.vip.VIPPriceService; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | |
| | | return vipPriceDao.get(id); |
| | | } |
| | | |
| | | @Override |
| | | public VIPPrice selectByType(VIPPriceType type) { |
| | | return vipPriceDao.selectByType(type); |
| | | } |
| | | |
| | | } |
| | |
| | | package com.yeshi.buwan.service.imp.vip; |
| | | |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.alipay.api.response.AlipayTradeQueryResponse; |
| | | import com.yeshi.buwan.dao.vip.UserVIPInfoDao; |
| | | import com.yeshi.buwan.dao.vip.VIPOrderRecordDao; |
| | | import com.yeshi.buwan.domain.vip.UserVIPInfo; |
| | | import com.yeshi.buwan.domain.vip.VIPOrderRecord; |
| | | import com.yeshi.buwan.domain.vip.VIPPriceType; |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | import com.yeshi.buwan.pptv.PPTVVipManager; |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | | import org.hibernate.HibernateException; |
| | | import com.yeshi.buwan.util.user.VipUtil; |
| | | import com.yeshi.buwan.util.vip.VIPOrderUtil; |
| | | import org.hibernate.LockMode; |
| | | import org.hibernate.Query; |
| | | import org.hibernate.Session; |
| | | import org.springframework.orm.hibernate4.HibernateCallback; |
| | | import org.springframework.stereotype.Service; |
| | | import org.springframework.transaction.annotation.Transactional; |
| | | import org.yeshi.utils.alipay.AlipayH5PayUtil; |
| | | import org.yeshi.utils.entity.wx.WXPayOrderInfoV3; |
| | | import org.yeshi.utils.wx.WXPayV3Util; |
| | | |
| | | import javax.annotation.Resource; |
| | | import java.io.Serializable; |
| | | import java.math.BigDecimal; |
| | | import java.math.RoundingMode; |
| | | import java.util.Calendar; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | |
| | | |
| | | @Resource |
| | | private UserVIPInfoDao userVIPInfoDao; |
| | | |
| | | @Resource |
| | | private PPTVVipManager pptvVipManager; |
| | | |
| | | |
| | | /** |
| | |
| | | */ |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public void paySuccess(final String id, int payWay, BigDecimal payMoney, Date payTime) throws VIPException { |
| | | VIPException exception = (VIPException) vipOrderRecordDao.excute(new HibernateCallback() { |
| | | @Override |
| | | public VIPException doInHibernate(Session session) throws HibernateException { |
| | | public VIPOrderRecord paySuccess(final String id, int payWay, BigDecimal payMoney, Date payTime) throws VIPException, PPTVException { |
| | | |
| | | Session session = vipOrderRecordDao.getSession(); |
| | | |
| | | //修改记录 |
| | | Query query = session.createQuery("from VIPOrderRecord as r where r.id=? ").setParameter(0, id); |
| | | query.setLockMode("r", LockMode.UPGRADE); |
| | | List<VIPOrderRecord> list = query.list(); |
| | | |
| | | if (list != null && list.size() > 0) { |
| | | if (list.get(0).getState() == VIPOrderRecord.STATE_PAY) |
| | | return new VIPException(1, "订单已经支付"); |
| | | VIPOrderRecord record = list.get(0); |
| | | if (record.getState() == VIPOrderRecord.STATE_PAY) |
| | | throw new VIPException(1, "订单已经支付"); |
| | | |
| | | Date[] expireDate = addExpireTime(session, list.get(0).getUid(), payTime, list.get(0).getType()); |
| | | |
| | | record.setPayWay(payWay); |
| | | record.setPayMoney(payMoney); |
| | | record.setPayTime(payTime); |
| | | record.setUpdateTime(new Date()); |
| | | |
| | | record.setState(VIPOrderRecord.STATE_PAY); |
| | | |
| | | |
| | | Date[] expireDate = addExpireTime(session, record.getUid(), payTime, record.getType()); |
| | | if (expireDate == null) { |
| | | return new VIPException(2, "添加用户会员时间出错"); |
| | | throw new VIPException(2, "添加用户会员时间出错"); |
| | | } |
| | | session.createQuery("update VIPOrderRecord r set r.payWay=?,r.payMoney=?,r.payTime=?,r.updateTime=?,r.vipStartTime=?,r.vipEndTime=?,r.state=? where r.id=? ") |
| | | .setParameter(0, payWay) |
| | | .setParameter(1, payMoney) |
| | | .setParameter(2, payTime) |
| | | .setParameter(3, new Date()) |
| | | .setParameter(4, expireDate[0]) |
| | | .setParameter(5, expireDate[1]) |
| | | .setParameter(6, VIPOrderRecord.STATE_PAY) |
| | | .setParameter(7, id).executeUpdate(); |
| | | } else { |
| | | return new VIPException(10, "订单不存在"); |
| | | } |
| | | return null; |
| | | } |
| | | }); |
| | | |
| | | if (exception != null) |
| | | throw exception; |
| | | record.setVipStartTime(expireDate[0]); |
| | | record.setVipEndTime(expireDate[1]); |
| | | |
| | | session.update(record); |
| | | //购买VIP |
| | | pptvVipManager.buyVIP(record); |
| | | return record; |
| | | } else { |
| | | throw new VIPException(10, "订单不存在"); |
| | | } |
| | | |
| | | |
| | | } |
| | | |
| | | /** |
| | |
| | | query.state = state; |
| | | return vipOrderRecordDao.count(query); |
| | | } |
| | | |
| | | @Transactional(rollbackFor = Exception.class) |
| | | @Override |
| | | public VIPOrderRecord checkOrderPayState(String id) { |
| | | VIPOrderRecord record = vipOrderRecordDao.find(VIPOrderRecord.class, id); |
| | | if (record.getState() == VIPOrderRecord.STATE_PAY) |
| | | return record; |
| | | |
| | | switch (record.getPayWay()) { |
| | | case VIPOrderRecord.PAY_WAY_ALIPAY: { |
| | | //支付宝 |
| | | AlipayTradeQueryResponse res = null; |
| | | try { |
| | | res = AlipayH5PayUtil.queryOrder(VipUtil.getAlipayApp(), VIPOrderUtil.getOutOrderNo(id), null); |
| | | //支付成功 |
| | | if (res.isSuccess() && "TRADE_SUCCESS".equalsIgnoreCase(res.getTradeStatus())) { |
| | | try { |
| | | return paySuccess(id, VIPOrderRecord.PAY_WAY_ALIPAY, new BigDecimal(res.getTotalAmount()), new Date()); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | } catch (AlipayApiException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | break; |
| | | case VIPOrderRecord.PAY_WAY_WX: { |
| | | //微信 |
| | | try { |
| | | WXPayOrderInfoV3 info = WXPayV3Util.getPayOrderInfo(VIPOrderUtil.getOutOrderNo(id), VipUtil.getWXAPP()); |
| | | if (info != null && info.getTrade_state().equalsIgnoreCase("SUCCESS")) { |
| | | paySuccess(id, record.getPayWay(), new BigDecimal(info.getAmount().getPayer_total()).divide(new BigDecimal(100), 2, RoundingMode.FLOOR), new Date()); |
| | | return record; |
| | | } |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | break; |
| | | } |
| | | return record; |
| | | |
| | | } |
| | | |
| | | @Override |
| | | public VIPOrderRecord getOrderRecord(String id) { |
| | | return vipOrderRecordDao.find(VIPOrderRecord.class, id); |
| | | } |
| | | |
| | | @Transactional |
| | | @Override |
| | | public void initUserVipInfo(String loginUid) { |
| | | Session session = userVIPInfoDao.getSession(); |
| | | UserVIPInfo userVIPInfo = (UserVIPInfo) session.get(UserVIPInfo.class, loginUid); |
| | | if (userVIPInfo == null) { |
| | | userVIPInfo = new UserVIPInfo(); |
| | | userVIPInfo.setUid(loginUid); |
| | | userVIPInfo.setCreateTime(new Date()); |
| | | userVIPInfoDao.save(userVIPInfo); |
| | | } |
| | | } |
| | | } |
| | |
| | | import com.yeshi.buwan.domain.user.LoginUser; |
| | | import com.yeshi.buwan.domain.user.LoginUserExtra; |
| | | import com.yeshi.buwan.exception.LoginUserException; |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | import org.yeshi.utils.entity.wx.WeiXinUser; |
| | | |
| | | public interface LoginUserService { |
| | |
| | | */ |
| | | public void updateSelectiveByPrimaryKey(LoginUserExtra extra); |
| | | |
| | | |
| | | /** |
| | | * 更新PPTV的openId |
| | | * @param uid |
| | | * @return |
| | | */ |
| | | public String updatePPTVOpenId(String uid) throws PPTVException; |
| | | |
| | | } |
New file |
| | |
| | | package com.yeshi.buwan.service.inter.video; |
| | | |
| | | import com.yeshi.buwan.domain.video.VideoWatchHistory; |
| | | |
| | | import java.util.List; |
| | | |
| | | public interface VideoWatchHistoryService { |
| | | |
| | | public void add(VideoWatchHistory history); |
| | | |
| | | |
| | | public void delete(List<String> ids); |
| | | |
| | | public long countHistory(String device); |
| | | |
| | | public List<VideoWatchHistory> listHistory(String device, int page, int pageSize); |
| | | |
| | | |
| | | } |
| | |
| | | package com.yeshi.buwan.service.inter.vip; |
| | | |
| | | import com.yeshi.buwan.domain.vip.VIPPrice; |
| | | import com.yeshi.buwan.domain.vip.VIPPriceType; |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | |
| | | import java.util.List; |
| | |
| | | public VIPPrice selectByPrimaryKey(String id); |
| | | |
| | | |
| | | /** |
| | | * 根据类型查询 |
| | | * |
| | | * @param type |
| | | * @return |
| | | */ |
| | | public VIPPrice selectByType(VIPPriceType type); |
| | | |
| | | |
| | | } |
| | |
| | | |
| | | import com.yeshi.buwan.domain.vip.UserVIPInfo; |
| | | import com.yeshi.buwan.domain.vip.VIPOrderRecord; |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | |
| | | import java.math.BigDecimal; |
| | |
| | | * @param payTime |
| | | * @throws VIPException |
| | | */ |
| | | public void paySuccess(String id, int payWay, BigDecimal payMoney, Date payTime) throws VIPException; |
| | | public VIPOrderRecord paySuccess(String id, int payWay, BigDecimal payMoney, Date payTime) throws VIPException, PPTVException; |
| | | |
| | | |
| | | /** |
| | |
| | | public long countOrderRecord(String uid, Integer state); |
| | | |
| | | |
| | | /** |
| | | * 检测支付状态 |
| | | * |
| | | * @param id |
| | | */ |
| | | public VIPOrderRecord checkOrderPayState(String id); |
| | | |
| | | |
| | | public VIPOrderRecord getOrderRecord(String id); |
| | | |
| | | public void initUserVipInfo(String loginUid); |
| | | |
| | | |
| | | } |
| | |
| | | @Entity |
| | | public class Constant { |
| | | |
| | | public final static String HOST="http://cb.ysdq.yeshitv.com"; |
| | | |
| | | public final static String PHONE_BIND_PREFIX = "phone_login_code_"; |
| | | |
| | | public static boolean isUpdate = false;// 是否在上传应用市场; |
| | |
| | | import java.io.IOException; |
| | | import java.io.OutputStream; |
| | | import java.io.UnsupportedEncodingException; |
| | | import java.lang.reflect.Type; |
| | | import java.security.MessageDigest; |
| | | import java.security.NoSuchAlgorithmException; |
| | | import java.text.DateFormat; |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | import java.util.regex.Matcher; |
| | | import java.util.regex.Pattern; |
| | |
| | | import javax.persistence.Entity; |
| | | import javax.servlet.http.HttpServletRequest; |
| | | |
| | | import com.google.gson.FieldNamingPolicy; |
| | | import com.google.gson.Gson; |
| | | import com.google.gson.GsonBuilder; |
| | | import com.google.gson.JsonArray; |
| | | import com.google.gson.JsonElement; |
| | | import com.google.gson.JsonObject; |
| | | import com.google.gson.JsonParser; |
| | | import com.google.gson.*; |
| | | |
| | | import com.yeshi.buwan.domain.vip.VIPPriceType; |
| | | import sun.misc.BASE64Decoder; |
| | | import sun.misc.BASE64Encoder; |
| | | |
| | |
| | | return o.toString(); |
| | | } else { |
| | | Gson gson = new GsonBuilder().enableComplexMapKeySerialization().excludeFieldsWithoutExposeAnnotation() |
| | | .setDateFormat(DateFormat.LONG).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 会把字段首字母大写 |
| | | .setDateFormat(DateFormat.LONG).registerTypeAdapter(Date.class, new JsonSerializer<Date>() { |
| | | @Override |
| | | public JsonElement serialize(Date value, Type theType, JsonSerializationContext context) { |
| | | if (value == null) { |
| | | return new JsonPrimitive("0"); |
| | | } else { |
| | | return new JsonPrimitive(value.getTime()); |
| | | } |
| | | } |
| | | }).setFieldNamingPolicy(FieldNamingPolicy.UPPER_CAMEL_CASE)// 会把字段首字母大写 |
| | | .setPrettyPrinting().setVersion(1.0).create(); |
| | | String st = gson.toJson(o); |
| | | return Utils.JsonFilter(st); |
New file |
| | |
| | | package com.yeshi.buwan.util; |
| | | |
| | | import java.util.concurrent.LinkedBlockingQueue; |
| | | import java.util.concurrent.ThreadPoolExecutor; |
| | | import java.util.concurrent.TimeUnit; |
| | | |
| | | public class ThreadUtil { |
| | | |
| | | private static LinkedBlockingQueue<Runnable> queue = new LinkedBlockingQueue<Runnable>(100); |
| | | |
| | | private static ThreadPoolExecutor threadPoolExecutor = new ThreadPoolExecutor(30, 3000, 20, TimeUnit.SECONDS, queue); |
| | | |
| | | static { |
| | | threadPoolExecutor.allowCoreThreadTimeOut(true); |
| | | } |
| | | |
| | | public static void run(Runnable runnable) { |
| | | threadPoolExecutor.execute(runnable); |
| | | } |
| | | } |
New file |
| | |
| | | package com.yeshi.buwan.util.log; |
| | | |
| | | import org.slf4j.Logger; |
| | | import org.slf4j.LoggerFactory; |
| | | |
| | | public class LoggerUtil { |
| | | |
| | | private static Logger vipLogger = LoggerFactory.getLogger("vip"); |
| | | |
| | | public static Logger getVIPLogger() { |
| | | return vipLogger; |
| | | } |
| | | |
| | | } |
| | |
| | | package com.yeshi.buwan.util.user; |
| | | |
| | | import com.alipay.api.AlipayApiException; |
| | | import com.yeshi.buwan.util.Constant; |
| | | import org.apache.commons.io.IOUtils; |
| | | import org.yeshi.utils.alipay.AlipayH5PayUtil; |
| | | import org.yeshi.utils.entity.alipay.AlipayAppInfo; |
| | |
| | | * @param money |
| | | * @return |
| | | */ |
| | | public static String getVipChargeAlipayForm(String orderNo, BigDecimal money) { |
| | | public static String getVipChargeAlipayForm(String id, String orderNo, BigDecimal money) { |
| | | try { |
| | | String goodsTitle = "影视大全会员充值"; |
| | | String returnUrl = "http://vip.ysdq.yeshitv.com"; |
| | | String notifyUrl = "http://api.ysdq.yeshitv.com:8089/BuWan/alipay/pay"; |
| | | String returnUrl = "http://vip.ysdq.yeshitv.com/pay_success.html?id=" + id; |
| | | String notifyUrl = Constant.HOST+ "/BuWan/alipay/pay"; |
| | | AlipayAppInfo appInfo = getAlipayApp(); |
| | | String form = AlipayH5PayUtil.createOrderForm(appInfo, orderNo, money, goodsTitle, returnUrl, notifyUrl); |
| | | return form; |
| | |
| | | * @return |
| | | * @throws Exception |
| | | */ |
| | | public static String createWXOrder(String ip, String orderNo, BigDecimal money, String title) throws Exception { |
| | | public static String createWXOrder(String id, String ip, String orderNo, BigDecimal money, String title) throws Exception { |
| | | WXPlaceOrderParams params = new WXPlaceOrderParams(); |
| | | params.setIp(ip); |
| | | params.setOrderNo(orderNo); |
| | | params.setNotifyUrl("http://api.ysdq.yeshitv.com:8089/BuWan/wx/pay/vip"); |
| | | params.setNotifyUrl( Constant.HOST+ "/BuWan/wx/pay/vip"); |
| | | params.setFee(money); |
| | | params.setBody(title); |
| | | params.setApp(getWXAPP()); |
| | | String payUrl = WXPayV3Util.createH5Order(params, "http://vip.ysdq.yeshitv.com/wx_result.html"); |
| | | String returnUrl = "http://vip.ysdq.yeshitv.com/pay_finish.html?id=" + id; |
| | | String payUrl = WXPayV3Util.createH5Order(params, returnUrl); |
| | | return payUrl; |
| | | } |
| | | |
| | |
| | | |
| | | public final static List<String> iqiyiSpecialNames = Arrays.asList(new String[]{ |
| | | //不参与过滤的词 |
| | | "《卧底》","没关系,是青春啊!","山海情(原声版)" |
| | | "《卧底》","没关系,是青春啊!","山海情(原声版)","我的时代,你的时代" |
| | | }); |
| | | |
| | | |
| | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | |
| | | <!--name表示为哪一个logger指定层级和输出的方式 |
| | | additivity表示叠加祖先的输出方式(默认为true,会叠加),所以com.lxc.o2o以及其子类都会输出在控制台中,因为这个logger继承了root中的appender |
| | | level表示级别大于等于${log.level}的信息才会输出,输出方式为配置的appender, |
| | |
| | | <appender-ref ref="ALIPAY_FILE"></appender-ref> |
| | | </logger> |
| | | |
| | | <appender name="vipAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <file>${log.filePath}/vip/vip.log</file> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
| | | <fileNamePattern>${log.filePath}/vip/vip.%d{yyyy-MM-dd}.log.gz</fileNamePattern> |
| | | <maxHistory>${log.maxHistory}</maxHistory> |
| | | </rollingPolicy> |
| | | <encoder> |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | <filter class="ch.qos.logback.classic.filter.LevelFilter"> |
| | | <level>INFO</level> |
| | | <onMatch>ACCEPT</onMatch> |
| | | <onMismatch>DENY</onMismatch> |
| | | </filter> |
| | | </appender> |
| | | |
| | | <logger name="vip" level="INFO" additivity="true"> |
| | | <appender-ref ref="vipAppender"></appender-ref> |
| | | </logger> |
| | | |
| | | |
| | | |
| | |
| | | </logger> |
| | | |
| | | |
| | | <appender name="vipAppender" class="ch.qos.logback.core.rolling.RollingFileAppender"> |
| | | <file>${log.filePath}/vip/vip.log</file> |
| | | <rollingPolicy class="ch.qos.logback.core.rolling.TimeBasedRollingPolicy"> |
| | | <fileNamePattern>${log.filePath}/vip/vip.%d{yyyy-MM-dd}.log.gz</fileNamePattern> |
| | | <maxHistory>${log.maxHistory}</maxHistory> |
| | | </rollingPolicy> |
| | | <encoder> |
| | | <pattern>${log.pattern}</pattern> |
| | | </encoder> |
| | | <filter class="ch.qos.logback.classic.filter.LevelFilter"> |
| | | <level>INFO</level> |
| | | <onMatch>ACCEPT</onMatch> |
| | | <onMismatch>DENY</onMismatch> |
| | | </filter> |
| | | </appender> |
| | | |
| | | <logger name="vip" level="INFO" additivity="true"> |
| | | <appender-ref ref="vipAppender"></appender-ref> |
| | | </logger> |
| | | |
| | | |
| | | |
| | | |
| | | |
| | |
| | | @Test |
| | | public void test6() { |
| | | try { |
| | | iqiyi2VideoUpdate.updateVideoByPlayerUrl("https://www.iqiyi.com/v_bwlvq0dul8.html?vfrm=pcw_dianshiju&vfrmblk=B&vfrmrst=fcs_2_p1"); |
| | | iqiyi2VideoUpdate.updateVideoByPlayerUrl("https://www.iqiyi.com/v_1wcatt2ykr4.html?vfrm=pcw_dianshiju&vfrmblk=F&vfrmrst=711219_dianshiju_tbrb_image1"); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | |
| | | public void count() { |
| | | // long count = iqiyiAlbum2Dao.countVideoByAid(253120001L); |
| | | // System.out.println(count); |
| | | IqiyiAlbum2 album2 = iqiyiAlbum2Dao.get(1842274140085101L); |
| | | IqiyiAlbum2 album2 = iqiyiAlbum2Dao.get(7974832045751601L); |
| | | iqiyi2Service.addToVideoInfo(album2); |
| | | } |
| | | |
| | |
| | | package com.hxh.spring.test; |
| | | |
| | | import com.yeshi.buwan.exception.PPTVException; |
| | | import com.yeshi.buwan.pptv.PPTVApiUtil; |
| | | import com.yeshi.buwan.pptv.PPTVUtil; |
| | | import com.yeshi.buwan.pptv.entity.PPTVSeries; |
| | | import com.yeshi.buwan.service.inter.LoginUserService; |
| | | import com.yeshi.buwan.service.inter.juhe.PPTVService; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | |
| | | import java.util.List; |
| | | |
| | | |
| | | //@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试 |
| | | //@ContextConfiguration(locations = {"classpath:spring.xml"}) |
| | | //@WebAppConfiguration |
| | | @RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试 |
| | | @ContextConfiguration(locations = {"classpath:spring.xml"}) |
| | | @WebAppConfiguration |
| | | public class PPTVTest { |
| | | |
| | | @Resource |
| | | private PPTVService pptvService; |
| | | |
| | | @Resource |
| | | private LoginUserService loginUserService; |
| | | |
| | | @Test |
| | | public void save() { |
| | |
| | | @Test |
| | | public void getOpenId() { |
| | | //CODE:XefbSM0H8BC9kaEGEjHF2U7wd6Sd9ec1oSUmG1gZDTg= |
| | | PPTVApiUtil.login("XefbSM0H8BC9kaEGEjHF2U7wd6Sd9ec1oSUmG1gZDTg="); |
| | | // PPTVApiUtil.login("XefbSM0H8BC9kaEGEjHF2U7wd6Sd9ec1oSUmG1gZDTg="); |
| | | String pptvUid = PPTVUtil.decryptPPTVCode("XefbSM0H8BC9kaEGEjHF2U7wd6Sd9ec1oSUmG1gZDTg=").pptvUid; |
| | | // String openId = PPTVApiUtil.getOpenId(pptvUid); |
| | | // System.out.println(openId); |
| | | |
| | | PPTVApiUtil.getOpenId("buwan_766693"); |
| | | try { |
| | | loginUserService.updatePPTVOpenId("766693"); |
| | | } catch (PPTVException e) { |
| | | e.printStackTrace(); |
| | | } |
| | | |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void getVIPPriceList() { |
| | | PPTVApiUtil.getVIPPriceList(); |
| | | } |
| | | |
| | | |
| | | @Test |
| | | public void addVideoInfo() { |
| | | PPTVSeries series = pptvService.getSeriesDetail("9847"); |
| | | System.out.println(series); |
| | | } |
| | | |
| | | |
| | |
| | | import com.yeshi.buwan.exception.vip.VIPException; |
| | | import com.yeshi.buwan.service.inter.vip.VIPPriceService; |
| | | import com.yeshi.buwan.service.inter.vip.VIPService; |
| | | import com.yeshi.buwan.util.HttpUtil; |
| | | import org.junit.Test; |
| | | import org.junit.runner.RunWith; |
| | | import org.springframework.test.context.ContextConfiguration; |
| | |
| | | import java.util.Date; |
| | | import java.util.List; |
| | | |
| | | @RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试 |
| | | @ContextConfiguration(locations = {"classpath:spring.xml"}) |
| | | @WebAppConfiguration |
| | | //@RunWith(SpringJUnit4ClassRunner.class) //使用junit4进行测试 |
| | | //@ContextConfiguration(locations = {"classpath:spring.xml"}) |
| | | //@WebAppConfiguration |
| | | public class VIPTest { |
| | | |
| | | @Resource |
| | |
| | | @Test |
| | | public void addVIPPrice() { |
| | | VIPPrice price = new VIPPrice(); |
| | | price.setPrice(new BigDecimal(8)); |
| | | price.setPrice(new BigDecimal("14.8")); |
| | | price.setType(VIPPriceType.month); |
| | | price.setPptvGoodsNo("DA7559531560894"); |
| | | price.setShow(true); |
| | |
| | | } |
| | | |
| | | price = new VIPPrice(); |
| | | price.setPrice(new BigDecimal(24)); |
| | | price.setPrice(new BigDecimal("37.8")); |
| | | price.setType(VIPPriceType.season); |
| | | price.setPptvGoodsNo("DA7559574625089"); |
| | | price.setShow(true); |
| | |
| | | |
| | | |
| | | price = new VIPPrice(); |
| | | price.setPrice(new BigDecimal(45)); |
| | | price.setPrice(new BigDecimal("68.8")); |
| | | price.setType(VIPPriceType.halfYear); |
| | | price.setPptvGoodsNo("DA6989580247516"); |
| | | price.setShow(true); |
| | |
| | | |
| | | |
| | | price = new VIPPrice(); |
| | | price.setPrice(new BigDecimal(88)); |
| | | price.setPrice(new BigDecimal("128.8")); |
| | | price.setType(VIPPriceType.year); |
| | | price.setPptvGoodsNo("DA8129574268091"); |
| | | price.setShow(true); |
| | |
| | | @Test |
| | | public void paySuccess() { |
| | | try { |
| | | vipService.paySuccess("2", VIPOrderRecord.PAY_WAY_ALIPAY, new BigDecimal("2.99"), new Date()); |
| | | } catch (VIPException e) { |
| | | vipService.checkOrderPayState(23 + ""); |
| | | } catch (Exception e) { |
| | | e.printStackTrace(); |
| | | } |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | for (int i = 0; i < 20; i++) { |
| | | final int p=i; |
| | | new Thread(new Runnable() { |
| | | @Override |
| | | public void run() { |
| | | HttpUtil.get("http://192.168.3.122:8080/BuWan/test/vipPay?id=27"); |
| | | System.out.println("执行完成:"+p); |
| | | } |
| | | }).start(); |
| | | } |
| | | } |
| | | |
| | | |
| | | } |