package com.bizzan.bitrade.test.service;

import static org.junit.Assert.*;

import java.io.UnsupportedEncodingException;
import java.math.BigDecimal;
import java.net.URLEncoder;
import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.ArrayList;
import java.util.Calendar;
import java.util.Date;
import java.util.List;
import java.util.regex.Matcher;
import java.util.regex.Pattern;

import org.junit.Test;

import com.alibaba.fastjson.JSON;
import com.alibaba.fastjson.JSONObject;
import com.bizzan.bitrade.entity.Member;
import com.bizzan.bitrade.util.GeneratorUtil;
import com.bizzan.bitrade.util.GoogleAuthenticatorUtil;
import com.bizzan.bitrade.util.HttpClientUtil;
import com.bizzan.bitrade.util.HttpSend;
import com.bizzan.bitrade.util.MessageResult;
import com.bizzan.bitrade.vendor.provider.support.MstxSMSProvider;

public class SMSTest {

	@Test
	public void testSendSingleMessage() {
		/*MstxSMSProvider provider = new MstxSMSProvider();
		try {
			provider.sendSingleMessage("19179502598", "312345");
		} catch(Exception e) {
			e.printStackTrace();
		}*/
		fail("Not yet implemented");
	}

	@Test
	public void testSendInternationalMessage() {
		MstxSMSProvider provider = new MstxSMSProvider("","","","LTAI5tAKb4s4HQ7zmwGM7kGX","4W1NGjQAA8cll392h49QBVsXtNhVI5","DOGECOIN","","");
		try {
			System.out.print(provider.sendInternationalMessage("123456", "66", "958671019"));
		} catch(Exception e) {
			e.printStackTrace();
		}
		fail("Not yet implemented");
	}
	
	@Test
	public void testGoogleAuth() {
        String secret = GoogleAuthenticatorUtil.generateSecretKey();
        String qrBarcodeURL = GoogleAuthenticatorUtil.getQRBarcodeURL("600800",
                "www.foxs.vip", secret);
        JSONObject jsonObject = new JSONObject();
        jsonObject.put("link",qrBarcodeURL);
        jsonObject.put("secret",secret);
        MessageResult messageResult = new MessageResult();
        messageResult.setData(jsonObject);
        messageResult.setMessage("获取成功");
        System.out.print(messageResult);
	}
	
	@Test
	public void testGoogle() {
		long t = System.currentTimeMillis();
        GoogleAuthenticatorUtil ga = new GoogleAuthenticatorUtil();
        boolean r = ga.check_code("7O3KCQZGZDK45K2O", 124136, t);
        System.out.print(r);
	}
	
	@Test
	public void testNull() throws UnsupportedEncodingException {
		//String smsContent = "【FOX】您的验证码为：222222，十分钟内有效，如非本人操作，请忽略。";
		//String url = "https://api.smsbao.com/sms?u=king2023&p=ea70fdd729484831bdca0e2a3675ad94&m=13823589378&c="+URLEncoder.encode(smsContent, "UTF-8");
		//String result = HttpClientUtil.get(url, null, null);
		//System.out.println("result="+result);
		System.out.print(JSON.toJSONString(null));
	}
	
	@Test
	public void test() {
		System.out.println(new Date(1678698813430L));
		
		String seed = "0123456789A";
    	String code = "";
    	for(int i=0; i<4; i++) {
    		int index = GeneratorUtil.getRandomNumber(0, 10);
    		code += seed.charAt(index);
    	}
    	System.out.println(code);
	}
	@Test
	public void testTime() throws ParseException {
		/*String s = "123456";
		System.out.println(s.substring(s.length()-4));
		Calendar calendar1 = Calendar.getInstance();
		calendar1.setTimeInMillis(1664582400000L);
		calendar1.add(Calendar.MONTH, -14);
		Calendar calendar2 = Calendar.getInstance();
		calendar2.setTimeInMillis(1664582400000L);
		int months = calendar2.get(Calendar.MONTH) - calendar1.get(Calendar.MONTH) + (calendar2.get(Calendar.YEAR) - calendar1.get(Calendar.YEAR))*12;
		System.out.println(months);
		System.out.println(calendar1.getTimeInMillis());*/
		System.out.println(new Date(1679884203367L));
		SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm");
		Date date = sdf.parse("2023-01-02 12:00");
		System.out.println(date.getTime());
		System.out.println(Double.valueOf(8)/100);
		String str = "63e660d08855b0268fa3b5d6&shikuUserId=10000007";
		System.out.println(str.substring(0, str.indexOf("&")));
	}
	
	@Test
	public void testList() {
		String content = "123,321,111,123";
		String[] ids = content.split(",");
    	List<String> list = new ArrayList<>();
    	for(String id: ids) {
    		if(!list.contains(id)) {
    			//tradingAccountMonitor.updateAccount(Long.parseLong(id));
    			System.out.println(id);
    			list.add(id);
    		}
    	}
		System.out.println(list.toString());
	}
	
	@Test
	public void testEmailValidate() {
		String email = "fu.zy18@163.com";
		String regExp = "^[a-zA-Z0-9]+([._-][a-zA-Z0-9]+)*@([a-z0-9A-Z]+(-[a-z0-9A-Z]+)?\\.)+[a-zA-Z]{2,}$";
		Pattern p = Pattern.compile(regExp);
		Matcher m = p.matcher(email);
		System.out.println(m.matches());
	}

}
