package com.huiju.estateagents;

import com.huiju.estateagents.common.wxpay.WXPayUtil;
import org.apache.commons.codec.digest.DigestUtils;
import org.junit.Test;
import org.junit.runner.RunWith;
import org.springframework.boot.test.context.SpringBootTest;
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
import org.springframework.transaction.annotation.Transactional;
import sun.misc.BASE64Decoder;

import javax.crypto.Cipher;
import javax.crypto.spec.SecretKeySpec;
import java.util.Map;

@RunWith(SpringJUnit4ClassRunner.class)
@SpringBootTest(webEnvironment = SpringBootTest.WebEnvironment.RANDOM_PORT)
@Transactional
public class WxPayTest {

    @Test
    public void getLocationCity() {
//        try {
//            String abc = "<xml><return_code>SUCCESS</return_code><appid><![CDATA[wxbbb069a341055ef0]]></appid><mch_id><![CDATA[1577983541]]></mch_id><nonce_str><![CDATA[3d8740137b51c5980b2048a105beb708]]></nonce_str><req_info><![CDATA[5RjGrqrAbzRvah2pEMp1QjCQavhY16xZhke159cIIap/UlJqUj0HSpFHGhlxp03Spbhb5I7WFdUqUErX8NOF7Wp4B/t06xYDvu+/KOVVtjHxvHijGfRIn9LTXPdDqJePFg/ZeYbZUYSUoqHygMSw8O+itBnlipxxh+bUPuTZro1/ydaiTC7gCcKTLkT1Njx6ctrPUC+IcukGVOzpnHy4tSfrt8mMpeGGrKVnmTDZxPBVbfGFebkir32wU4JfBpbpGmS0HDS8i8uq1qW8hnrDufIdcqzio7uMeM/ClTU5jy2Ez4SA7Ks21iObx0gNXMfnEDBKYJsw58R3V7aSf8VS2gWTSn/2QFxmzrSoMH3/bBKvY+LfOsSkis+ZvnMd4baYrRoIzGUkfmE2QXxzupN4404folIyuJ2xB1ewLRK7BTU6MRjPhg9jcEIAVWyoTp04Alek3xLzMILvMzGr0tOdIIqXYKs+7FAcuXgiqpvyw6yVF1l3Xj/IorXLSpfeFqycUUTr4uH7Rm8eCdFDt6YTSVaMRLWNWUBTC8BW4JlpimuXYYMeqrjY0MaJceiN5ZHoIGFmqnml/Tpzcwyb2j6tk5oaEIHlYVAJmsFmL6RLTPFDlUTOOEFAnZ1+wUqxSO0Z6cwcZgIioL1OPS2DC5c2Vi/FEgt8vu1HMn2wClH+R9kDu3fx9TqP8sfG1W89TQP1/s+oQvNdtFJKacGCVeSJ5Fc4pF1zRCStOGOoIAtEf7ub7VitKelYuABPc8P0dzgoLsBPUwFgrx+QrDMzyp8zICK8bzIqqFp+x+1RSN5Q7i8gvh4vWKuajST3F74L+zkQ9r2pEaZ/zWIUHx+xWDb8nw9hMlR4oER+ITASgsqP1PAFpRrHNFl3kV6p5V9Cp5LEVfch+yCS1f/cfcY3KiY4KYBB2jNe+nr/cq5Aq1ijujNERBpjDzJaaJiVcPBKSkcAwk0wPTqYk4ihDlUQ8XTgrfEKje1acdKiA3/t4ltHdG0vGVTKXwteHdnRggBUwELzQFLrPpbx1M2lxBlc8zkm08WLP+DW+rx09ZcyQMCBTFk=]]></req_info></xml>";
//            Map resultMap = WXPayUtil.xmlToMap(abc);
//            SecretKeySpec key = new SecretKeySpec(DigestUtils.md5Hex("RGiWajOfaw3Zl7TUIoQNjmEKA8VG8ZNL").toLowerCase().getBytes(), "AES");
//            Cipher cipher = Cipher.getInstance("AES/ECB/PKCS5Padding");
//            cipher.init(Cipher.DECRYPT_MODE, key);
//            String req_info = new String(cipher.doFinal(new BASE64Decoder().decodeBuffer(resultMap.get("req_info").toString())), "UTF-8");
//
//            Map<String, String> orderInfo = WXPayUtil.xmlToMap(req_info);
//            System.out.println(orderInfo);
//        }catch (Exception e) {
//            e.printStackTrace();
//        }

    }
}
