ECPay / Logistic_Java

綠界科技 物流整合介接JAVA 第一版
3 stars 3 forks source link

Why API not return data as JSON format? #5

Open daotq2000 opened 2 years ago

daotq2000 commented 2 years ago

Hi development team, I have try implement and run your source code but I face with a problem. Data is not return as json format. It return like createTestData:

How I can get data with json format. Thank for help. Hope you can reply soon.

AllennChang commented 2 years ago

Hi, daotq2000,
Thank you for your response, Regarding the way to send back json format, Please refer to https://www.ecpay.com.tw/Content/files/ecpay_030.pdf?v=960 .

daotq2000 commented 2 years ago

Thank you [Allen Cheng, How Can I find all list store address of 7-eleven ? Do you suggest for me?

AllennChang commented 2 years ago

Thank you [Allen Cheng, How Can I find all list store address of 7-eleven ? Do you suggest for me?

The list of all 7-eleven store addresses exists at 7-eleven, we are calling the 7-eleven API to redirect to the 7-eleven page for customer selection.

daotq2000 commented 2 years ago

Thank you. I can find it on https://www.ecpay.com.tw/Content/files/ecpay_030.pdf?v=960, right? One more time I have try example on your document but I found this error. Request: { "MerchantID": "2000132", "RqHeader": { "Timestamp": "1647400651", "Revision": "1.0.0" }, "Data":"{\"TempLogisticsID\":\"0\",\"GoodsAmount\":500,\"IsCollection\":\"Y\",\"GoodsName\":\"商品名\",\"SenderName\":\"王小明\",\"SenderZipCode\":\"123\",\"SenderAddress\":\"xxxxxxxx\",\"Remark\":\"xxx\",\"ServerReplyURL\":\"https://xxxx.com/xxx\",\"ClientReplyURL\":\"https://xxxx.com/yyy\",\"Temperature\":\"0001\",\"Specification\":\"0001\",\"ScheduledPickupTime\":\"4\",\"PackageCount\":1,\"ReceiverAddress\":\"xxxxxxxx\",\"ReceiverCellPhone\":\"09xxxxxxxx\",\"ReceiverPhone\":\"xxxxxxxx\",\"ReceiverName\":\"陳小明\",\"EnableSelectDeliveryTime\":\"Y\",\"EshopMemberID\":\"xxxxyyyy123\"}" } Response : { "PlatformID": "", "MerchantID": "2000132", "RpHeader": { "Timestamp": "1647400657" }, "TransCode": 712, "TransMsg": "解密失敗", "Data": "" } How I can fixed it? Thank your support. Hope I can have your linkedin or whatapp to discuss with you.

erictseng618 commented 2 years ago

Hello, the data in Data must be encrypted before transmission, the encryption method can be referred to page 74 of the document, in addition, we do not have Linkedin or Whatsapp

erictseng618 commented 2 years ago

Green World will provide the Key and IV for AES encryption, please encrypt the data with URL Encode first, then AES encryption. The strength setting of AES encryption is 128 bit, CipherMode : CBC, PaddingMode :PKCS7

daotq2000 commented 2 years ago

Thank you so much. How I can find your contact? I have pin my facebook on link below. https://www.facebook.com/daotq2 Nice to meet you.

daotq2000 commented 2 years ago

Thank you. Hi team, Can you help check? I encryption data but it's not correct format GreenWorld. This is Java code. `package com.yingcan.verification;

import java.io.UnsupportedEncodingException; import java.security.*; import java.security.spec.AlgorithmParameterSpec; import java.util.Base64;

import javax.crypto.*; import javax.crypto.spec.IvParameterSpec; import javax.crypto.spec.SecretKeySpec;

public class Test { static String plainText = "{\"Name\":\"Test\",\"ID\":\"A123456789\"}";

public static void main(String[] args) throws Exception
{
    KeyGenerator keyGenerator = KeyGenerator.getInstance("AES");
    keyGenerator.init(128);

    // Generate Key
    SecretKey key = keyGenerator.generateKey();

    // Generating IV.
    byte[] IV = new byte[16];
    SecureRandom random = new SecureRandom();
    random.nextBytes(IV);

    System.out.println("Original Text  : "+plainText);

    byte[] cipherText = encrypt(plainText.getBytes(),key, IV);
    System.out.println("Encrypted Text : "+Base64.getEncoder().encodeToString(cipherText) );

    String decryptedText = decrypt(cipherText,key, IV);
    System.out.println("DeCrypted Text : "+decryptedText);

}

public static byte[] encrypt (byte[] plaintext,SecretKey key,byte[] IV ) throws Exception
{
    //Get Cipher Instance
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

    //Create SecretKeySpec
    SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "AES");

    //Create IvParameterSpec
    IvParameterSpec ivSpec = new IvParameterSpec(IV);

    //Initialize Cipher for ENCRYPT_MODE
    cipher.init(Cipher.ENCRYPT_MODE, keySpec, ivSpec);

    //Perform Encryption
    byte[] cipherText = cipher.doFinal(plaintext);

    return cipherText;
}

public static String decrypt (byte[] cipherText, SecretKey key, byte[] IV) throws Exception
{
    //Get Cipher Instance
    Cipher cipher = Cipher.getInstance("AES/CBC/PKCS5Padding");

    //Create SecretKeySpec
    SecretKeySpec keySpec = new SecretKeySpec(key.getEncoded(), "AES");

    //Create IvParameterSpec
    IvParameterSpec ivSpec = new IvParameterSpec(IV);

    //Initialize Cipher for DECRYPT_MODE
    cipher.init(Cipher.DECRYPT_MODE, keySpec, ivSpec);

    //Perform Decryption
    byte[] decryptedText = cipher.doFinal(cipherText);

    return new String(decryptedText);
}

} ` Original Text : {"Name":"Test","ID":"A123456789"} Encrypted Text : YJUiix56pdUJsjCTKNmZklaPU8Frup2/SRgpnskgjeSDR7yUhkLF98Zd9cNVR17t DeCrypted Text : {"Name":"Test","ID":"A123456789"}

Payload: https://logistics-stage.ecpay.com.tw/Express/v2/RedirectToLogisticsSelection Request: { "MerchantID": "2000132", "RqHeader": { "Timestamp": "1647408629", "Revision": "1.0.0" }, "Data":"YJUiix56pdUJsjCTKNmZklaPU8Frup2/SRgpnskgjeSDR7yUhkLF98Zd9cNVR17t" } Response: { "PlatformID": "", "MerchantID": "2000132", "RpHeader": { "Timestamp": "1647408635" }, "TransCode": 712, "TransMsg": "解密失敗", "Data": "" } Thank you so much, Hope you can reply soon.

erictseng618 commented 2 years ago

Hello, what is your KEY and IV?

erictseng618 commented 2 years ago

Original Text : {"Name":"Test","ID":"A123456789"} Why your Encrypted Text is YJUiix56pdUJsjCTKNmZklaPU8Frup2/SRgpnskgjeSDR7yUhkLF98Zd9cNVR17t ? It should be uvI4yrErM37XNQkXGAgRgJAgHn2t72jahaMZzYhWL1HmvH4WV18VJDP2i9pTbC+tby5nxVExLLFyAkbjbS2Dvg== Please encrypt the data with URL Encode first.

daotq2000 commented 2 years ago

Hi erictseng618, Encrypted but can't passed. Payload: https://logistics-stage.ecpay.com.tw/Express/v2/RedirectToLogisticsSelection Request: { { "MerchantID": "2000132", "RqHeader": { "Timestamp": "1647417674", "Revision": "1.0.0" }, "Data":"uvI4yrErM37XNQkXGAgRgJAgHn2t72jahaMZzYhWL1HmvH4WV18VJDP2i9pTbC+tby5nxVExLLFyAkbjbS2Dvg==" } Response: { "PlatformID": "", "MerchantID": "2000132", "RpHeader": { "Timestamp": "1647417681" }, "TransCode": 712, "TransMsg": "解密失敗", "Data": "" } Can you help check again?

erictseng618 commented 2 years ago

Sorry, please use the following Key = 5294y06JbISpM5x9, Iv=v77hoKGq4kWxNNIS, for encryption, as provided on page 7 of the document

daotq2000 commented 2 years ago

Hi team, Could you help me share function encode and decode with ASC for Java? I have try many time but It's working in-correct. It's very urgent. Please help share java code function for encode and decode. Thank you so much

haohaotw commented 2 years ago

Hi @daotq2000 I hope you find this example helpful.

https://github.com/haohaotw/ecpay-invoice-java-api/blob/main/src/test/java/com/haohere/ecpay/invoice/ECPayInvoiceDemoTest.java