|
|
@@ -0,0 +1,506 @@
|
|
|
+package com.kxs.lhb.basic.biz;
|
|
|
+
|
|
|
+import cn.hutool.core.collection.ListUtil;
|
|
|
+import cn.hutool.core.lang.UUID;
|
|
|
+import cn.hutool.core.util.IdUtil;
|
|
|
+import cn.hutool.core.util.StrUtil;
|
|
|
+import cn.hutool.json.JSONObject;
|
|
|
+import cn.hutool.json.JSONUtil;
|
|
|
+import com.kxs.lhb.basic.biz.channel.yiwang.utils.AESUtil;
|
|
|
+import com.kxs.lhb.basic.biz.channel.yiwang.utils.RSAUtil;
|
|
|
+import lombok.extern.slf4j.Slf4j;
|
|
|
+import okhttp3.*;
|
|
|
+import org.junit.jupiter.api.Test;
|
|
|
+import org.springframework.beans.factory.annotation.Autowired;
|
|
|
+import org.springframework.boot.test.context.SpringBootTest;
|
|
|
+
|
|
|
+import javax.net.ssl.*;
|
|
|
+import java.io.IOException;
|
|
|
+import java.security.KeyManagementException;
|
|
|
+import java.security.NoSuchAlgorithmException;
|
|
|
+import java.security.SecureRandom;
|
|
|
+import java.security.cert.X509Certificate;
|
|
|
+import java.util.ArrayList;
|
|
|
+import java.util.HashMap;
|
|
|
+import java.util.List;
|
|
|
+import java.util.Map;
|
|
|
+import java.util.concurrent.TimeUnit;
|
|
|
+
|
|
|
+@SpringBootTest
|
|
|
+@Slf4j
|
|
|
+public class testApi {
|
|
|
+
|
|
|
+
|
|
|
+ public static OkHttpClient okHttpClient;
|
|
|
+
|
|
|
+ static {
|
|
|
+ X509TrustManager xtm = new X509TrustManager() {
|
|
|
+ @Override
|
|
|
+ public void checkClientTrusted(X509Certificate[] chain, String authType) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public void checkServerTrusted(X509Certificate[] chain, String authType) {
|
|
|
+ }
|
|
|
+
|
|
|
+ @Override
|
|
|
+ public X509Certificate[] getAcceptedIssuers() {
|
|
|
+ X509Certificate[] x509Certificates = new X509Certificate[0];
|
|
|
+ return x509Certificates;
|
|
|
+ }
|
|
|
+ };
|
|
|
+
|
|
|
+ SSLContext sslContext = null;
|
|
|
+ try {
|
|
|
+ sslContext = SSLContext.getInstance("SSL");
|
|
|
+
|
|
|
+ sslContext.init(null, new TrustManager[]{xtm}, new SecureRandom());
|
|
|
+
|
|
|
+ } catch (NoSuchAlgorithmException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ } catch (KeyManagementException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ HostnameVerifier DO_NOT_VERIFY = new HostnameVerifier() {
|
|
|
+ @Override
|
|
|
+ public boolean verify(String hostname, SSLSession session) {
|
|
|
+ return true;
|
|
|
+ }
|
|
|
+ };
|
|
|
+ ConnectionPool connectionPool = new ConnectionPool(50, 60, TimeUnit.SECONDS);
|
|
|
+ okHttpClient = new OkHttpClient.Builder()
|
|
|
+ .connectTimeout(5, TimeUnit.SECONDS)
|
|
|
+ .readTimeout(30, TimeUnit.SECONDS)
|
|
|
+ .connectionPool(connectionPool)
|
|
|
+ .sslSocketFactory(sslContext.getSocketFactory(),xtm)
|
|
|
+ .hostnameVerifier(DO_NOT_VERIFY)
|
|
|
+ .build();
|
|
|
+ }
|
|
|
+ // public static final String BASE ="http://localhost:8801/504590";
|
|
|
+// public static final String BASE ="http://192.168.96.103:8802/test-api/504590";
|
|
|
+ public static final String BASE ="https://iotcentral.hunancatv.com:8081/yiwang-api/000002";
|
|
|
+ public static final String URL = BASE+"/gd/openapi";
|
|
|
+ public static final String URL_FORMAT = "{}{}?token={}";
|
|
|
+ public static final String TOKEN_URL = BASE+"/gd/oauth";
|
|
|
+ public static final String APP_ID = "1925005501249015809";
|
|
|
+ public static final String APP_CODE = "1FJRZ3IvTEwSTtoEpfXbrho52yvpiUuS"; // key==>'appCode'
|
|
|
+ public static final String APP_SECRET = "gsPO6vM8jys2PQDSeLmlRUYGbrqnMORh";
|
|
|
+ public static final String PUBLIC = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC+vES9ukCwHBJBhz5iPH+CZPyi43pwI9LCfDoWIq5kipP7aD5zcJSWVGA7994v/DpaX3Hy9CqsJWyCILlxUHnTxeMHtMYJqiHbKozJ1oGvBM3Cb++5XHh1Pn7wfwO57PY1iRFjfWEiSJetOxnA+NTLOje1JkXuQJ9m0Yh0xcwcQQIDAQAB";
|
|
|
+ public static String TOKEN ;
|
|
|
+ private final static String apiCode_number = "/fenxiao/prov/openAcount/qryNumberNew";
|
|
|
+
|
|
|
+ private final static String apiCode_goods = "/fenxiao/prov/openAcount/qryGoodsListByType";
|
|
|
+
|
|
|
+ private final static String apiCode_numSelOccupy = "/fenxiao/prov/openAcount/numSelOccupy";
|
|
|
+
|
|
|
+ private final static String apiCode_online = "/fenxiao/prov/openAcount/onlineCreateUserCheck";
|
|
|
+
|
|
|
+ private final static String apiCode_address = "/fenxiao/prov/openAcount/validateAddress";
|
|
|
+
|
|
|
+ private final static String apiCode_order = "/fenxiao/prov/openAcount/submitOrder";
|
|
|
+
|
|
|
+ private final static String apiCode_preCheck = "/fenxiao/prov/openAcount/submitPreCheck";
|
|
|
+
|
|
|
+ private final static String apiCode_returnOrder = "/fenxiao/prov/openAcount/returnOrder";
|
|
|
+
|
|
|
+ private final static String apiCode_qryOrderDetail = "/fenxiao/prov/openAcount/qryOrderDetail";
|
|
|
+
|
|
|
+ private final static String apiCode_qryNumberOwnership = "/fenxiao/prov/openAcount/qryNumberOwnership";
|
|
|
+
|
|
|
+ private final static String apiCode_qryorderLogistics = "/fenxiao/prov/openAcount/qryorderLogistics";
|
|
|
+ private final static String apiCode_firstCharge = "/fenxiao/prov/openAcount/queryFirstRecharge";
|
|
|
+
|
|
|
+ private final static String apiCode_qryOrderDetailBatch = "/fenxiao/prov/openAcount/qryOrderDetailBatch";
|
|
|
+
|
|
|
+ private final static String apiCode_chargeLevel = "/fenxiao/prov/openAcount/queryMarketRechargeLevelByOfferCode";
|
|
|
+ private final static String apiCode_uploadImgForOnline = "/fenxiao/prov/openAcount/uploadImgForOnline";
|
|
|
+
|
|
|
+ private final static String CUST_NAME= "名字";
|
|
|
+ private final static String CUST_IDEN = "身份证";
|
|
|
+ private final static String CUST_PHONE = "手机号";
|
|
|
+ private final static String CUST_REGIONID = "910731";
|
|
|
+
|
|
|
+ private final static String CUST_ADDRESS = "开福区望麓园街道蔡锷北路138号2楼";
|
|
|
+ private final static String CUST_SHENG = "HN00";
|
|
|
+ private final static String CUST_QU = "48938";
|
|
|
+
|
|
|
+ private final static String PHONE = "19209204109";
|
|
|
+
|
|
|
+ private final static String GOODS_ID = "916d9793f48c4168bdccd80e10e0dad6";
|
|
|
+ private final static String GOODS_SKU_ID ="d05e1b97a4884545b41e725aafc36b84";
|
|
|
+ private final static String OFFER_CODE =null;
|
|
|
+ // private final static String OFFER_CODE = "10003906";
|
|
|
+ private final static String OFFER_NAME ="正龙卡(促销)";
|
|
|
+
|
|
|
+ private final static String ORDER_ID = "P20250711111135554170";
|
|
|
+ private final static String USER_ID = "12398792023923231212446";
|
|
|
+ public static void main(String[] args) {
|
|
|
+ //3.1.1Token生成接口
|
|
|
+ TOKEN = refreshToken();
|
|
|
+// TOKEN = "72e4f083-a0a6-4767-a1a5-f7d71fd056b4";
|
|
|
+ //地址查询接口接口
|
|
|
+// refreshAreaInfo();
|
|
|
+
|
|
|
+ //号码查询接口
|
|
|
+ numbers();
|
|
|
+
|
|
|
+ //选套餐接口
|
|
|
+// packages();
|
|
|
+ //一证五号校验接口
|
|
|
+// online();
|
|
|
+ //地址校验接口
|
|
|
+// checkAddr();
|
|
|
+
|
|
|
+ //号码选占接口
|
|
|
+// preNumber();
|
|
|
+
|
|
|
+
|
|
|
+ //开户下单预校验接口
|
|
|
+// preCheck();
|
|
|
+ //订单提交接口(开户)TODO
|
|
|
+
|
|
|
+// submitOrder();
|
|
|
+
|
|
|
+
|
|
|
+ //订单状态同步获取接口
|
|
|
+// queryStatus();
|
|
|
+ //分销充值返还档次查询接口
|
|
|
+// queryChargeLevel();
|
|
|
+ // 取消订单接口
|
|
|
+// cancelOrder();
|
|
|
+ //物流详情查询接口
|
|
|
+// queryLogistics();
|
|
|
+ //首充结果查询接口
|
|
|
+// queryFirstCharge();
|
|
|
+ //订单状态批量同步获取接口
|
|
|
+// batchQuery();
|
|
|
+ // 一证通、社保/居住证文件上传接口(下单号码地市为深圳时使用
|
|
|
+// uploadImgForOnline();
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void submitOrder() {
|
|
|
+ String submitOrderUrl = StrUtil.format(URL_FORMAT,URL,apiCode_order,TOKEN);
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ params.put("seqId", IdUtil.fastSimpleUUID());
|
|
|
+// 不用 params.put("orderType", "15");
|
|
|
+// 不用 params.put("channelId","SHENGFEN");
|
|
|
+// params.put("orgId","orgId");//todo 这个是省份代理商
|
|
|
+// 不用 params.put("channelType", "6");
|
|
|
+// 不用 params.put("channelCode", "EB002");
|
|
|
+ params.put("areaName", "长沙市");
|
|
|
+ params.put("areaCode", CUST_REGIONID);
|
|
|
+ params.put("regionCode",CUST_QU);
|
|
|
+ params.put("provinceCode",CUST_SHENG);
|
|
|
+
|
|
|
+ params.put("cityCode",CUST_REGIONID);
|
|
|
+ params.put("cityName","长沙市");
|
|
|
+ params.put("phone", PHONE);
|
|
|
+// 不用 params.put("payWay","9");
|
|
|
+// 不用 params.put("userIdType","1");
|
|
|
+ params.put("userId",USER_ID);
|
|
|
+ params.put("payMoney","30000");
|
|
|
+ params.put("sendWay","1");
|
|
|
+ params.put("orderRemark","我是备注");
|
|
|
+ Map<String,Object> goods = new HashMap<>();
|
|
|
+ goods.put("goodsId",GOODS_ID);
|
|
|
+ goods.put("goodsSkuId",GOODS_SKU_ID);
|
|
|
+// goods.put("goodsTypeId","C01");
|
|
|
+ goods.put("orderNum","1");
|
|
|
+ List<Map<String,Object>> offerList = new ArrayList<>();
|
|
|
+ Map<String,Object> codes = new HashMap<>();
|
|
|
+ if(StrUtil.isNotBlank(OFFER_CODE)){
|
|
|
+ codes.put("offerCode",OFFER_CODE);
|
|
|
+ offerList.add(codes);
|
|
|
+ }
|
|
|
+// if(!offerList.isEmpty()){
|
|
|
+ goods.put("offerList",offerList);
|
|
|
+// }
|
|
|
+
|
|
|
+
|
|
|
+ params.put("goodsParams",goods);
|
|
|
+
|
|
|
+ Map<String,Object> orderRecvAddr = new HashMap<>();
|
|
|
+ orderRecvAddr.put("receiveName",CUST_NAME);
|
|
|
+ orderRecvAddr.put("receiveCountry","中国");
|
|
|
+ orderRecvAddr.put("receiveProvince",CUST_SHENG);
|
|
|
+ orderRecvAddr.put("receiveProvinceName","湖南省");
|
|
|
+ orderRecvAddr.put("receiveCity",CUST_REGIONID);
|
|
|
+ orderRecvAddr.put("receiveCityName","长沙市");
|
|
|
+ orderRecvAddr.put("receiveCounty", CUST_QU);
|
|
|
+ orderRecvAddr.put("receiveCountyName","开福区");
|
|
|
+ orderRecvAddr.put("receiveAddress",CUST_ADDRESS);
|
|
|
+ orderRecvAddr.put("receiveMobile",CUST_PHONE);
|
|
|
+ params.put("orderRecvAddr",orderRecvAddr);
|
|
|
+
|
|
|
+ Map<String,Object> custInfo = new HashMap<>();
|
|
|
+ custInfo.put("custName",CUST_NAME);
|
|
|
+ custInfo.put("idenType","1");
|
|
|
+ custInfo.put("idenNr",CUST_IDEN);
|
|
|
+ custInfo.put("contNumber",CUST_PHONE);
|
|
|
+ params.put("custInfo",custInfo);
|
|
|
+
|
|
|
+ params.put("outOrderId",IdUtil.fastSimpleUUID());
|
|
|
+
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), submitOrderUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void uploadImgForOnline(){
|
|
|
+ String uploadImgUrl = StrUtil.format(URL_FORMAT,URL,apiCode_uploadImgForOnline,TOKEN);
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+// 不需要 params.put("busiSence", "10");
|
|
|
+// 不需要 params.put("idenType", "1");
|
|
|
+ params.put("idenNr", CUST_IDEN);
|
|
|
+ params.put("imgType", "1006");//照片类型: 1006:社保/居住证 1007:一证通查截图
|
|
|
+ params.put("img", "iVBORw0KGgoAAAANSUhEUgAAAAEAAAABCAQAAAC1HAwCAAAAC0lEQVR42mNkYAAAAAYAAjCB0C8AAAAASUVORK5CYII==");
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), uploadImgUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+ public static void batchQuery(){
|
|
|
+ String batchUrl = StrUtil.format(URL_FORMAT,URL,apiCode_qryOrderDetailBatch,TOKEN);
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ params.put("orderIdLists", ListUtil.of(ORDER_ID));
|
|
|
+ params.put("phoneLists", ListUtil.of(PHONE));
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), batchUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void queryLogistics(){
|
|
|
+ String logisticsUrl = StrUtil.format(URL_FORMAT,URL,apiCode_qryorderLogistics,TOKEN);
|
|
|
+ Map<String,String> params = new HashMap<>();
|
|
|
+ params.put("orderId",ORDER_ID);
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), logisticsUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void queryFirstCharge(){
|
|
|
+ String firstChargeUrl = StrUtil.format(URL_FORMAT,URL,apiCode_firstCharge,TOKEN);
|
|
|
+ Map<String,String> params = new HashMap<>();
|
|
|
+ params.put("phoneNumber",PHONE);
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), firstChargeUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+ public static void queryChargeLevel(){
|
|
|
+ String chargeLevelUrl = StrUtil.format(URL_FORMAT,URL,apiCode_chargeLevel,TOKEN);
|
|
|
+ Map<String,String> params = new HashMap<>();
|
|
|
+ params.put("phone",PHONE);
|
|
|
+ params.put("offerCode",OFFER_CODE);
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), chargeLevelUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void queryStatus() {
|
|
|
+ String queryUrl = StrUtil.format(URL_FORMAT,URL,apiCode_qryOrderDetail,TOKEN);
|
|
|
+
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ params.put("orderId",ORDER_ID);
|
|
|
+ params.put("phone",CUST_PHONE);
|
|
|
+ params.put("userId",USER_ID);
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), queryUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void cancelOrder(){
|
|
|
+ String cancelUrl = StrUtil.format(URL_FORMAT,URL,apiCode_returnOrder,TOKEN);
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ // 不要 params.put("chnlCode","EB002");
|
|
|
+ params.put("returnCauseType","0");
|
|
|
+ params.put("orderId",ORDER_ID);
|
|
|
+ params.put("applyPerson","XXXX");
|
|
|
+ params.put("returnCause","YYYYYY");
|
|
|
+// 不要 params.put("returnChnl",config.getAppCode());
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), cancelUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ public static void preCheck() {
|
|
|
+ String preCheckUrl = StrUtil.format(URL_FORMAT,URL,apiCode_preCheck,TOKEN);
|
|
|
+ String userId = UUID.fastUUID().toString(true);
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+// 不要 params.put("orderType", "15");
|
|
|
+ params.put("areaCode", CUST_REGIONID);
|
|
|
+ params.put("provinceCode",CUST_SHENG);
|
|
|
+ params.put("phone", PHONE);
|
|
|
+// 不要 params.put("userIdType","1");
|
|
|
+ params.put("userId",userId);
|
|
|
+ Map<String,Object> goods = new HashMap<>();
|
|
|
+ goods.put("orderNum","1");
|
|
|
+ goods.put("goodsId",GOODS_ID);
|
|
|
+ goods.put("goodsSkuId",GOODS_SKU_ID);
|
|
|
+ List<Map<String,Object>> offerList = new ArrayList<>();
|
|
|
+ Map<String,Object> codes = new HashMap<>();
|
|
|
+ if(StrUtil.isNotBlank(OFFER_CODE)){
|
|
|
+ codes.put("offerCode",OFFER_CODE);
|
|
|
+ codes.put("offerName",OFFER_NAME);
|
|
|
+ offerList.add(codes);
|
|
|
+ }
|
|
|
+// if(!offerList.isEmpty()){
|
|
|
+ goods.put("offerList",offerList);
|
|
|
+// }
|
|
|
+
|
|
|
+ params.put("goodsParams",goods);
|
|
|
+ Map<String,Object> orderRecvAddr = new HashMap<>();
|
|
|
+ orderRecvAddr.put("receiveName",CUST_NAME);
|
|
|
+ orderRecvAddr.put("receiveCountry","中国");
|
|
|
+ orderRecvAddr.put("receiveProvince",CUST_SHENG);
|
|
|
+ orderRecvAddr.put("receiveProvinceName","湖南省");
|
|
|
+ orderRecvAddr.put("receiveCity",CUST_REGIONID);
|
|
|
+ orderRecvAddr.put("receiveCityName","长沙市");
|
|
|
+
|
|
|
+ orderRecvAddr.put("receiveCounty",CUST_QU);
|
|
|
+ orderRecvAddr.put("receiveCountyName","开福区");
|
|
|
+
|
|
|
+ orderRecvAddr.put("receiveAddress",CUST_ADDRESS);
|
|
|
+ orderRecvAddr.put("receiveMobile",CUST_PHONE);
|
|
|
+ params.put("orderRecvAddr",orderRecvAddr);
|
|
|
+ Map<String,Object> custInfo = new HashMap<>();
|
|
|
+ custInfo.put("custName",CUST_NAME);
|
|
|
+ custInfo.put("idenType","1");
|
|
|
+ custInfo.put("idenNr",CUST_IDEN);
|
|
|
+
|
|
|
+
|
|
|
+ params.put("custInfo",custInfo);
|
|
|
+ params.put("seqId", IdUtil.fastSimpleUUID());
|
|
|
+ params.put("payMoney","30000");
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), preCheckUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void online() {
|
|
|
+ String onlineUrl = StrUtil.format(URL_FORMAT,URL,apiCode_online,TOKEN);
|
|
|
+
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+// 不要 params.put("idenType","1");
|
|
|
+ params.put("custName",CUST_NAME);
|
|
|
+ params.put("idenNr",CUST_IDEN);
|
|
|
+ params.put("regionId",CUST_REGIONID);
|
|
|
+// 不要 params.put("channelType","1");
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), onlineUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void checkAddr() {
|
|
|
+ String addressUrl = StrUtil.format(URL_FORMAT,URL,apiCode_address,TOKEN);
|
|
|
+
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ params.put("receiveProvince",CUST_SHENG);
|
|
|
+ params.put("receiveCity",CUST_REGIONID);
|
|
|
+ params.put("receiveCounty",null);
|
|
|
+ params.put("receiveAddress",CUST_ADDRESS);
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), addressUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+ public static void preNumber() {
|
|
|
+ String preNumberUrl = StrUtil.format(URL_FORMAT,URL,apiCode_numSelOccupy,TOKEN);
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ params.put("accessNum",PHONE);
|
|
|
+// 不要 params.put("occupyType","1");
|
|
|
+// 不要 params.put("idenType","1");
|
|
|
+ params.put("custCardNo",CUST_IDEN);
|
|
|
+ params.put("regionId",CUST_REGIONID);
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), preNumberUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void packages() {
|
|
|
+ String packageUrl = StrUtil.format(URL_FORMAT,URL,apiCode_goods,TOKEN);
|
|
|
+ Map<String,String> params = new HashMap<>();
|
|
|
+ params.put("typeId","C01");
|
|
|
+ params.put("areaCode",CUST_SHENG);
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), packageUrl);
|
|
|
+ log.info("调用获取接口json:{}",json);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void numbers() {
|
|
|
+ String numbersUrl = StrUtil.format(URL_FORMAT,URL,apiCode_number,TOKEN);
|
|
|
+ Map<String,Object> params = new HashMap<>();
|
|
|
+ params.put("regionId",CUST_REGIONID);
|
|
|
+ params.put("fuzzyTag","2");
|
|
|
+ params.put("fuzzyKey","109");
|
|
|
+ params.put("currentPage","1");
|
|
|
+ params.put("pageSize","20");
|
|
|
+ params.put("beautifulTag","0");
|
|
|
+ JSONObject json = guangdian(JSONUtil.toJsonStr(params), numbersUrl);
|
|
|
+ log.info("调用获取号码接口json:{}",json);
|
|
|
+
|
|
|
+
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+ public static void refreshAreaInfo(){
|
|
|
+ String areaUrl = StrUtil.format(URL_FORMAT,URL,apiCode_qryNumberOwnership,TOKEN);
|
|
|
+ guangdian("{}", areaUrl);
|
|
|
+ }
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+
|
|
|
+ /**
|
|
|
+ * 获取token
|
|
|
+ */
|
|
|
+ private static String refreshToken(){
|
|
|
+ HttpUrl.Builder urlBuilder =HttpUrl.parse(TOKEN_URL)
|
|
|
+ .newBuilder();
|
|
|
+ urlBuilder.addQueryParameter("username",APP_ID);
|
|
|
+ urlBuilder.addQueryParameter("password",APP_SECRET);
|
|
|
+ //改成OKHTTP形式
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(urlBuilder.build())
|
|
|
+ .get()
|
|
|
+ .build();
|
|
|
+ okhttp3.Call call = okHttpClient.newCall(request);
|
|
|
+ String json = null;
|
|
|
+ try {
|
|
|
+ json = call.execute().body().string();
|
|
|
+ } catch (IOException e) {
|
|
|
+ e.printStackTrace();
|
|
|
+ }
|
|
|
+ JSONObject object= JSONUtil.parseObj(json);
|
|
|
+ System.out.println(object);
|
|
|
+ return object.getStr("token");
|
|
|
+ }
|
|
|
+
|
|
|
+ private static JSONObject guangdian(String jsonBody, String apiUrl) {
|
|
|
+ String random = RSAUtil.getRandom();
|
|
|
+ Map<String,String> obj = new HashMap<>();
|
|
|
+ String s = AESUtil.enAES(jsonBody, random + random + random);
|
|
|
+ obj.put("requestParams", s);
|
|
|
+ String ajaxran = null;
|
|
|
+ try {
|
|
|
+ ajaxran = RSAUtil.encryptByPublicKey(random, PUBLIC);
|
|
|
+ } catch (Exception e) {
|
|
|
+ throw new RuntimeException("加密失败");
|
|
|
+ }
|
|
|
+ //修改为okhhtp
|
|
|
+ okhttp3.RequestBody body = okhttp3.RequestBody.create(JSONUtil.toJsonStr(obj), MediaType.parse("application/json; charset=utf-8"));
|
|
|
+ Request request = new Request.Builder()
|
|
|
+ .url(apiUrl)
|
|
|
+ .head()
|
|
|
+ .addHeader("ajaxrandomcode", ajaxran)
|
|
|
+ .addHeader("publicKey", PUBLIC)
|
|
|
+ .addHeader("CRC", APP_ID)
|
|
|
+ .addHeader("appCode", APP_CODE)
|
|
|
+ .addHeader("ostype", "android")
|
|
|
+ .post(body)
|
|
|
+ .build();
|
|
|
+ okhttp3.Call call = okHttpClient.newCall(request);
|
|
|
+ try (Response response = call.execute()){
|
|
|
+ String json = response.body().string();
|
|
|
+ log.info("调用接口{} {},{}",apiUrl,jsonBody,json);
|
|
|
+ return JSONUtil.parseObj(json);
|
|
|
+ } catch (Exception e) {
|
|
|
+ log.error("广电访问出错",e);
|
|
|
+ }
|
|
|
+ return null;
|
|
|
+ }
|
|
|
+}
|