package com.yxcheng.token.web.controller.test;

import com.yxcheng.token.utils.Base64Util;
import com.yxcheng.token.utils.DateUtils;
import com.yxcheng.token.utils.Security;
import com.yxcheng.token.utils.UUIDGenerator;
import org.junit.Test;

import java.util.HashMap;
import java.util.Map;

public class SmsUnitTest {

//    static String host = "http://47.94.208.133:8762";
//    static String host = "http://127.0.0.1:8762";
    static String host = "https://pushtoken.invservice.cn";
//    String accessKeyID = "eyongyou";
//    static String accessKeySecret = "yongyou!@#566ccd";
//    String accessKeyID = "echangchen";
//    static String accessKeySecret = "echangchen#@rrwea1";
    String accessKeyID = "fpcheck";
    static String accessKeySecret = "fpcheck$%^123";
    /**
     * zone   91430600081385810Q   -> 4300   特殊的是4403
     *
     * @throws Exception
     */
    @Test
    public void testSmsReceive() throws Exception{
        String url = host + "/client/smsReceive?";
        String signStr = "accessKeyID=%s&signatureNonce=%s&timeStamp=%s&version=1.0";

        String signatureNonce = UUIDGenerator.generate();
        long time = System.currentTimeMillis();

        String timeStamp = DateUtils.formatDate(time,DateUtils.yyyymmddthhmmssz);

        signStr = String.format(signStr,accessKeyID,signatureNonce, timeStamp);
        url += signStr + ("&signature=" + getSign(signStr));
        String sign = getSign(signStr);

        Map map = new HashMap<>();
        map.put("accessKeyID",accessKeyID);
        map.put("signatureNonce",signatureNonce);
        map.put("timeStamp",timeStamp);
        map.put("version",1.0);
        map.put("signature",sign);

        String smsCode = "【内蒙税务】短信验证码：120915。为保障您的账户安全，请勿泄露给他人。";
        map.put("smsCode",Base64Util.encode(smsCode));
        map.put("cellphone","13922345671");
//        map.put("zoneCode","");
//        map.put("validCode","120915");


//        System.out.println(url);
//        ResponseContent ret = HttpHelper.postJsonEntity(url, JSON.toJSONString(map));
//        System.out.println(ret.getContent());
    }


    public static String getSign(String data){
        try {
            return Security.getSignature(data.getBytes("UTF-8"),accessKeySecret.getBytes("UTF-8"));
        } catch (Exception e) {
            e.printStackTrace();
        }
        return null;
    }
}
