From 4011b8d0b377af33e2bc435f7726329630d706cb Mon Sep 17 00:00:00 2001 From: admin <weikou2014> Date: 星期二, 02 三月 2021 18:28:52 +0800 Subject: [PATCH] 搜索引擎接口更新 --- src/main/java/com/yeshi/buwan/pptv/PPTVApiUtil.java | 91 +++++++++++++++++++++++++++++++++++++-------- 1 files changed, 75 insertions(+), 16 deletions(-) diff --git a/src/main/java/com/yeshi/buwan/pptv/PPTVApiUtil.java b/src/main/java/com/yeshi/buwan/pptv/PPTVApiUtil.java index d45970e..15c3b01 100644 --- a/src/main/java/com/yeshi/buwan/pptv/PPTVApiUtil.java +++ b/src/main/java/com/yeshi/buwan/pptv/PPTVApiUtil.java @@ -1,27 +1,34 @@ package com.yeshi.buwan.pptv; import com.google.gson.Gson; -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 net.sf.json.JSONArray; import net.sf.json.JSONObject; import org.apache.commons.httpclient.HttpClient; -import org.apache.commons.httpclient.NameValuePair; import org.apache.commons.httpclient.methods.PostMethod; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import org.yeshi.utils.HttpUtil; +import java.net.URLEncoder; import java.util.*; public class PPTVApiUtil { static Logger logger = LoggerFactory.getLogger(PPTVApiUtil.class); - private final static String APP_KEY = "eb324ec4439e193c38fd8d7fdbdae9af"; - private final static String APP_SECRET = "163cf4fa3780091e61a48c6abb6246d3"; - private final static String CHANNEL_ID = "111111"; + //姝e紡 + public final static String APP_KEY = "9227024a6c540a7f8571d75c469da9ba"; + private final static String APP_SECRET = "f3e922ac18f9da6c816d3012f8b7e575"; + + //娴嬭瘯 +// private final static String APP_KEY = "eb324ec4439e193c38fd8d7fdbdae9af"; +// private final static String APP_SECRET = "163cf4fa3780091e61a48c6abb6246d3"; + + + public final static String CHANNEL_ID = "253350"; + private final static String CANAL = "buwan"; private static String getBase64(String str) { String st = StringUtil.getBase64(str).replace("\r\n", ""); @@ -110,7 +117,7 @@ } private static List<PPTVSeries> getList(String method) { - String result = baseRequest(null, method); + String result = baseRequest(new HashMap<>(), method); logger.error(result); List<String> list = parseUrls(result); List<PPTVSeries> totalList = new ArrayList<>(); @@ -153,10 +160,21 @@ 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"); - logger.info(result); +// String result = baseRequest("https://coapi.pptv.com/coapi-web/api/http/sopRequest", params, "pptv.channel.openid.get"); + String result = baseRequest("http://coapiwebsit.cnsuning.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); } @@ -165,15 +183,56 @@ * * @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); - Map<String, String> params = new HashMap<>(); - params.put("code", code); - String result = baseRequest(url, params, ""); - logger.info(result); + String result = HttpUtil.get(url); + System.out.println(result); + JSONObject resultJSON = JSONObject.fromObject(result); + return resultJSON.optInt("errCode") == 1; + } -// JSONObject resultJSON = JSONObject.fromObject(result); -// return resultJSON.optJSONObject("response").optJSONObject("body").optString("openId"); + + /** + * 涔板晢鍝� + * + * @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", 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://billing.api.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) { + //DA7559531560894 + buyGoods("257dfd950c20ad25dee9f99ef926c0f8", "buwan_100", "DA7559531560894", new Date()); } -- Gitblit v1.8.0