| | |
| | | package com.yeshi.buwan.pptv; |
| | | |
| | | import com.google.gson.Gson; |
| | | import com.yeshi.buwan.pptv.entity.PPTVGoodsInfo; |
| | | import com.yeshi.buwan.pptv.entity.PPTVProgram; |
| | | import com.yeshi.buwan.pptv.entity.PPTVSeries; |
| | | import com.yeshi.buwan.util.StringUtil; |
| | | import com.yeshi.buwan.util.TimeUtil; |
| | | import com.yeshi.buwan.util.log.LoggerUtil; |
| | | import net.sf.json.JSONArray; |
| | | import net.sf.json.JSONObject; |
| | | import org.apache.commons.httpclient.HttpClient; |
| | |
| | | import org.slf4j.LoggerFactory; |
| | | import org.yeshi.utils.HttpUtil; |
| | | |
| | | import java.lang.reflect.Field; |
| | | import java.net.URLEncoder; |
| | | import java.util.*; |
| | | |
| | |
| | | } |
| | | |
| | | public static PPTVSeries getDetail(String seriesCodes) { |
| | | Gson gson = new Gson(); |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("seriesCodes", seriesCodes); |
| | | String result = baseRequest(params, "pptv.channel.content.detail"); |
| | | System.out.println(result); |
| | | return null; |
| | | JSONObject resultJSON = JSONObject.fromObject(result); |
| | | JSONArray array = resultJSON.optJSONObject("response").optJSONObject("body").optJSONArray("contentInfos"); |
| | | List<PPTVProgram> programList = new ArrayList<>(); |
| | | PPTVSeries pptvSeries = null; |
| | | for (int i = 0; i < array.size(); i++) { |
| | | JSONObject item = array.optJSONObject(i); |
| | | if (pptvSeries == null) |
| | | pptvSeries = gson.fromJson(item.toString(), PPTVSeries.class); |
| | | |
| | | PPTVGoodsInfo goodsInfo = new PPTVGoodsInfo(); |
| | | goodsInfo.setGoodsNo(item.optString("goodsNo")); |
| | | goodsInfo.setGoodsName(item.optString("goodsName")); |
| | | goodsInfo.setStatus(item.optString("goodsStatus")); |
| | | goodsInfo.setIsNoVipPricing(item.optString("isNoVipPricing")); |
| | | goodsInfo.setIsTicket(item.optString("isTicket")); |
| | | goodsInfo.setIsVipPricing(item.optString("isVipPricing")); |
| | | |
| | | pptvSeries.setGoodsInfo(goodsInfo); |
| | | |
| | | |
| | | List<String> keys = new ArrayList<>(); |
| | | for (Iterator<String> its = item.keys(); its.hasNext(); ) { |
| | | String key = its.next(); |
| | | if (!key.contains("series_")) { |
| | | keys.add(key); |
| | | } |
| | | } |
| | | |
| | | for (String key : keys) { |
| | | item.remove(key); |
| | | } |
| | | |
| | | String itemStr = item.toString().replace("series_", ""); |
| | | |
| | | JSONObject pitem = JSONObject.fromObject(itemStr); |
| | | goodsInfo = new PPTVGoodsInfo(); |
| | | goodsInfo.setGoodsNo(pitem.optString("goodsNo")); |
| | | goodsInfo.setGoodsName(pitem.optString("goodsName")); |
| | | goodsInfo.setStatus(pitem.optString("goodsStatus")); |
| | | goodsInfo.setIsNoVipPricing(pitem.optString("isNoVipPricing")); |
| | | goodsInfo.setIsTicket(pitem.optString("isTicket")); |
| | | goodsInfo.setIsVipPricing(pitem.optString("isVipPricing")); |
| | | |
| | | PPTVProgram program = gson.fromJson(itemStr, PPTVProgram.class); |
| | | program.setGoodsInfo(goodsInfo); |
| | | programList.add(program); |
| | | } |
| | | pptvSeries.setSeries(programList); |
| | | return pptvSeries; |
| | | } |
| | | |
| | | |
| | |
| | | public static String getOpenId(String uid) { |
| | | Map<String, String> params = new HashMap<>(); |
| | | params.put("uid", uid); |
| | | // String result = baseRequest("https://coapi.pptv.com/coapi-web/api/http/sopRequest", params, "pptv.channel.openid.get"); |
| | | 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); |
| | |
| | | * @param 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 url = String.format("https://coapi.pptv.com/coapi-web/api/getUserToken/%s/%s.htm", APP_KEY, URLEncoder.encode(code)); |
| | | String result = HttpUtil.get(url); |
| | | System.out.println(result); |
| | | JSONObject resultJSON = JSONObject.fromObject(result); |
| | |
| | | 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("canal", CHANNEL_ID); |
| | | 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); |
| | | String result = get("http://billing.api.pptv.com/cusp/jointMember", params); |
| | | LoggerUtil.getVIPLogger().info("开通会员-订单号:{},结果:{}", orderNo, result); |
| | | System.out.println(result); |
| | | JSONObject data = JSONObject.fromObject(result); |
| | | if (data.optInt("errorCode") == 0) { |
| | |
| | | } |
| | | |
| | | public static void main(String[] args) { |
| | | buyGoods("257dfd950c20ad25dee9f99ef926c0f8", "buwan_27", "DA7559531560894", new Date()); |
| | | //DA7559531560894 |
| | | buyGoods("257dfd950c20ad25dee9f99ef926c0f8", "buwan_100", "DA7559531560894", new Date()); |
| | | } |
| | | |
| | | |