import AES from 'crypto-js/aes';
import Utf8 from 'crypto-js/enc-utf8';
import ECBmode from 'crypto-js/mode-ecb';
import PaddingPkcs7 from 'crypto-js/pad-pkcs7';

export const formatePayString = (
  payStr: string,
  customerId: number,
): {
  timeStamp: number;
  nonceStr: string;
  package: string;
  signType: string;
  paySign: string;
} => {
  const key = customerId.toString().padEnd(16, '0');
  const payData = JSON.parse(
    AES.decrypt(payStr, Utf8.parse(key), {
      mode: ECBmode,
      padding: PaddingPkcs7,
    }).toString(Utf8),
  );
  return payData.msg;
};
