diff --git a/projects/fangjia-script/pom.xml b/projects/fangjia-script/pom.xml index b98b25ab1..e639f76e3 100644 --- a/projects/fangjia-script/pom.xml +++ b/projects/fangjia-script/pom.xml @@ -530,6 +530,13 @@ + + + org.bouncycastle + bcpkix-jdk15to18 + 1.70 + + diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/AutoAddDistrictBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/AutoAddDistrictBatch.groovy index ae2703c0a..5367882e6 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/AutoAddDistrictBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/AutoAddDistrictBatch.groovy @@ -177,7 +177,6 @@ class AutoAddDistrictBatch extends BaseBatch{ q.put("match_id", new BasicDBObject('$exists',false)) q.put("old_match_id", new BasicDBObject('$exists',false)) q.put("city", c) - q.put("name", "Ç®½­´óÏÃ") def dbcursor = thirdSeaweedMappingColl.find(q).batchSize(5000) def rMap = [:] for(def d : dbcursor){ diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/ThirdPriceMappingBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/ThirdPriceMappingBatch.groovy index 329a548fb..9af4b1ec4 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/ThirdPriceMappingBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/data_handle/ThirdPriceMappingBatch.groovy @@ -4,7 +4,6 @@ import com.fangjia.script.BaseBatch import com.fangjia.script.BatchOwner import com.fangjia.script.Watcher import com.fangjia.script.commData.CommonDatautils -import com.fangjia.script.common.DataHandleUtils import com.fangjia.script.gj.district.FangjiaClientUtils import com.fangjia.script.util.CommonUtils import com.fangjia.script.util.DataUtil @@ -12,14 +11,11 @@ import com.fangjia.script.util.DateUtils import com.fangjia.script.util.MongoUtils import com.mongodb.BasicDBObject import com.mongodb.DBCollection -import org.bson.types.ObjectId -import java.util.concurrent.CopyOnWriteArrayList import java.util.concurrent.CountDownLatch import java.util.concurrent.ExecutorService import java.util.concurrent.Executors import java.util.concurrent.atomic.AtomicLong - /** * µÚÈý·½Ð¡ÇøÓëÎÒÃÇÐ¡ÇøÓ³Éä¹ØÏµ±í */ @@ -44,7 +40,7 @@ class ThirdPriceMappingBatch extends BaseBatch{ @Override public void process(Object args) { // //½«ÐÂÔöÊý¾Ýͬ²½¹ýÀ´ -// addNemCommunity() + addNemCommunity() // //½Ó¿Ú½øÐÐÆ¥Åä match() diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/xiamen/CryptoSm4Util.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/xiamen/CryptoSm4Util.groovy new file mode 100644 index 000000000..6e960180d --- /dev/null +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/xiamen/CryptoSm4Util.groovy @@ -0,0 +1,115 @@ +package com.fangjia.script.gj.xiamen + +import org.bouncycastle.crypto.engines.SM4Engine; +import org.bouncycastle.crypto.modes.CBCBlockCipher; +import org.bouncycastle.crypto.paddings.PaddedBufferedBlockCipher; +import org.bouncycastle.crypto.params.KeyParameter; +import org.bouncycastle.crypto.params.ParametersWithIV; +import org.bouncycastle.util.encoders.Hex; + +import java.security.SecureRandom; + +/** + * @author shenjian + * @since 2024/10/9 + */ +public class CryptoSm4Util { + + /** + * ĬÈÏÃÜÔ¿ + */ + private static final String DEFAULT_SECRET_KEY = "A1B2C3D4E5F60789A1B2C3D4E5F60789"; + private static final String CHARSET = "UTF-8"; + + // String plaintext -> Base64-encoded String ciphertext + public static String encrypt(String key, String plaintext) { + try { + byte[] keyBytes = Hex.decode(key); + byte[] iv = generateIV(); + PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new SM4Engine())); + cipher.init(true, new ParametersWithIV(new KeyParameter(keyBytes), iv)); + byte[] input = plaintext.getBytes(CHARSET); + byte[] encrypted = new byte[cipher.getOutputSize(input.length)]; + int length1 = cipher.processBytes(input, 0, input.length, encrypted, 0); + int length2 = cipher.doFinal(encrypted, length1); + byte[] finalEncrypted = new byte[length1 + length2]; + System.arraycopy(encrypted, 0, finalEncrypted, 0, finalEncrypted.length); + return Hex.toHexString(iv) + Hex.toHexString(finalEncrypted); + } catch (Exception ex) { + ex.printStackTrace(); + } + return null; + } + + private static byte[] generateIV() { + byte[] iv = new byte[16]; + new SecureRandom().nextBytes(iv); + return iv; + } + + // Base64-encoded String ciphertext -> String plaintext + public static String decrypt(String key, String ciphertext) { + try { + byte[] keyBytes = Hex.decode(key); + byte[] iv = Hex.decode(ciphertext.substring(0, 32)); + byte[] encryptedData = Hex.decode(ciphertext.substring(32)); + PaddedBufferedBlockCipher cipher = new PaddedBufferedBlockCipher(new CBCBlockCipher(new SM4Engine())); + cipher.init(false, new ParametersWithIV(new KeyParameter(keyBytes), iv)); + byte[] decrypted = new byte[cipher.getOutputSize(encryptedData.length)]; + int length1 = cipher.processBytes(encryptedData, 0, encryptedData.length, decrypted, 0); + int length2 = cipher.doFinal(decrypted, length1); + byte[] finalDecrypted = new byte[length1 + length2]; + System.arraycopy(decrypted, 0, finalDecrypted, 0, finalDecrypted.length); + return new String(finalDecrypted, CHARSET).trim(); + } catch (Exception ex) { + ex.printStackTrace(); + } + return null; + } + + /** + * ʹÓÃĬÈÏÃÜÔ¿¼ÓÃÜ + * + * @param str ¼ÓÃÜÄÚÈÝ + * @return ÒÔStringÃÜÎÄÊäÈë, StringÃ÷ÎÄÊä³ö + */ + public static String encode(String str) { + return encode(DEFAULT_SECRET_KEY, str); + } + + /** + * ×Ô¶¨ÒåÃÜÔ¿¼ÓÃÜ + * + * @param key ×Ô¶¨ÒåÃÜÔ¿ + * @param str ¼ÓÃܵÄÄÚÈÝ + * @return StringÃ÷ÎÄÊäÈë, StringÃÜÎÄÊä³ö + */ + public static String encode(String key, String str) { + return encrypt(key, str); + } + + /** + * ʹÓÃĬÈÏÃÜÔ¿½âÃÜ + * + * @param str ½âÃÜÄÚÈÝ + * @return ÒÔStringÃÜÎÄÊäÈë, StringÃ÷ÎÄÊä³ö + */ + public static String decode(String str) { + return decode(DEFAULT_SECRET_KEY, str); + } + + /** + * ×Ô¶¨ÒåÃÜÔ¿½âÃÜ + * + * @param key ×Ô¶¨ÒåÃÜÔ¿ + * @param str ¼ÓÃÜÄÚÈÝ + * @return ÒÔStringÃÜÎÄÊäÈë, StringÃ÷ÎÄÊä³ö + */ + public static String decode(String key, String str) { + return decrypt(key, str); + } + + public static void main(def a){ + println encrypt( DEFAULT_SECRET_KEY, "²âÊÔ") + } +} diff --git a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/xiamen/RelatedTaiWanBatch.groovy b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/xiamen/RelatedTaiWanBatch.groovy index 25beca0a7..e44d4424e 100644 --- a/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/xiamen/RelatedTaiWanBatch.groovy +++ b/projects/fangjia-script/src/main/groovy/com/fangjia/script/gj/xiamen/RelatedTaiWanBatch.groovy @@ -15,9 +15,13 @@ import com.mongodb.DBCollection /** * ÏÃÃÅÉæÌ¨Ô°ÇøÊý¾Ýͬ²½ */ + + @BatchOwner(Watcher.GaoJuan) class RelatedTaiWanBatch extends BaseBatch{ + + def curDate = Integer.parseInt(DateUtils.formatDateByPattern(new Date(), "yyyyMM")); DBCollection yuanqu_qiye_coll = MongoUtils.getCollectionByName("crawl", "qzd_shetai_company_detail", "192.168.0.206", 27020) @@ -28,6 +32,8 @@ class RelatedTaiWanBatch extends BaseBatch{ def zimaoqu_datas = ["Öйú£¨¸£½¨£©×ÔÓÉóÒ×ÊÔÑéÇøÏÃÃÅÆ¬Çø","Öйú£¨¸£½¨£©×ÔÓÉóÒ×ÊÔÑéÇø¸£ÖÝÆ¬Çø","Öйú£¨¸£½¨£©×ÔÓÉóÒ×ÊÔÑéÇøÆ½Ì¶Æ¬Çø"] + + static main(args) { runBatch(new RelatedTaiWanBatch(), args); } @@ -37,14 +43,10 @@ class RelatedTaiWanBatch extends BaseBatch{ def day = new Date().getDate() if(day == 10){ - //createDatas() //ÆóÒµ¿â»ñÈ¡ÉæÌ¨Ô°ÇøÆóÒµ +// createDatas() //ÆóÒµ¿â»ñÈ¡ÉæÌ¨Ô°ÇøÆóÒµ updateRangeByPoint() //¸ü¸ÄÆóÒµËùÔÚ×ÔÃ³Çø export() //µ¼³öÊý¾Ý } -// else{ -// exportEmptyFile() -// } - } @@ -153,10 +155,18 @@ class RelatedTaiWanBatch extends BaseBatch{ } def allDatas = [] allDatas.addAll(rows) -// FileUtils.batchCreateFile(rows, fileName, null, "utf-8", false); - FileUtils.batchCreateFileByCustomSuffix(rows, fileName, null, "utf-8", false, "|@|","|+|"); + + //Ô­²»¼ÓÃÜ֮ǰ +// FileUtils.batchCreateFileByCustomSuffix(rows, fileName, null, "utf-8", false, "|@|","|+|"); +// XmBankFtpUtils.ftpUpload(fileName, curDate) + + + def str1 = FileUtils.createFileStringByCustomSuffix(rows, fileName, "utf-8", "|@|","|+|"); + def str1_encryptedText = CryptoSm4Util.encrypt( CryptoSm4Util.DEFAULT_SECRET_KEY, str1) + FileUtils.createEncryptFile(fileName, str1_encryptedText, false) XmBankFtpUtils.ftpUpload(fileName, curDate) + def fileName2 = "/home/goojia/xmbank/free_trade_zone_${curDate}_init.dat.rdy" if(CommonDatautils.isWindow()){ fileName2 = "D:\\Êý¾Ý\\ÏÃÃÅ\\ÉæÌ¨Ô°Çø\\free_trade_zone_${curDate}_init.dat.rdy" @@ -182,4 +192,7 @@ class RelatedTaiWanBatch extends BaseBatch{ FileUtils.batchCreateFileByCustomSuffix([rdy_datas], fileName2, null, "utf-8", false, "","|+|"); XmBankFtpUtils.ftpUpload(fileName2, curDate) } + + + }