package com.chinacreator.video.restful.util;

import java.io.BufferedReader;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileReader;
import java.io.InputStreamReader;
import java.io.UnsupportedEncodingException;
import java.net.URLDecoder;
import java.net.URLEncoder;
import java.security.MessageDigest;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Calendar;
import java.util.Date;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.TreeMap;
import java.util.UUID;

import org.apache.commons.codec.digest.DigestUtils;
import org.apache.commons.lang.StringUtils;
import org.apache.commons.lang.time.DateFormatUtils;
import org.springframework.http.HttpRequest;

import com.chinacreator.video.bean.OrderInfo;
import com.chinacreator.video.restful.bean.ShangHaiObject;
import com.chinacreator.video.util.AESUtil;
import com.chinacreator.video.util.DesUtil;
import com.chinacreator.video.util.MD5;
import com.chinacreator.video.util.URLUtil;
import com.fasterxml.jackson.databind.ObjectMapper;
import com.n3.ecs.open.util.HMACUtil;
import com.n3.ecs.open.util.SignUtil;
import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONArray;
import com.alibaba.fastjson.JSONObject;

public class PseudoCode {
    /**
     * 相关表
     * 1. TB_DONTINVOKE_CONFIG 调接口配置表
     * 2. TB_CHANNEL_ORG 渠道配置表，有密码字段
     * 3. TB_CP_ACCOUNT_CONFIG 账号配置，有密码字段
     * 4. TB_UNIFIEDLIMIT_CONFIG IP限制表
     * 5. TB_UNIFIEDINVOKE_CONFIG 统一接口权限表
     * 6. TB_DICTIONRY_INFO 字典表
     * 7. TB_BLACKWHITE_LIST 白名单表
     * 8. TB_DONTINVOKE_CONFIG 免调ecb/vac接口配置表
     *
     * @throws Exception
     */
    public static void main(String[] args) throws Exception {
        //System.out.println(5/10);
		/*
		String userid = "UooUmz1MQgSRsKdMZVpGIQ==";
		try {
			userid  = DesUtil.decode(userid, "315b5de2");
			System.out.println(userid);
		} catch (Exception e) {
			e.printStackTrace();
		}
		*/
        //String userid = "17608004026";
        //String pwd = "xgx12345";
        //System.out.println(DesUtil.encode(userid, pwd));
        //PseudoCode.getQryUrl();
        //PseudoCode.getTrafficOrderUrl();
        //PseudoCode.getShangHaiUrl();
        //String url = "http://127.0.0.1:8082/videoif/tcpreOrder.do?orderid=7c193aed3678413da6955cdfea6a3c0e&type=0&access=null&apptype=2&channel=jiangsusf&cpid=gdtencent&spid=115&timestamp=2019-08-06 15:43:11 888&token=null&userid=NReB0BerTnl3cBgvcFM6nQ%3D%3D&signature=74b5f3a147bd5766d97641969c5dba5a";
        //System.out.println(URLUtil.get(url));
        //PseudoCode.ftpFileParse();
        //PseudoCode.getCapReverseUrl();
        //PseudoCode.cp();
        //PseudoCode.cpprople("18673197465","15360","0");
        //PseudoCode.filebilbl();
        //aiqy();
        //youtuvip();
        //getQryQcAuthUrl();
        //getQcOrderUrl();
        //getQryQcResUrl();

        //getCsmakeupUrl();
        //getCshuyuUrl();

        //getVideoOrderHandle();
        //getBackbusiQryUrl();
        //getTenDrawAuthUrl();
        //getTenDrawQryUrl();
        //getTenDrawsendUrl();

        //douyinUrl();

        //flowqryfbyproductid();
        //fullOrderParams();
        //fullCancelParams();
        //usermapp_qrymappid();
        //usermapp_qryuserid();

        //invokeFlowQuery("18673197465","tencent");
        //cpPush();
        //cpPushResSql();

        //getAqy20DrawsendUrl();
        //tw5gSyncUrl();
        ColorsealUrl();

    }

    /**
     * 把赠送结果改为SQL
     *
     * @throws Exception
     */
    public static void cpPushResSql() throws Exception {
        /**
         insert into tl_cdn_flow_cp_alert_log(id,userid,flowcp,alerttype,flow,maxflow,resultcode,resultinfo,inserttime,times,rediskey)
         values (TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS')||SEQ_COMMON.NEXTVAL,'18673197465','youtu','0','0','20240','0','{"resultcode":"0","resultinfo":""}',sysdate,'9999','FLOW_PROPEL_13145571576_youtu')
         */
        try {
            String path = "C:/cppushres";
            File file = new File(path);
            String[] files = file.list();
            String maxflowTotal = "";
            String userid = "";
            String type = "";
            String flowTotal = "";
            String flowcp = "";
            String key = "";
            String resultcode = "";
            String resultinfo = "";
            Map<String, String> data = new HashMap<String, String>();
            for (int i = 0; i < files.length; i++) {
                System.out.println("正在处理【" + i + "】个文件，剩余【" + (files.length - i) + "】");
                System.out.println(files[i]);
                File tmp = new File(path + files[i]);

                BufferedReader br = null;
                String line = null;
                String sql = "insert into tl_cdn_flow_cp_alert_log(id,userid,flowcp,alerttype,flow,maxflow,resultcode,resultinfo,inserttime,times,rediskey) " +
                        " values (TO_CHAR(SYSDATE, 'YYYYMMDDHH24MISS')||SEQ_COMMON.NEXTVAL,";
                String other = "";
                try {
                    FileInputStream is = new FileInputStream(new File(path + "/" + files[i]));
                    br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                    int index = 0;
                    while ((line = br.readLine()) != null) {
                        if (StringUtils.isEmpty(line)) {
                            return;
                        }
                        if (line.contains("###")) {
                            //System.out.println(line);
                            String[] array = line.split("###");
                            JSONObject jsonObj = (JSONObject) JSONObject.parse(array[0]);
                            maxflowTotal = jsonObj.getString("maxflowTotal");
                            userid = jsonObj.getString("userid");
                            type = jsonObj.getString("type");
                            flowTotal = jsonObj.getString("flowTotal");
                            flowcp = jsonObj.getString("flowcp");
                            key = jsonObj.getString("key");
                            resultinfo = array[1];
                            JSONObject resObj = (JSONObject) JSONObject.parse(array[1]);
                            resultcode = resObj.getString("resultcode");
                            //if(data.containsKey(userid+flowcp+type+maxflowTotal)){

                            //}else{
                            //data.put(userid+flowcp+type+maxflowTotal, "1");
                            //other = "'"+userid+"','"+flowcp+"','"+type+"','"+flowTotal+"','"+maxflowTotal+"','"+resultcode+"','"+resultinfo+"',sysdate,'9999','"+key+"');";
                            //System.out.println(sql+other);
                            //index++;
                            //}
                            if (data.containsKey(userid + flowcp)) {

                            } else {
                                data.put(userid + flowcp, "1");
                            }
                        }
                    }
                    //System.out.println(index);
                } finally {
                    if (br != null)
                        try {
                            br.close();
                        } catch (Exception localException) {
                        }
                }
            }
            System.out.println(data.size());
            System.out.println(data.keySet());
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    /**
     * CP推送
     *
     * @throws Exception
     */
    public static void cpPush() throws Exception {
        try {
            String path = "C:/cppushfile";
            File file = new File(path);
            String[] files = file.list();
            String maxflowTotal = "";
            String userid = "";
            String type = "";
            String flowTotal = "";
            String flowcp = "";
            for (int i = 0; i < files.length; i++) {
                System.out.println("正在处理【" + i + "】个文件，剩余【" + (files.length - i) + "】");
                System.out.println(files[i]);
                File tmp = new File(path + files[i]);

                BufferedReader br = null;
                String line = null;
                try {
                    FileInputStream is = new FileInputStream(new File(path + "/" + files[i]));
                    br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
                    int index = 0;
                    while ((line = br.readLine()) != null) {
                        if (StringUtils.isEmpty(line)) {
                            return;
                        }
                        //System.out.println(line);
                        JSONObject jsonObj = (JSONObject) JSONObject.parse(line);
                        maxflowTotal = jsonObj.getString("maxflowTotal");
                        userid = jsonObj.getString("userid");
                        type = jsonObj.getString("type");
                        flowTotal = jsonObj.getString("flowTotal");
                        flowcp = jsonObj.getString("flowcp");
                        if ("0".equals(type)) {
                            String overful = invokeFlowQuery(userid, flowcp);
                            if ("1".equals(overful)) {
                                String res = invokeCpPush(userid, flowcp, maxflowTotal, flowTotal);
                                System.out.println(line + "###" + res);
                            }
                        }
                        //System.out.println();
                        index++;
                    }
                    System.out.println(index);
                } finally {
                    if (br != null)
                        try {
                            br.close();
                        } catch (Exception localException) {
                        }
                }
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * CP推送
     *
     * @throws Exception
     */
    public static String invokeCpPush(String usermob, String flowcp, String maxflow, String flow) {
        String res = "";
        try {
            Map<String, String> cpconf = new HashMap<String, String>();
            cpconf.put("wotv", "沃视频	|https://open.17wo.cn/wovideo/slb/flowAlert/send|ks82xnfo|0");
            cpconf.put("tjgb", "听见广播|http://api.cbct.cn/flowAlert/send|tjgb1234|1");
            cpconf.put("tencent", "腾讯|https://access.video.qq.com/fcgi/send?raw=1&vappid=26130544&vsecret=724a5c9958cf9c26566d38d4131a6528f741f359ccf4be42|tenc1234|1");
            cpconf.put("youtu", "优酷|https://4g.youku.com/wl/unicom/restSync|ks82xnfo|0");

            if (cpconf.get(flowcp) != null) {
                String timestamp = new Date().getTime() / 1000 + "";
                String mobtype = cpconf.get(flowcp).split("\\|")[3];
                String KEY = "ac22273abb2f4960";
                String netpwd = cpconf.get(flowcp).split("\\|")[2];
                String baseurl = cpconf.get(flowcp).split("\\|")[1];
                String userid = usermob.trim();
                if ("1".equals(mobtype)) {
                    userid = AESUtil.encrypt(usermob, KEY);
                }
                userid = DesUtil.encode(userid, netpwd);
                String sign = MD5.MD5Encode(userid + flowcp + timestamp + netpwd);

                userid = URLEncoder.encode(userid, "utf-8");
                if (baseurl.indexOf("?") == -1) {
                    baseurl += "?";
                } else {
                    baseurl += "&";
                }
                String url = baseurl + "userid=" + userid + "&cpid=" + flowcp.trim() + "&maxflow=" + maxflow.trim() + "&flow=" + flow.trim() + "&timestamp=" + timestamp + "&signature=" + sign;
                System.out.println(url);
                res = doHandle(url);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
        return res;
    }

    /**
     * 查询用户流量
     *
     * @param userid
     * @param cpid
     * @throws Exception
     */
    public static String invokeFlowQuery(String userid, String cpid) throws Exception {
        String overful = "";
        /**
         wotv	沃视频	https://open.17wo.cn/wovideo/slb/flowAlert/send	ks82xnfo	0
         tjgb	听见广播	http://api.cbct.cn/flowAlert/send	tjgb1234	1
         tencent	腾讯	https://access.video.qq.com/fcgi/send?raw=1&vappid=26130544&vsecret=724a5c9958cf9c26566d38d4131a6528f741f359ccf4be42	tenc1234	1
         youtu	优酷	https://4g.youku.com/wl/unicom/restSync	ks82xnfo	0
         */
        String key = "ac22273abb2f4960";
        userid = AESUtil.encrypt(userid, key);
        String channel = "cdn";
        String timestamp = (System.currentTimeMillis()) / 1000 + "";
        String pwd = "cdn";
        String signature = MD5.MD5Encode(userid + cpid + channel + timestamp + pwd);
        String baseUrl = "http://111.206.134.43:809/"; //生产环境公网
        String urlflowQuery = "orderFlow/flowQuery";
        String invokeUrl = baseUrl + urlflowQuery + "?userid=" + URLEncoder.encode(userid, "utf-8") + "&cpid=" + cpid + "&channel=" + channel + "&timestamp=" + timestamp + "&signature=" + signature;
        //System.out.println(invokeUrl);
        //System.out.println(doHandle(invokeUrl));
        String res = doHandle(invokeUrl);
        //System.out.println(res);
        if (res != null && !"".equals(res)) {
            JSONObject jsonObj = (JSONObject) JSONObject.parse(res);
            overful = jsonObj.getString("overful");


        }
        //System.out.println(overful);
        return overful;
    }

    /**
     * 手机号码映射
     *
     * @throws Exception
     */
    public static void usermapp_qryuserid() throws Exception {
        String url = "http://172.16.33.16:8084/video-order/usermapp/qryuserid";
        //测试环境
        //url = "http://114.255.201.228:86/video-order/usermapp/qryuserid";
        String pwd = "315b5de2";
        pwd = "#EDC2wsx";
        String account = "237bb20bafee4a5cbb5bedf0c94109f4";
        String channel = "kc";
        channel = "xrbt";
        String timestamp = (System.currentTimeMillis()) / 1000 + "";
        //account = DesUtil.encode(account, pwd);
        String signature = account + channel + timestamp + pwd;
        System.out.println(signature);
        signature = MD5.MD5Encode(signature);
        JSONObject params = new JSONObject();
        params.put("account", account);
        params.put("channel", channel);
        params.put("timestamp", timestamp);
        params.put("signature", signature);
        System.out.println(params.toJSONString());
        invokePostJson(url, params.toJSONString());
    }

    public static void usermapp_qrymappid() throws Exception {
        String url = "http://172.16.33.16:8084/video-order/usermapp/qrymappid";
        //测试环境
        url = "http://114.255.201.228:86/video-order/usermapp/qrymappid";
        String pwd = "315b5de2";
        String account = "18673197465";
        String channel = "kc";
        String timestamp = (System.currentTimeMillis()) / 1000 + "";
        account = DesUtil.encode(account, pwd);
        String signature = account + channel + timestamp + pwd;
        System.out.println(signature);
        signature = MD5.MD5Encode(signature);
        JSONObject params = new JSONObject();
        params.put("account", account);
        params.put("channel", channel);
        params.put("timestamp", timestamp);
        params.put("signature", signature);
        System.out.println(params.toJSONString());
        invokePostJson(url, params.toJSONString());
    }

    public static String fullCancelParams() throws Exception {
        String jsonParams = "";
        HashMap<String, String> params = new HashMap<String, String>();
        String mobile = "18534940378";
        mobile = "15645426238";
        mobile = "13101653062";
        mobile = "13136996281";
        String timestamp = System.currentTimeMillis() + "";
        String spid = "952772590007";
        String cpid = "704454252784779264";
        String userType = "1";
        String password = "wbpJwfGJ";
        mobile = DesUtil.encode(mobile, password); //手机号码加密
        String signature = MD5.MD5Encode(spid + cpid + mobile + timestamp + userType + password);

        JSONObject json = new JSONObject();
        json.put("timestamp", timestamp);
        json.put("signature", signature);
        json.put("spid", spid);
        json.put("cpid", cpid);
        json.put("mobile", mobile);
        json.put("userType", userType);
        JSONObject json2 = new JSONObject();
        json2.put("status", "0");
        json2.put("ordertime", "20200701112023");
        json2.put("canceltime", "20200714231547");
        json2.put("endtime", "20200731235959");
        json.put("data", json2);
        jsonParams = json.toString();
        System.out.println(jsonParams);
        //去除json格式
        jsonParams = jsonParams.replaceAll(":", "=").replaceAll(",", "&")
                .replaceAll("\"", "").replaceAll("\\{", "").replaceAll("\\}", "");
        System.out.println(jsonParams);
        return jsonParams;
    }

    public static String fullOrderParams() throws Exception {
        String jsonParams = "";
        String timestamp = System.currentTimeMillis() + "";
        String mobile = "18689196344";
        mobile = "15692687320";
        mobile = "18534940378";
        String spid = "952772590007";
        String cpid = "704454252784779264";
        String memberUrl = "";
        String orderNumber = "202006302230248072307";
        String password = "wbpJwfGJ";
        mobile = DesUtil.encode(mobile, password); //手机号码加密
        String signature = MD5.MD5Encode(spid + cpid + orderNumber + timestamp + password);

        JSONObject json = new JSONObject();
        JSONArray jsonArray = new JSONArray();
        jsonArray.add(mobile);
        json.put("timestamp", timestamp);
        json.put("signature", signature);
        json.put("spid", spid);
        json.put("cpid", cpid);
        json.put("mobiles", jsonArray);
        json.put("memberUrl", memberUrl);
        json.put("orderNumber", orderNumber);
        jsonParams = json.toString();
        System.out.println(jsonParams);
        return jsonParams;
    }

    public static void flowqryfbyproductid() throws Exception {
        String ss = "{\"productids\":[\"90723706\",\"90776778\"],\"signature\":\"884e68ae9288dfa92116e5f105d47017\",\"channel\":\"kc\",\"userid\":\"UooUmz1MQgSRsKdMZVpGIQ==\",\"timestamp\":\"1592927802\"}";
        JSONObject inputObj = new JSONObject().parseObject(ss);
        System.out.println(inputObj.toJSONString());
        String url = "http://172.16.33.16:8084/video-order/flowlimit/qryfbyproductid";
        String pwd = "315b5de2";
        String userid = "18673197465";
        userid = "18774826258";
        JSONArray productids = new JSONArray();
        //productids.add("90723762");
        //productids.add("90723765");

        productids.add("90723798");

        String channel = "kc";
        String timestamp = (System.currentTimeMillis()) / 1000 + "";
        userid = DesUtil.encode(userid, pwd);
        String signature = userid + productids.toJSONString() + channel + timestamp + pwd;
        System.out.println(signature);
        signature = MD5.MD5Encode(userid + productids.toJSONString() + channel + timestamp + pwd);
        JSONObject params = new JSONObject();
        params.put("userid", userid);
        params.put("productids", productids);
        params.put("channel", channel);
        params.put("timestamp", timestamp);
        params.put("signature", signature);
        System.out.println(params.toJSONString());
        invokePostJson(url, params.toJSONString());
    }

    /**
     * 九楼抖音接口
     *
     * @throws Exception
     */
    public static void douyinUrl() throws Exception {
        String url = "https://800.wo.cn/directional/syncTrafficTo.do";
        List<HashMap<String, String>> apList = new ArrayList<HashMap<String, String>>();
        JSONObject reqJson = new JSONObject();
        HashMap<String, String> apMap = new HashMap<String, String>();
        String data = "{\"SERIAL_NUMBER\":\"13239305161\",\"ELEMENT_ID\":\"8436177\",\"REMAIN\":\"58\",\"KAFKA_TYPE\":\"r\",\"DEAL_TIME\":\"20200429100316\",\"PERCENT\":\"90\",\"EPARCHY_CODE\":\"0930\",\"USER_ID\":\"8718031338922290\",\"ADD_PRODUCT_ID\":\"90274148\",\"USED_VALUE\":\"0.72\",\"PROVINCE_CODE\":\"87\"}";
        data = "{\"SERIAL_NUMBER\":\"17693442036\",\"ELEMENT_ID\":\"8338346\",\"REMAIN\":\"176\",\"KAFKA_TYPE\":\"r\",\"DEAL_TIME\":\"20200514204344\",\"PERCENT\":\"60\",\"EPARCHY_CODE\":\"0931\",\"USER_ID\":\"8717031783376141\",\"ADD_PRODUCT_ID\":\"90063345\",\"USED_VALUE\":\"0.32\",\"PROVINCE_CODE\":\"87\"}";
        data = "[2020/05/14 20:52:29,252] - 3100103,1|||{\"SERIAL_NUMBER\":\"13193998879\",\"ELEMENT_ID\":\"61132841\",\"REMAIN\":\"10180\",\"KAFKA_TYPE\":\"r\",\"DEAL_TIME\":\"20200514205223\",\"PERCENT\":\"50\",\"EPARCHY_CODE\":\"0398\",\"USER_ID\":\"7616011516204465\",\"ADD_PRODUCT_ID\":\"90363851\",\"USED_VALUE\":\"10.06\",\"PROVINCE_CODE\":\"76\"}";
        data = data.split("\\|\\|\\|")[1];
        JSONObject json = JSONObject.parseObject(data);
        String pwd = "dy#@24fL";
        String timestamp = (System.currentTimeMillis()) / 1000 + "";
        String params = DesUtil.encode(data, pwd);
        String signature = MD5.MD5Encode(params + timestamp + pwd);
        reqJson.put("params", params);
        reqJson.put("timestamp", timestamp);
        reqJson.put("signature", signature);
        String jsonStr = reqJson.toJSONString();
        System.out.println("请求参数：" + jsonStr);

        invokePostJson(url, jsonStr);
		
		/*
		JSONObject paramsJson = JSONObject.parseObject(jsonStr);
		String reqparams = paramsJson.getString("params");
		String reqtimestamp = paramsJson.getString("timestamp");
		String reqsignature = paramsJson.getString("signature");
		System.out.println(reqsignature);
		System.out.println(MD5.MD5Encode(reqparams+reqtimestamp+pwd));
		System.out.println("参数解密后："+DesUtil.decode(reqparams, pwd));
		*/
        getQcOrderUrl();

        //JSONObject json2 = new JSONObject();
        //json2.put("params2", reqJson.get("params"));
        //System.out.println(json2.toJSONString());
        //System.out.println(json2.get("params2"));
    }

    //爱奇艺20元抽奖活动
    public static void getAqy20DrawsendUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/tendraw/prizesend";
            //测试环境
            url = "http://114.255.201.228:86/video-order/aqydraw";
            String pwd = "2aqy1gd5";
            //18673197465
            String userid = "18673197465";
            String channel = "aqy20active";
            //String userid = MD5.MD5Encode("18654128342");
            userid = DesUtil.encode(userid, pwd);
            System.out.println(userid + " **************************");
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            String signature = MD5.MD5Encode(userid + channel + timestamp + pwd);
            String jsonParams = "";
            JSONObject json = new JSONObject();

            json.put("userid", userid);
            json.put("spid", "1018");
            json.put("channel", channel);
            json.put("timestamp", timestamp);
            json.put("signature", signature);
            jsonParams = json.toJSONString();
            System.out.println(url);
            System.out.println(jsonParams);
            invokePostJson(url, jsonParams);
//			userid = URLEncoder.encode(userid,"utf-8");
//			String spid = "1018";
//			String username = URLEncoder.encode("测试","utf-8");
//            String address = URLEncoder.encode("测试","utf-8");
//			//System.out.println(userid);
//            url = url + "?userid="+userid+"&spid="+spid+"&username="+username+"&address="+address;
//			System.out.println(url);
//			invoke(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void getTenDrawsendUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/tendraw/prizesend";
            //测试环境
            url = "http://114.255.201.228:86/video-order/tendraw/prizesend";

            String pwd = "kdp59Fje";
            String userid = "18654128342";
            String mappid = "20200424160224000001";
            mappid = "";
            String prizetime = "20200425184021";
            String prizename = "核桃露一箱";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            String signature = MD5.MD5Encode(userid + mappid + prizetime + prizename + timestamp + pwd);
            String jsonParams = "";
            JSONObject json = new JSONObject();
            json.put("userid", userid);
            json.put("mappid", mappid);
            json.put("prizetime", prizetime);
            json.put("prizename", prizename);
            json.put("timestamp", timestamp);
            json.put("signature", signature);
            jsonParams = json.toJSONString();
            //System.out.println(signature);
            //String enUserid = URLEncoder.encode(userid,"utf-8");
            //url = url+"?channel="+channel+"&signature="+signature+"&timestamp="+timestamp+"&userid="+enUserid+"&orderid="+orderid+"&cpid="+cpid+"&spid="+spid+"&type="+type;
            System.out.println(url);
            System.out.println(jsonParams);
            invokePostJson(url, jsonParams);
        } catch (Exception e) {
        }
    }

    /**
     * 腾讯20元活动奖品查询接口
     */
    public static void getTenDrawQryUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/tendraw/prizeqry";
            //测试环境
            url = "http://114.255.201.228:86/video-order/tendraw/prizeqry";

            String pwd = "kdp59Fje";

            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            String signature = MD5.MD5Encode(timestamp + pwd);
            String jsonParams = "";
            JSONObject json = new JSONObject();
            json.put("timestamp", timestamp);
            json.put("signature", signature);
            jsonParams = json.toJSONString();
            //System.out.println(signature);
            //String enUserid = URLEncoder.encode(userid,"utf-8");
            //url = url+"?channel="+channel+"&signature="+signature+"&timestamp="+timestamp+"&userid="+enUserid+"&orderid="+orderid+"&cpid="+cpid+"&spid="+spid+"&type="+type;
            System.out.println(url);
            System.out.println(jsonParams);
            invokePostJson(url, jsonParams);
        } catch (Exception e) {
        }
    }

    /**
     * 腾讯20元活动抽奖资格查询接口
     */
    public static void getTenDrawAuthUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/tendraw/prizeauth";
            //测试环境
            url = "http://114.255.201.228:86/video-order/tendraw/prizeauth";
            String channel = "tendraw";
            String pwd = "kdp59Fje";
            String account = "18673197465";
            //account = "20200424160224000001";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            String type = "0";
            //type = "1";
            String signature = MD5.MD5Encode(account + type + timestamp + pwd);

            String jsonParams = "";
            JSONObject json = new JSONObject();
            json.put("timestamp", timestamp);
            json.put("account", account);
            json.put("type", type);
            json.put("signature", signature);
            jsonParams = json.toJSONString();
            //System.out.println(signature);
            //String enUserid = URLEncoder.encode(userid,"utf-8");
            //url = url+"?channel="+channel+"&signature="+signature+"&timestamp="+timestamp+"&userid="+enUserid+"&orderid="+orderid+"&cpid="+cpid+"&spid="+spid+"&type="+type;
            System.out.println(url);
            System.out.println(jsonParams);
            invokePostJson(url, jsonParams);
        } catch (Exception e) {
        }
    }

    public static void kk(String... s) {
        System.out.println(Arrays.asList(s));
    }


    /**
     * 畅视2元组合产品订购
     */
    public static void getBackbusiQryUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/querybackorder";
            //测试环境
            url = "http://114.255.201.228:86/video-order/querybackorder";
            String channel = "TX20_twback_qc";
            String pwd = "7dea1gd5";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            String orderid = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
            String signature = MD5.MD5Encode(channel + orderid + timestamp + pwd);
            System.out.println(signature);
            url = url + "?channel=" + channel + "&signature=" + signature + "&timestamp=" + timestamp + "&orderid=" + orderid;
            System.out.println(url);
            invoke(url);
        } catch (Exception e) {
        }
    }

    /**
     * 畅视互娱产品订购
     */
    public static void getCshuyuUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/cshuyu";
            //测试环境
            //url = "http://114.255.201.228:86/video-order/cshuyu";
            String channel = "cshyapp";
            channel = "womusic";
            String pwd = "Hml7eUvC";
            pwd = "Mu7eUwo8";
            String userid = "18673197465";
            String cpid = "cshy";
            String spid = "1031";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            userid = DesUtil.encode(userid, pwd);
            String type = "0";
            type = "1";
            String orderid = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
            String signature = MD5.MD5Encode(orderid + cpid + spid + userid + type + channel + timestamp + pwd);

            String jsonParams = "";
            JSONObject json = new JSONObject();
            json.put("timestamp", timestamp);
            json.put("signature", signature);
            json.put("spid", spid);
            json.put("cpid", cpid);
            json.put("userid", userid);
            json.put("channel", channel);
            json.put("orderid", orderid);
            json.put("type", type);
            json.put("signature", signature);
            jsonParams = json.toJSONString();
            //System.out.println(signature);
            //String enUserid = URLEncoder.encode(userid,"utf-8");
            //url = url+"?channel="+channel+"&signature="+signature+"&timestamp="+timestamp+"&userid="+enUserid+"&orderid="+orderid+"&cpid="+cpid+"&spid="+spid+"&type="+type;
            System.out.println(url);
            System.out.println(jsonParams);
            invokePostJson(url, jsonParams);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 畅视2元组合产品订购
     */
    public static void getCsmakeupUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/csmakeup";
            //测试环境
            //url = "http://114.255.201.228:86/video-order/csmakeup";
            String channel = "TX20_twback_qc";
            channel = "TX20_twback";
            String pwd = "7dea1gd5";
            pwd = "7dea1gd5";
            String userid = "18673197465";
            String cpid = "changshi";
            String spid = "CS000002";
            //spid = "CS000001";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            userid = DesUtil.encode(userid, pwd);
            String type = "1";
            String usertype = "1";
            String orderid = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
            String signature = MD5.MD5Encode(orderid + cpid + spid + userid + type + usertype + channel + timestamp + pwd);
            System.out.println(signature);
            String enUserid = URLEncoder.encode(userid, "utf-8");
            url = url + "?channel=" + channel + "&signature=" + signature + "&timestamp=" + timestamp + "&userid=" + enUserid + "&orderid=" + orderid + "&cpid=" + cpid + "&spid=" + spid + "&type=" + type + "&usertype=" + usertype;
            System.out.println(url);
            invoke(url);
        } catch (Exception e) {
        }
    }

    /**
     * 女王卡领取资格查询
     */
    public static void getQryQcResUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/qryQcRes";
            //测试环境
            url = "http://114.255.201.228:86/video-order/qryQcRes";
            String channel = "H5_qcauth";
            String pwd = "qceaFx26";
            //String cpid = "youtu";
            //String spid = "1168";
            String userid = "18673197465";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            userid = DesUtil.encode(userid, pwd);
            String signature = "";
            //signature = MD5.MD5Encode(cpid + spid + userid + channel + timestamp + pwd);
            signature = MD5.MD5Encode(userid + channel + timestamp + pwd);
            String enUserid = URLEncoder.encode(userid, "utf-8");
            //url = url+"?channel="+channel+"&signature="+signature+"&timestamp="+timestamp+"&userid="+enUserid+"&spid="+spid+"&cpid="+cpid;
            url = url + "?channel=" + channel + "&signature=" + signature + "&timestamp=" + timestamp + "&userid=" + enUserid;
            //System.out.println("查询url");
            System.out.println(url);
            invoke(url);
        } catch (Exception e) {
        }
    }

    /**
     * 女王卡订购
     */
    public static void getQcOrderUrl() {
        try {
            /**
             * [2020-03-02 09:20:42.182] - {"userInfo":{"channel":"TX20_twback_old","cpid":"mangtv","orderid":"683966181287133184",
             * "signature":"778c2321189d3017c5be23e922108a63","spid":"173","timestamp":"1583111845","userid":"bIax0qma4hIMDR7Q4MGA+w=="},"forward":"backorder","resultcode":"10006","errorinfo":"签名校验失败"}
             */
            //778c2321189d3017c5be23e922108a63
            //778c2321189d3017c5be23e922108a63
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/backorder";
            //测试环境
            //url = "http://114.255.201.228:86/video-order/backorder";
            //url = "http://114.255.201.221:809/univideo/backorder";
            //本地环境
            url = "http://127.0.0.1:8084/video-order/backorder";
            String channel = "TX20_twback_qc";
            String pwd = "7dea1gd5";
            //pwd = "2wsx#EDC";
            String userid = "18673197465";
            String cpid = "youtu";
            String spid = "1168";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            userid = DesUtil.encode(userid, pwd);
            String orderid = new SimpleDateFormat("yyyyMMddHHmmssSSS").format(new Date());
            //channel = "TX20_twback_old";
            //cpid = "mangtv";
            //spid = "173";
            //timestamp = "1583111845";
            //userid = "bIax0qma4hIMDR7Q4MGA+w==";
            //orderid = "683966181287133184";

            String signature = MD5.MD5Encode(orderid + cpid + spid + userid + channel + timestamp + pwd);
            System.out.println(signature);
            String enUserid = URLEncoder.encode(userid, "utf-8");
            url = url + "?channel=" + channel + "&signature=" + signature + "&timestamp=" + timestamp + "&userid=" + enUserid + "&orderid=" + orderid + "&cpid=" + cpid + "&spid=" + spid;
            System.out.println("后向订购url");
            System.out.println(url);
            invoke(url);
        } catch (Exception e) {
        }
    }

    /**
     * 女王卡领取资格查询
     */
    public static void getQryQcAuthUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/qryQcAuth";
            //测试环境
            url = "http://114.255.201.228:86/video-order/qryQcAuth";
            String channel = "H5_qcauth";
            String pwd = "qceaFx26";
            String userid = "18673197465";
            //userid = "18584347524";
            String cpid = "youtu";
            String spid = "1168";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            //timestamp = "1586852374";
            userid = DesUtil.encode(userid, pwd);
            String signature = "";
            signature = MD5.MD5Encode(cpid + spid + userid + channel + timestamp + pwd);
            String enUserid = URLEncoder.encode(userid, "utf-8");
            url = url + "?channel=" + channel + "&signature=" + signature + "&timestamp=" + timestamp + "&userid=" + enUserid + "&spid=" + spid + "&cpid=" + cpid;
            //System.out.println("查询url");
            System.out.println(url);
            invoke(url);
        } catch (Exception e) {
        }
    }

    public static void youtuvip() {
        try {
            //String url = "http://111.206.135.32:8080/flowlimit/refreshFlowcp?queueName=flowAddPropel&userid=18822040070&flowTotal=160&maxflowTotal=15360&flowcp=youtu&type=1";
            // System.out.println("=========================>"+URLUtil.get(url));

            String path = "C:/youtu";
            File file = new File(path);
            String[] files = file.list();
            for (int i = 0; i < files.length; i++) {
                System.out.println("正在处理【" + i + "】个文件，剩余【" + (files.length - i) + "】");
                System.out.println(files[i]);
                File tmp = new File(path + files[i]);
                parseFileYoutu(null, path + "/" + files[i]);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
    }

    public static void parseFileYoutu(File localFile, String textFileName) throws Exception {
        // System.out.println(textFileName);
        BufferedReader br = null;
        String line = null;
        try {
            FileInputStream is = new FileInputStream(new File(textFileName));
            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            // br = new BufferedReader(new FileReader(localFile));
            int index = 0;
            while ((line = br.readLine()) != null) {
                if (StringUtils.isEmpty(line)) {
                    return;
                }
                sendVip(line);
                index++;
            }
            System.out.println(index);
        } finally {
            if (br != null)
                try {
                    br.close();
                } catch (Exception localException) {
                }
        }
    }

    /**
     * 赠送会员
     *
     * @param
     * @return
     * @throws Exception
     */
    public static void sendVip(String userid) {
        try {
            //测试地址：http://114.255.201.228:86/activity/joinYouku20Vip
            //正式地址：http://114.255.201.238:8090/video-activity/joinYouku20Vip
            String num = userid;
            String vipurl = "http://114.255.201.238:8090/video-activity/joinYouku20Vip";
            String timestamp = (System.currentTimeMillis() / 1000) + "";
            //String userid = (String)reqBean.get("userid");
            String channel = "youtu";
            String activetype = "27";
            String pwd = "ea044e50";
            userid = DesUtil.encode(userid, pwd);
            String signature = MD5.MD5Encode(userid + pwd + timestamp);
            signature = signature.toLowerCase();
            vipurl = vipurl + "?userid=" + URLEncoder.encode(userid, "utf-8") + "&channel=" + channel + "&activetype=" + activetype + "&timestamp="
                    + timestamp + "&signature=" + signature;

            String result = URLUtil.get(vipurl, 10 * 1000); //调赠送会员接口，超时时间设置为10秒
            System.out.println("赠送会员结果=> userid: " + num + " , result: " + result);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static boolean compareDate(String currTime, String endTime) {
        boolean result = false;
        try {
            SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
            Date dateCurrTime = sdf.parse(currTime);
            Date dateEndTime = sdf.parse(endTime);
            int i = dateEndTime.compareTo(dateCurrTime);
            System.out.println("========================" + i);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return result;
    }

    public static SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");

    public static SimpleDateFormat formatter = new SimpleDateFormat("yyyyMMddHHmmssSSS");

    /**
     * 上海2元权益
     */
    public static void getShangHaiUrl() {
/*
{
    "UNI_BSS_HEAD": {
        "APP_ID": "abc", 
        "RESERVED": "", 
        "TIMESTAMP": "2019-07-26 09:35:14 227", 
        "TOKEN": "e934960c50002669e11f94b1070db34f", 
        "TRANS_ID": "20190726093514227610145"
    }, 
    "UNI_BSS_BODY": {
        "ACTIVE_COUPON_NO_REQ": {
            "ACCOUNT_PARAM": {
                "signature": ""
            }, 
            "ID": "20190726093514", 
            "ORDER_TIME": "2019-07-26 09:35:14 575", 
            "PHONE_NUMBER": "18673197465", 
            "TRADE_ID": "e4aec5615e8f42998f97fa951413cabc"
        }
    }, 
    "UNI_BSS_ATTACHED": {
    
     }
}		
 */
        String url = "http://172.16.33.16:8084/video-order/sh/activeCouponNo";
        //url = "http://114.255.201.221:809/univideo/sh/activeCouponNo";
        SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        //APP_IDabcTIMESTAMP2016-04-12 15:06:06 100TRANS_ID20160412150606100335423B2732427
        String app_secret = "B2732427";
        String appid = "abc";
        String timestamp = fm.format(new Date());
        //timestamp = "2019-08-23 16:54:36 004";
        String transid = getRequestId(); //流水号
        //transid = "20190806152242939590414";
        //transid = "20160412150606100335423";
        String reserved = "";
        String token = "";
        String userid = "18673197465"; //充值账号
        //userid = "13162730437";
        String signature = "";
        String channel = "shanghaiqy";
        String cpid = "gdtencent";
        cpid = "changshi";
        String spid = "115";
        spid = "1170";
        String type = "0"; //0：订购   1：退订   2：预订购
        String pwd = "shqy1234";
        pwd = "3edc@WSX";
        Map<String, String> reqParams = new HashMap<String, String>();
        JSONObject reqJson = new JSONObject();
        //JSONObject bodyJson = new JSONObject();
        //JSONObject attachedJson = new JSONObject();

        TreeMap<String, Object> headerMap = new TreeMap<String, Object>();
        TreeMap<String, Object> bodyMap = new TreeMap<String, Object>();
        TreeMap<String, Object> acnrMap = new TreeMap<String, Object>();
        //TreeMap<String, Object> apMap = new TreeMap<String, Object>();
        Map<String, String> apMap = new HashMap<String, String>();
        List<Map> apList = new ArrayList<Map>();
        TreeMap<String, String> attachedMap = new TreeMap<String, String>();
        headerMap.put("APP_ID", appid);
        headerMap.put("TIMESTAMP", timestamp);
        headerMap.put("TRANS_ID", transid);
        token = "APP_ID" + appid + "TIMESTAMP" + timestamp + "TRANS_ID" + transid + app_secret;
        //token = "APP_IDabcTIMESTAMP2016-04-12 15:06:06 100TRANS_ID20160412150606100335423B2732427";
        token = MD5.MD5Encode(token);
        //System.out.println(DigestUtils.md5Hex(token));
        //System.out.println(token);
        headerMap.put("TOKEN", token);
        headerMap.put("RESERVED", reserved);

        reqJson.put("UNI_BSS_HEAD", headerMap);
        //System.out.println(reqJson.toString());

        String tradeid = UUID.randomUUID().toString().replace("-", ""); //订单号
        acnrMap.put("TRADE_ID", tradeid);
        acnrMap.put("ORDER_TIME", fm.format(new Date()));
        acnrMap.put("PHONE_NUMBER", userid);
        acnrMap.put("ID", sdf.format(new Date()));
        //timestamp = (System.currentTimeMillis())/1000+"";
        //Md5(CHANNEL+CPID+SPID+PHONE_NUMBER+TYPE+TIMESTAMP+PWD)

//		timestamp =  "2019-09-03 13:38:11 850";
//		channel = "shanghaiqy";
//		cpid = "gdtencent";
//		spid = "115";
//		userid = "13162730437";
//		type = "0";
//		//pwd = "shqy1234";
//		pwd="3edc@WSX";

        signature = channel + cpid + spid + userid + type + timestamp + pwd;

        //signature = "shanghaiqychangshi11701316273043702019-08-23 16:54:36 296shqy1234";
        System.out.println("signature before=> " + signature);
        signature = MD5.MD5Encode(signature);
        System.out.println("signature after=> " + signature);
        //apMap.put("SIGNATURE", signature);
        //apMap.put("CHANNEL", channel);
        //apMap.put("CPID", cpid);
        //apMap.put("SPID", spid);
        //apMap.put("TYPE", type);
        //List<Map> apList = new ArrayList<Map>();

        apMap = new HashMap<String, String>();
        apMap.put("KEY", "SIGNATURE");
        apMap.put("VALUE", signature);
        apList.add(apMap);
        apMap = new HashMap<String, String>();
        apMap.put("KEY", "CHANNEL");
        apMap.put("VALUE", channel);
        apList.add(apMap);
        apMap = new HashMap<String, String>();
        apMap.put("KEY", "CPID");
        apMap.put("VALUE", cpid);
        apList.add(apMap);
        apMap = new HashMap<String, String>();
        apMap.put("KEY", "SPID");
        apMap.put("VALUE", spid);
        apList.add(apMap);
        apMap = new HashMap<String, String>();
        apMap.put("KEY", "TYPE");
        apMap.put("VALUE", type);
        apList.add(apMap);
        apMap = new HashMap<String, String>();
        apMap.put("KEY", "TIMESTAMP");
        apMap.put("VALUE", timestamp);
        apList.add(apMap);

        acnrMap.put("ACCOUNT_PARAM", apList);
        bodyMap.put("ACTIVE_COUPON_NO_REQ", acnrMap);
        reqJson.put("UNI_BSS_BODY", bodyMap);
        reqJson.put("UNI_BSS_ATTACHED", attachedMap);
        System.out.println(reqJson.toString());
        JSONObject jsonObject = null;
        ShangHaiObject inputObj = jsonObject.parseObject(reqJson.toString(), ShangHaiObject.class);
        JSONArray jSONArray = (JSONArray) inputObj.getUni_bss_body().getJSONObject("ACTIVE_COUPON_NO_REQ").get("ACCOUNT_PARAM");
        JSONObject accountParam = (JSONObject) jSONArray.get(0);
        for (int i = 0; i < jSONArray.size(); i++) {
            Map tmpMap = (Map) jSONArray.get(i);
            //System.out.println(tmpMap);
            //System.out.println(tmpMap.get("KEY"));
            //System.out.println(tmpMap.get("VALUE"));

        }
        //System.out.println(accountParam.get("CHANNEL"));
        //System.out.println(inputObj.getUni_bss_body().getJSONObject("ACTIVE_COUPON_NO_REQ").get("ACCOUNT_PARAM").getClass());
        //JSONObject accountParam = (JSONObject)inputObj.getUni_bss_body().getJSONObject("ACTIVE_COUPON_NO_REQ").get("ACCOUNT_PARAM");
        //JSONObject uniBssHand = inputObj.getUni_bss_head();
        //System.out.println(uniBssHand.get("TIMESTAMP"));
        //System.out.println(accountParam.toJSONString());
        //JSONArray jsonArray = inputObj.getUni_bss_body().getJSONObject("ACTIVE_COUPON_NO_REQ").getJSONArray("ACCOUNT_PARAM");
        //System.out.println(jsonArray.toJSONString());
        //String orderTime = (String)inputObj.getUni_bss_body().getJSONObject("ACTIVE_COUPON_NO_REQ").get("ORDER_TIME");
        //System.out.println("orderTime=>"+orderTime.toString());
        System.out.println(url);
        try {
            System.out.println("开始调接口....");
            System.out.println("返回结果=>" + doHandle(url, reqJson.toString()));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * CAP反向通知
     */
    public static void getCapReverseUrl() {
        String url = "http://172.16.33.16:8084/video-order/cap/reverseOrdering";
        //url = "http://114.255.201.221:809/univideo/cap/reverseOrdering";
        //测试环境
        url = "http://114.255.201.228:86/video-order/cap/reverseOrdering";
        JSONObject reqJson = new JSONObject();

        //填充UNI_BSS_HEAD
        TreeMap<String, Object> headerMap = new TreeMap<String, Object>();
        SimpleDateFormat fm = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss SSS");
        String timestamp = fm.format(new Date());
        String transid = getTransId();
        String appid = "abc";
        String app_secret = "B2732427";
        String token = "APP_ID" + appid + "TIMESTAMP" + timestamp + "TRANS_ID" + transid + app_secret;
        token = encrypt32(token);
        String reserved = "";
        headerMap.put("APP_ID", appid);
        headerMap.put("TIMESTAMP", timestamp);
        headerMap.put("TRANS_ID", transid);
        headerMap.put("TOKEN", token);
        headerMap.put("RESERVED", reserved);
        //reqJson.put("UNI_BSS_HEAD", headerMap);

        //填充UNI_BSS_BODY
        SimpleDateFormat fm2 = new SimpleDateFormat("yyyyMMddHHmmss");
        SimpleDateFormat fm3 = new SimpleDateFormat("MMddHHmmss");
        TreeMap<String, Object> bodyMap = new TreeMap<String, Object>();
        TreeMap<String, Object> roeMap = new TreeMap<String, Object>();
        TreeMap<String, Object> spMap = new TreeMap<String, Object>();
        roeMap.put("SEQUENCE_ID", fm2.format(new Date()) + getRandNumFour()); //流水号，格式为时间戳+序列号：YYYYMMDDHHMMSSxxxx，其中xxxx为序列号，从0001开始，排满9999后重新循环
        String capcode = "68"; //2位CAP编码标识
        String platfromcode = "190";  //3位业务平台编码（CAP统一分配）
        String orderid = capcode + platfromcode + fm3.format(new Date());
        roeMap.put("ORDER_ID", orderid);    //cBSS订单号
        roeMap.put("UPDATE_TYPE", "1");    //操作类型: 订购-1、退订-2
        roeMap.put("MDN", "18673197465");    //订购手机号
        roeMap.put("ACCEPT_TIME", fm2.format(new Date()));    //操作时间，格式：yyyyMMddhhmmss
        roeMap.put("IN_MODE_CODE", "05");    //订购/退订渠道
        roeMap.put("SOURCEDEVICE_ID", "XXXX");    //下游系统标识

        spMap.put("SP_PRODUCT_ID", "123456");
        spMap.put("SP_ID", "6635");
        spMap.put("START_DATE", fm2.format(new Date()));
        spMap.put("END_DATE", "20501230235959");

        roeMap.put("SP_INFO", spMap);
        //reqJson.parse(roeMap);
        //reqJson.put("SP_INFO", roeMap);

        String jsonParams = "";

        JSONObject json = new JSONObject();
        JSONObject spinfo = new JSONObject();
        spinfo.put("SP_PRODUCT_ID", "123456");
        spinfo.put("SP_ID", "6635");
        spinfo.put("START_DATE", fm2.format(new Date()));
        spinfo.put("END_DATE", "20501230235959");

        json.put("SP_INFO", spinfo);
        json.put("ORDER_ID", orderid);    //cBSS订单号
        json.put("UPDATE_TYPE", "1");    //操作类型: 订购-1、退订-2
        json.put("MDN", "18673197465");    //订购手机号
        json.put("ACCEPT_TIME", fm2.format(new Date()));    //操作时间，格式：yyyyMMddhhmmss
        json.put("IN_MODE_CODE", "05");    //订购/退订渠道
        json.put("SOURCEDEVICE_ID", "XXXX");    //下游系统标识
        json.put("SEQUENCE_ID", fm2.format(new Date()) + getRandNumFour()); //流水号，格式为时间戳+序列号：YYYYMMDDHHMMSSxxxx，其中xxxx为序列号，从0001开始，排满9999后重新循环

        jsonParams = json.toJSONString();

        //bodyMap.put("REVERSE_ORDERING_REQ", roeMap);
        //reqJson.put("UNI_BSS_BODY", bodyMap);

        //填充UNI_BSS_ATTACHED
        //TreeMap<String, Object> attachedMap = new TreeMap<String, Object>();
        //reqJson.put("UNI_BSS_ATTACHED", attachedMap);

        System.out.println(jsonParams);

        System.out.println(url);
        try {
            System.out.println("开始调接口....");
            System.out.println("返回结果=>" + doHandle(url, jsonParams));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * MD5 32位小写加密
     *
     * @param encryptStr
     * @return
     */
    public static String encrypt32(String encryptStr) {
        String md5Str = "";
        try {
            MessageDigest md5 = MessageDigest.getInstance("MD5");
            byte[] md5Bytes = md5.digest(encryptStr.getBytes());
            StringBuffer hexValue = new StringBuffer();
            for (int i = 0; i < md5Bytes.length; i++) {
                int val = ((int) md5Bytes[i]) & 0xff;
                if (val < 16)
                    hexValue.append("0");
                hexValue.append(Integer.toHexString(val));
            }
            md5Str = hexValue.toString();
        } catch (Exception e) {
            throw new RuntimeException(e);
        }
        return md5Str;
    }


    public static String doHandle(String url, String data) throws Exception {
        return URLUtil.post(url, data);
    }

    /**
     * 获取请求ID
     *
     * @return
     */
    private static String getTransId() {
        SimpleDateFormat fm = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String requestId = fm.format(new Date()) + getRandNum();
        return requestId;
    }

    /**
     * 获取6位随机数
     *
     * @return
     */
    private static String getRandNum() {
        int romNum = (int) ((Math.random() * 9 + 1) * 100000);
        return romNum + "";
    }

    /**
     * 获取4位随机数
     *
     * @return
     */
    private static String getRandNumFour() {
        int romNum = (int) ((Math.random() * 9 + 1) * 1000);
        return romNum + "";
    }

    private static String getRandNum11() {
        int romNum = (int) ((Math.random() * 9 + 1) * 1000);
        return romNum + "";
    }

    /**
     * 获取请求ID
     *
     * @return
     */
    private static String getRequestId() {
        SimpleDateFormat fm = new SimpleDateFormat("yyyyMMddHHmmssSSS");
        String requestId = fm.format(new Date()) + getRandNum();
        return requestId;
    }


    /**
     * 查询接口url
     */
    public static void getQryUrl() {
        try {
            String url = "http://172.16.33.16:8084/video-order/qrybusi";
            String channel = "TX20_wtqd";
            String pwd = "khrewqad";
            String cpid = "youtu";
            cpid = "gdtencent";
            //cpid = "0";
            String spid = "1167";
            spid = "0";
            spid = "115";
            String userid = "18673197465";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            userid = DesUtil.encode(userid, pwd);
            String signature = "";
            signature = MD5.MD5Encode(cpid + spid + userid + channel + timestamp + pwd);
            String enUserid = URLEncoder.encode(userid, "utf-8");
            url = url + "?channel=" + channel + "&cpid=" + cpid + "&spid=" + spid + "&signature=" + signature + "&timestamp=" + timestamp + "&userid=" + enUserid;
            //System.out.println("查询url");
            System.out.println(url);
        } catch (Exception e) {
        }
    }

    /**
     * FTP同步接口
     */
    public static void getTrafficOrderUrl(String provincecode, String nettypecode, String serialnumber, String orderid,
                                          String ordertime, String orderstatus, String productid, String depart) {
        //System.out.println("provincecode=>"+provincecode+",nettypecode"+nettypecode+",serialnumber=>"+serialnumber+",orderid=>"+orderid
        //+",ordertime=>"+ordertime+",orderstatus=>"+orderstatus+",productid=>"+productid+",depart=>"+depart);
        try {
            String url = "http://172.16.33.16:8084/video-order/trafficOrder";
            url = "http://114.255.201.221:809/univideo/trafficOrder";

            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            //timestamp = "1564736796";
            String signature;

            String channel = "ftporder";
            String pwd = "khrewqad";


            serialnumber = DesUtil.encode(serialnumber, pwd);
            //Md5(接入渠道+手机号码伪码+订单号+订单状态+产品编码+时间戳+密码)
            signature = MD5.MD5Encode(channel + serialnumber + orderid + orderstatus + productid + timestamp + pwd);
            String enUserid = URLEncoder.encode(serialnumber, "utf-8");
            //enUserid = serialnumber;
            url = url + "?provincecode=" + provincecode + "&nettypecode=" + nettypecode + "&serialnumber=" + enUserid + "&orderstatus=" + orderstatus + "&productid=" + productid
                    + "&depart=" + depart + "&orderid=" + orderid + "&ordertime=" + ordertime + "&timestamp=" + timestamp + "&channel=" + channel + "&signature=" + signature;
            System.out.println(url);
            System.out.println(URLUtil.get(url));
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * FTP同步接口
     */
    public static void getTrafficOrderUrl() {
        try {
            String url = "http://172.16.33.16:8084/video-order/trafficOrder";
            //url = "http://114.255.201.221:86/univideo/handle";
            url = "http://114.255.201.228:86/video-order/trafficOrder";
            String provincecode = "011";
            String nettypecode = "02";
            String serialnumber = "13241990655";
            String orderstatus = "0";
            String productid = "9658745";
            String depart = "02";
            String orderid = "BUSI031907241825380050000025";
            String ordertime = "20190422104607";

            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            //timestamp = "1564736796";
            String signature;

            String channel = "Traffic";
            String pwd = "khrewqad";

            channel = "ftporder";
            pwd = "wsx2#EDC";

            serialnumber = DesUtil.encode(serialnumber, pwd);
            //Md5(接入渠道+手机号码伪码+订单号+订单状态+产品编码+时间戳+密码)
            signature = MD5.MD5Encode(channel + serialnumber + orderid + orderstatus + productid + timestamp + pwd);
            String enUserid = URLEncoder.encode(serialnumber, "utf-8");
            //enUserid = serialnumber;
            url = url + "?provincecode=" + provincecode + "&nettypecode=" + nettypecode + "&serialnumber=" + enUserid + "&orderstatus=" + orderstatus + "&productid=" + productid
                    + "&depart=" + depart + "&orderid=" + orderid + "&ordertime=" + ordertime + "&timestamp=" + timestamp + "&channel=" + channel + "&signature=" + signature;
            System.out.println(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    /**
     * 积分商城
     */
    public static void getPointShopUrl() {
        try {
            String url = "http://172.16.33.16:8084/video-order/point/busi/";
            //org.apache.commons.codec.binary.Base64
            //JSONObject json = new JSONObject();
            TreeMap<String, String> paramMap = new TreeMap<String, String>();
            String aeskey = "78nQJ+8BEjCk0w5CCqXvJw==";
            String secret = "78nQJ+8BEjCk0w5CCqXvJ6lrpQ0/c7C/9MV0gAomiCU=";
            String time = sdf.format(new Date());
            String appId = "ZXcsdepart";
            String serviceCode = "ZC2018JF001";

            paramMap.put("appId", appId);

            String params = mapToJsonStr(getOrderParams());
            //json.put("params", params);
            paramMap.put("params", SignUtil.encrypt(params, aeskey));
            System.out.println("加密后的参数信息：" + paramMap.get("params"));
            System.out.println("解密后的参数信息：" + SignUtil.decrypt(paramMap.get("params"), aeskey));
            paramMap.put("serviceCode", serviceCode);
            paramMap.put("time", time);
            String signStr = "";
            String[] keyArray = paramMap.keySet().toArray(new String[]{});
            for (String key : keyArray) {
                signStr += "&" + key + "=" + paramMap.get(key);
            }
            signStr = signStr.substring(1);
            String sign = null;
            try {
                sign = HMACUtil.encrypt(signStr, secret, "utf-8");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            //System.out.println(sign);
            paramMap.put("sign", sign);

            System.out.println("充值参数：" + mapToJsonStr(paramMap));

            /*******************************************************/

            TreeMap<String, String> qryparamMap = new TreeMap<String, String>();
            qryparamMap.put("appId", appId);
            String qryparams = mapToJsonStr(getQryParams());
            //System.out.println(qryparams);
            qryparamMap.put("params", SignUtil.encrypt(qryparams, aeskey));
            System.out.println("URL: " + url);
            System.out.println("加密后的参数信息：" + qryparamMap.get("params"));
            System.out.println("解密后的参数信息：" + SignUtil.decrypt(qryparamMap.get("params"), aeskey));
            serviceCode = "ZC2018JF002";
            qryparamMap.put("serviceCode", serviceCode);
            qryparamMap.put("time", time);
            String[] keyArray2 = qryparamMap.keySet().toArray(new String[]{});
            String signStr2 = "";
            String sign2 = "";
            for (String key : keyArray2) {
                signStr2 += "&" + key + "=" + qryparamMap.get(key);
            }
            signStr2 = signStr2.substring(1);
            try {
                sign2 = HMACUtil.encrypt(signStr2, secret, "utf-8");
            } catch (Exception ex) {
                ex.printStackTrace();
            }
            //System.out.println(sign);
            qryparamMap.put("sign", sign2);

            System.out.println("查询参数：" + mapToJsonStr(qryparamMap));

        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static String mapToJsonStr(Map params) {
        String reJson = "";
        try {
            ObjectMapper mapper = new ObjectMapper();
            reJson = mapper.writeValueAsString(params);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return reJson;
    }

    public static Map jsonStrToMap(String jsonStr) {
        Map reMap = null;
        try {
            ObjectMapper mapper = new ObjectMapper();
            reMap = mapper.readValue(jsonStr, Map.class);
        } catch (Exception e) {
            e.printStackTrace();
        }
        return reMap;
    }

    public static Map getOrderParams() {
        /**
         * 爱奇艺会员  120  219072316285
         优酷 会员 + 免流   1168   119072316279
         */
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        String account = "18673197465"; //充值账号
        String orderNo = UUID.randomUUID().toString().replace("-", ""); //积分商城订单号
        String goodsCode = "1168";
        String orderTime = sdf.format(new Date());
        params.put("account", account);
        params.put("orderNo", orderNo);
        params.put("goodsCode", goodsCode);
        params.put("orderTime", orderTime);
        return params;
    }

    public static Map getQryParams() {
        TreeMap<String, Object> params = new TreeMap<String, Object>();
        String orderId = "201906221105038662904";
        String orderNo = "d4078706-2ff3-4f1b-9aad-80436a294b22";
        params.put("orderId", orderId);
        params.put("orderNo", orderNo);
        return params;
    }

    public static void aiqy() {
        try {
            //String url = "http://111.206.135.32:8080/flowlimit/refreshFlowcp?queueName=flowAddPropel&userid=18822040070&flowTotal=160&maxflowTotal=15360&flowcp=youtu&type=1";
            // System.out.println("=========================>"+URLUtil.get(url));

            String path = "C:/aiqy";
            File file = new File(path);
            String[] files = file.list();
            for (int i = 0; i < files.length; i++) {
                System.out.println("正在处理【" + i + "】个文件，剩余【" + (files.length - i) + "】");
                System.out.println(files[i]);
                File tmp = new File(path + files[i]);
                parseFileAiqy(null, path + "/" + files[i]);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
    }

    public static void parseFileAiqy(File localFile, String textFileName) throws Exception {
        // System.out.println(textFileName);
        BufferedReader br = null;
        String line = null;
        try {
            FileInputStream is = new FileInputStream(new File(textFileName));
            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            int index = 0;
            int times = 0;
            while ((line = br.readLine()) != null) {
                if (StringUtils.isEmpty(line)) {
                    return;
                }
                try {
                    if (line.indexOf("\"resultcode\":\"0\"") != -1
                            //line.indexOf("\"resultcode\":\"8004\"") != -1
                            ||
                            line.indexOf("\"resultcode\":\"8016\"") != -1
                    ) {
                        JSONObject jsonObj = (JSONObject) JSON.parse(line.split(" - ")[1]);
                        times += Integer.parseInt(jsonObj.getString("time"));
                        //System.out.println(jsonObj.getString("time"));
                    }

                } catch (Exception e) {
                    // TODO: handle exception
                }
		            /*
		            try {
		            	if(line.split(",").length == 2 && line.split(",")[0].length() == 32){
							String url = getFlowlimitUrl(line.split(",")[0],line.split(",")[1]);
							System.out.println(AESUtil.decrypt(line.split(",")[0], "ac22273abb2f4960")+"========================"+"=>"+URLUtil.get(url));
		            	}else{
		            		System.out.println("参数错误====》"+line);
		            	}

					} catch (Exception e) {
						System.out.println(AESUtil.decrypt(line.split(",")[0], "ac22273abb2f4960")+"==========="+line+"============="+e.getMessage());
					}
					*/
                index++;
            }
            System.out.println(times);
            System.out.println(times / 1000);
        } finally {
            if (br != null)
                try {
                    br.close();
                } catch (Exception localException) {
                }
        }
    }

    public static String getFlowlimitUrl(String userid, String cpid) throws Exception {
        String channel = "cdn";
        SimpleDateFormat sdf = new SimpleDateFormat("yyyyMMddHHmmss");
        String timestamp = (System.currentTimeMillis()) / 1000 + "";
        String pwd = "cdn";

        String signature = userid + cpid + channel + timestamp + pwd;
        //System.out.println("签名前："+signature);
        signature = MD5.MD5Encode(signature); //转换为十六进制ASCII 码字符串，共32 个字符，全小写 userid= Des(手机号码，pwd)
        //System.out.println("签名后："+signature);
        String baseUrl = "http://111.206.135.32:8080/"; //测试环境公网
        baseUrl = "http://111.206.134.43:809/"; //生产环境公网
        String urlflowQuery = "orderFlow/flowQuery";
        baseUrl += urlflowQuery + "?userid=" + URLEncoder.encode(userid, "utf-8") + "&cpid=" + cpid + "&channel=" + channel + "&timestamp=" + timestamp + "&signature=" + signature;
        return baseUrl;
    }

    public static void cp() {
        try {
            //String url = "http://111.206.135.32:8080/flowlimit/refreshFlowcp?queueName=flowAddPropel&userid=18822040070&flowTotal=160&maxflowTotal=15360&flowcp=youtu&type=1";
            // System.out.println("=========================>"+URLUtil.get(url));

            String path = "C:/cpproele";
            File file = new File(path);
            String[] files = file.list();
            for (int i = 0; i < files.length; i++) {
                System.out.println("正在处理【" + i + "】个文件，剩余【" + (files.length - i) + "】");
                System.out.println(files[i]);
                File tmp = new File(path + files[i]);
                parseFile2(null, path + "/" + files[i]);
                //VacFileService service = new VacFileService();
                //service.parseFile(new File(path+files[i]),DateFormatUtils.format(new Date( new File(path+files[i]).lastModified()),"yyyyMMddHHmmss"));
                //service.parseFile(new File(path+files[i]),inserttime);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
    }

    public static void parseFile2(File localFile, String textFileName) throws Exception {
        // System.out.println(textFileName);
        BufferedReader br = null;
        String line = null;
        try {
            FileInputStream is = new FileInputStream(new File(textFileName));
            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            // br = new BufferedReader(new FileReader(localFile));
            int index = 0;
            while ((line = br.readLine()) != null) {
                if (StringUtils.isEmpty(line)) {
                    return;
                }
                // System.out.println("========================"+line);
                //http://111.206.135.32:8080
                String url = "http://111.206.135.32:8080/flowlimit/refreshFlowcp?queueName=flowAddPropel&userid=" + line + "&flowTotal=40960&maxflowTotal=40960&flowcp=youtu&type=1";
                System.out.println("========================" + line + "=>" + URLUtil.get(url));
                ;
                index++;
            }
            System.out.println(index);
        } finally {
            if (br != null)
                try {
                    br.close();
                } catch (Exception localException) {
                }
        }
    }

    public static void ftpFileParse() {
        try {
            String path = "c:/ftpfile-tmp";
            //String path = "f:/vac/";
            File file = new File(path);
            String[] files = file.list();
            for (int i = 0; i < files.length; i++) {
                System.out.println("正在处理【" + i + "】个文件，剩余【" + (files.length - i) + "】");
                if (files[i].lastIndexOf("bak") != -1) {
                    continue;
                }
                System.out.println(files[i]);
                File tmp = new File(path + files[i]);
                parseFile(null, path + "/" + files[i]);
                //VacFileService service = new VacFileService();
                //service.parseFile(new File(path+files[i]),DateFormatUtils.format(new Date( new File(path+files[i]).lastModified()),"yyyyMMddHHmmss"));
                //service.parseFile(new File(path+files[i]),inserttime);
            }
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    public static void parseFile(File localFile, String textFileName) throws Exception {
        // System.out.println(textFileName);
        BufferedReader br = null;
        String line = null;
        try {
            FileInputStream is = new FileInputStream(new File(textFileName));
            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            // br = new BufferedReader(new FileReader(localFile));
            int index = 0;
            while ((line = br.readLine()) != null) {
                if (StringUtils.isEmpty(line)) {
                    return;
                }
                if (index != 0) {
                    //System.out.println(line);
                    String[] values = line.split("\\|", -1);
                    String provincecode = values[0];
                    String nettypecode = values[1];
                    String serialnumber = values[2];
                    String orderid = values[3];
                    String ordertime = values[4];
                    String orderstatus = values[5];
                    String productid = values[6];
                    String depart = values[7];

                    getTrafficOrderUrl(provincecode, nettypecode, serialnumber, orderid, ordertime, orderstatus, productid, depart);
                }
                index++;
            }
            System.out.println(index);
        } finally {
            if (br != null)
                try {
                    br.close();
                } catch (Exception localException) {
                }
        }
    }

    /**
     * CP推送
     *
     * @param usermob
     * @param maxflow
     * @param flow
     * @throws Exception
     */
    public static void cpprople(String usermob, String maxflow, String flow) throws Exception {
        String flowcp = "youtu";
        String baseurl = "https://pre-4g.youku.com/wl/unicom/restSync";
        String mobtype = "0";
        String netpwd = "ks82xnfo";
        String timestamp = (System.currentTimeMillis()) / 1000 + "";
        String userid = usermob.trim();
        userid = DesUtil.encode(userid, netpwd);
        String sign = MD5.MD5Encode(userid + flowcp + timestamp + netpwd);
        userid = URLEncoder.encode(userid, "utf-8");
        String url = baseurl + "?userid=" + userid + "&cpid=" + flowcp.trim() + "&maxflow=" + maxflow.trim() + "&flow=" + flow.trim() + "&timestamp=" + timestamp + "&signature=" + sign;
        String resp = URLUtil.get(url);
        System.out.println("userid = >" + usermob + ",  " + resp);
    }

    /**
     * 修复bilbl数据
     */
    public static void filebilbl() {
        try {
            String path = "C:/bilbl";
            File file = new File(path);
            String[] files = file.list();
            for (int i = 0; i < files.length; i++) {
                System.out.println("正在处理【" + i + "】个文件，剩余【" + (files.length - i) + "】");
                System.out.println(files[i]);
                if (files[i].indexOf("bak") != -1) {
                    continue;
                }
                File tmp = new File(path + files[i]);
                bilblparseFile(null, path + "/" + files[i]);
                //VacFileService service = new VacFileService();
                //service.parseFile(new File(path+files[i]),DateFormatUtils.format(new Date( new File(path+files[i]).lastModified()),"yyyyMMddHHmmss"));
                //service.parseFile(new File(path+files[i]),inserttime);
            }
        } catch (Exception e) {
            // TODO: handle exception
        }
    }

    public static void bilblparseFile(File localFile, String textFileName) throws Exception {
        //String baseurl = "http://111.206.134.43:809/flowlimit/busiChange";
        BufferedReader br = null;
        String line = null;
        try {
            FileInputStream is = new FileInputStream(new File(textFileName));
            br = new BufferedReader(new InputStreamReader(is, "UTF-8"));
            // br = new BufferedReader(new FileReader(localFile));
            int index = 0;
            while ((line = br.readLine()) != null) {
                if (StringUtils.isEmpty(line)) {
                    return;
                }
                try {
                    cpprople(line, "5242880", "5242880");
                    // String url = baseurl + "?ordertype=2&isold=1&cpid=bilibl&endtime=20191130235959&maxflow=5242880&starttime=20191101000001&spid="+line.split(",")[0].trim()+"&isfh=1&flowtype=1&flow=5242880&islimit=1&userid="+line.split(",")[1].trim();
                    // String resp = URLUtil.get(url);
                } catch (Exception e) {
                    e.printStackTrace();
                }
                index++;
                System.out.println(index);
            }

        } finally {
            if (br != null)
                try {
                    br.close();
                } catch (Exception localException) {
                }
        }


//		  String baseurl = "http://111.206.134.43:809/flowlimit/busiChange";
//		  String url = baseurl + "?ordertype=2&isold=1&cpid=bilibl&endtime=20191130235959&maxflow=5242880&starttime=20191101000001&spid=979&isfh=1&flowtype=1&flow=5242880&islimit=1&userid=18673197465";
//		  String resp = URLUtil.get(url);
//		  System.out.println(resp);
    }


    //video-order/handle
    public static String getVideoOrderHandle() {
        String url = "";
        String baseUrl = "http://172.16.33.16:8084/video-order/handle";
        //  baseUrl = "http://114.255.201.228:86/video-order/handle";
        try {
            String cpid = "";
            //cpid = "tencent";
            //cpid = "aiqy";
            cpid = "gdtencent";
            String spid = "";
            //spid ="101";
            //spid = "1017";
            spid = "115";
            String userid = "";
            //userid = "18673197465";
            userid = "13810021167";
            String type = "0";
            //String canceltype = "1";
            String channel = "";
            //channel = "TX20_dtqd";
            //channel = "TX20_wtqd";
            channel = "jiangsusf";
            String apptype = "2";
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            timestamp = "1592463219";
            String pwd = ""; //TB_CHANNEL_ORG表的PASSWORD 渠道表的密码
            //pwd = "jfgkutbz"; //TB_CHANNEL_ORG表的PASSWORD 渠道表的密码
            //pwd = "khrewqad";
            pwd = "$RFV5tgb";
            String access = "1";
            String seqnumber = ""; //可以为空
            //seqnumber = "123456789"; //可以为空
            seqnumber = "";
            String orderid = UUID.randomUUID().toString();
            orderid = "7-34202006180000142623";
            String usertype = "1"; //usertype(赠送会员的账户类型,1为qq号,2微信号  )，订购时需要，退订不要
            usertype = "";
            String userval = ""; //userval(会员的账户,如果usertype=1 那么userval=用户的qq号码，订购时需要，退订不要
            //userval = "321457895625";
            userval = "";
            userid = DesUtil.encode(userid, pwd);
            String signature = "";
            signature = orderid + cpid + spid + userid + type + channel + timestamp + pwd;
            //signature = cpid + spid + userid + type + channel + timestamp + pwd;
            System.out.println("signature=>" + signature);
            signature = MD5.MD5Encode(signature);
            System.out.println("signature=>" + signature);
            String enUserid = URLEncoder.encode(userid, "utf-8");
            String token = "";
            //token = "8383d76ddd120d928dafef49219297dd";
            token = "";
            url = baseUrl + "?seqnumber=" + seqnumber + "&usertype=" + usertype + "&userval=" + userval + "&orderid=" + orderid + "&access=" + access + "&apptype=" + apptype + "&channel=" + channel + "&cpid=" + cpid + "&spid=" + spid + "&type=" + type + "&signature=" + signature + "&timestamp=" + timestamp + "&token=" + token + "&userid=" + enUserid;
            System.out.println("订购url");
            System.out.println(url);
            type = "1";
            signature = orderid + cpid + spid + userid + type + channel + timestamp + pwd;
            //signature = cpid + spid + userid + type + channel + timestamp + pwd;
            System.out.println("signature=>" + signature);
            signature = MD5.MD5Encode(signature);
            System.out.println("退订url");
            url = baseUrl + "?seqnumber=&orderid=" + orderid + "&access=" + access + "&apptype=" + apptype + "&channel=" + channel + "&cpid=" + cpid + "&spid=" + spid + "&type=" + type + "&signature=" + signature + "&timestamp=" + timestamp + "&token=" + token + "&userid=" + enUserid;
            System.out.println(signature);
            System.out.println(url);
            //invoke(url);
        } catch (Exception e) {
            e.printStackTrace();
        }

        return url;
    }


    //拓维5gsync查询
    public static void tw5gSyncUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/tendraw/prizesend";
            //测试环境
            url = "http://114.255.201.228:86/video-order/tw5gsync";
            String pwd = "7dea1gd5";
            //18673197465
            String spid = "242";
            String userid = "18673197465";
            String channel = "TX20_twback_old";
            String cpid = "tencent";
            userid = DesUtil.encode(userid, pwd);
            System.out.println(userid + " **************************");
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            System.out.println(userid + channel + spid + cpid + timestamp + pwd);
            String signature = MD5.MD5Encode(userid + channel + spid + cpid + timestamp + pwd);
            String jsonParams = "";
            JSONObject json = new JSONObject();

            json.put("userid", userid);
            json.put("cpid", cpid);
            json.put("spid", spid);
            json.put("channel", channel);
            json.put("timestamp", timestamp);
            json.put("signature", signature);
            jsonParams = json.toJSONString();
            System.out.println(url);
            System.out.println(jsonParams);
            invokePostJson(url, jsonParams);
//			userid = URLEncoder.encode(userid,"utf-8");
//			String spid = "1018";
//			String username = URLEncoder.encode("测试","utf-8");
//            String address = URLEncoder.encode("测试","utf-8");
//			//System.out.println(userid);
//            url = url + "?userid="+userid+"&spid="+spid+"&username="+username+"&address="+address;
//			System.out.println(url);
//			invoke(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }

    //彩铃侧
    public static void ColorsealUrl() {
        try {
            //开发环境
            String url = "http://172.16.33.16:8084/video-order/tendraw/prizesend";
            //测试环境
            //通知 http://114.255.201.228:86/video-order/colorsealnotify
            //一键设置 http://114.255.201.228:86/video-order/colorsealset
            url = "http://114.255.201.228:86/video-order/colorsealset";
            String pwd = "#EDC2wsx";
            //18673197465
            String spid = "1008";
            String userid = "18673197465";
            String channel = "clmangtv";
            String cpid = "mangtv16";
            //String type = "1";
            userid = DesUtil.encode(userid, pwd);
            System.out.println(userid + " **************************");
            String timestamp = (System.currentTimeMillis()) / 1000 + "";
            String ringid = "99103000202008285994840";
            System.out.println(userid + channel + spid + cpid + timestamp + pwd);
            String signature = MD5.MD5Encode(userid + cpid + spid + channel + ringid + timestamp + pwd);
            String jsonParams = "";
            JSONObject json = new JSONObject();

            json.put("userid", userid);
            json.put("cpid", cpid);
            json.put("spid", spid);
            //json.put("type", type);
            json.put("channel", channel);
            json.put("timestamp", timestamp);
            json.put("signature", signature);
            json.put("ringid", ringid);
            jsonParams = json.toJSONString();
            System.out.println(url);
            System.out.println(jsonParams);
            invokePostJson(url, jsonParams);
//			userid = URLEncoder.encode(userid,"utf-8");
//			String spid = "1018";
//			String username = URLEncoder.encode("测试","utf-8");
//            String address = URLEncoder.encode("测试","utf-8");
//			//System.out.println(userid);
//            url = url + "?userid="+userid+"&spid="+spid+"&username="+username+"&address="+address;
//			System.out.println(url);
//			invoke(url);
        } catch (Exception e) {
            e.printStackTrace();
        }
    }


    public static void invokePostJson(String url, String params) {
        try {
            String resp = URLUtil.postJson(url, params);
            System.out.println(resp);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static void invoke(String url) {
        try {
            String resp = URLUtil.get(url);
            System.out.println(resp);
        } catch (Exception e) {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }
    }

    public static String doHandle(String url) throws Exception {
        return URLUtil.get(url);
    }

}
