package com.library.test;

import com.google.gson.Gson;
import com.library.service.Impl.AutomaticCodeServiceImpl;
import com.wechat.pay.MD5Util;
import sun.security.provider.MD5;

import javax.xml.datatype.DatatypeConfigurationException;
import javax.xml.datatype.DatatypeFactory;
import javax.xml.datatype.XMLGregorianCalendar;
import java.sql.Timestamp;
import java.text.SimpleDateFormat;
import java.util.*;

/**
 * Created by Administrator on 2018\10\31 0031.
 */
public class ylmTest {
    public static void main(String[] args) {

        //{"status":0,"code":"MSG_SUCCESS","message":"Success","txDetail":{"transDetailId":4551,"transDetailCode":"37363eef5895e3b0db52f3f79f611251","merchantId":null,"merchantCode":"ePayTest","merchantServiceId":null,"merchantServiceType":"TOPUP","transTime":1577946364313,"emServiceProvideId":null,"emServiceId":null,"emServiceCode":null,"status":1,"paymentType":null,"refId":"1121","transDescription":null,"transAmount":1.0,"currencyCode":"USD","transAmountConvert":null,"currencyExchangeRate":null,"acceptPaymentCurrencyCode":null,"discountType":"1","discountAmount":0.05,"commissionAmount":null,"transFee":0.0,"transTotalAmount":0.95,"transTotalAmountConvert":null,"customerPhoneNumber":"855883970777","customerName":null,"description":null,"paidTime":null,"paidTid":null,"paidEmoneyAccount":null,"paidFee":null,"paidChanel":null,"paidAmount":null,"paidCurrencyCode":null,"paidTip":null,"paidTotalAmount":null,"emCoporationId":null,"emCoporationMsisdn":null,"txPaymentTokenId":"S6a6oWb3RB2YAU48Wy6RbZwT01AUTh10xtNvcqOgMib32KB+KnUy68bVTm/G0GPKMRUHEM4OqAsYGxOKpkgANCDtX133IKCmw2+Y9OhUQkQOUq8HAD4EySiM0GZ/xkbJey9dPYmebRCouy5iwRl7acQbuMsHWsTCc7CEFUFNyyZzkGKjOXW8v/nq5tB7D/lxeXsspd9rHURVC4gc/NDU7MZPRxd4QPMMyRR2tZ7xHxIOXt6map1msd7Ce5uMD5mgFgNnyc4IVitNbAqGJuBeR3ixWYlaLF41LqJXgMwvGMhMbcAGlPzTMw97dREegXWCnpi4iLygk5tieyUZ5S34hg==","paymentQrCode":null},"pinCode":null,"billPaymentInfo":null}

        SimpleDateFormat sdf = new SimpleDateFormat("yyMMddHHmmss");
        String hms = sdf.format(new Date());

        System.out.println(hms);


        String phone = "12011101231211211";
        if (phone.startsWith("0")) {
            phone = phone.substring(1);
        }
        System.out.println(phone);

        System.out.println("===============");

        String sign="queryphonenumberstatus"+"shoptest"+"shoptest0001"+"shoptest181218006"+"2018-12-13 16:14:28"+"0189464112"+"2200ded1a890515641248dd1d6ea966e";
        System.out.println(MD5Util.MD5Encode(sign,"utf-8"));


        System.out.println(MD5Util.MD5Encode("123456",""));
        System.out.println(MD5Util.MD5Encode("123456","utf-8"));
        System.out.println(new Random().nextInt(10000));


        System.out.println("--------");

        System.out.println(getCurrentTime());
        System.out.println(getFormatedDateString(7));
    }

    public static String getCurrentTime(){
        //获取指定格式的时间
        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(TimeZone.getTimeZone("GMT-7"));//指定时区
        return sdf.format(new Date());
    }




    /**
     * 取北京时间
     * @return
     */
    public static String getBeijingTime(){
        return getFormatedDateString(8);
    }

    /**
     * 取班加罗尔时间
     * @return
     */
    public static String getBangaloreTime(){
        return getFormatedDateString(5.5f);
    }

    /**
     * 取纽约时间
     * @return
     */
    public static String getNewyorkTime(){
        return getFormatedDateString(-5);
    }

    /**
     * 此函数非原创，从网上搜索而来，timeZoneOffset原为int类型，为班加罗尔调整成float类型
     * timeZoneOffset表示时区，如中国一般使用东八区，因此timeZoneOffset就是8
     * @param timeZoneOffset
     * @return
     */
    public static String getFormatedDateString(float timeZoneOffset){
        if (timeZoneOffset > 13 || timeZoneOffset < -12) {
            timeZoneOffset = 0;
        }

        int newTime=(int)(timeZoneOffset * 60 * 60 * 1000);
        TimeZone timeZone;
        String[] ids = TimeZone.getAvailableIDs(newTime);
        if (ids.length == 0) {
            timeZone = TimeZone.getDefault();
        } else {
            timeZone = new SimpleTimeZone(newTime, ids[0]);
        }

        SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        sdf.setTimeZone(timeZone);
        return sdf.format(new Date());
    }
}
