CollectionAsynchronousNotifications

# CollectionAsynchronousNotifications

  • Please note: The current business only has callback notification reception when the order is successfully paid.

  • When performing signature verification, use the platform public key provided in Merchant Platform - Collection and Payment Configuration - API Configuration for decryption!!!

  • Digital currency has two special situations: no order mode and payment amount does not match the order amount. For this reason, we have adjusted the asynchronous notification as follows:

  • 1. If it is the above special situation, we will generate a new successful order for notification. You need to verify according to the notification information and generate a new order.

  • 2. Query whether the order exists in your system according to the merchant order number (orderNum) in the notification. It is recommended that you also store our platform order number (platOrderNum) when the order is successfully placed for double verification.

  • 3. Judge according to the parameter specialStatus (0-default, 1-special) in the notification. If it is 1, it is judged as the above special situation.

  • After TopPay result asynchronous notification, you need to respond with the SUCCESS string

  • Otherwise, TopPay will continue to initiate 5 notifications downstream


import com.google.gson.JsonObject;

public class TopPayNotify {
  // testAccount
  private static final String MCH_ID = "PH0000001";  // merchantNumber
  private static final String PLAT_PUBLIC_KEY = "MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQC2JoMfFqLsSJjAiCahEnlP3aRj8yCT+WHzR+VvPBTw9S1i7iYWb+MY09CG/HYuHF4+IxshXDJygmndxKf/esuwPybS8mAd//yubHpmZsmBqg1FffT8VH1APa6ZRWASUp4U01ZrbCCp35QA8FuWrJGMJxGx4xk7KUtV2yujxC8noQIDAQAB";  // platformPublicKey
  public static void main(String[] args) throws Exception {
    // collection
    JsonObject notifyBody = new jsonObject();
    boolean verifyResult = TopPayRequestUtil.verifySign(notifyBody,PLAT_PUBLIC_KEY);
    if (verifyResult) {
      // ... Signature verification passed, process normal business logic
    } else {
      // ... Signature verification error
    }
  }
}

<?php

$res = json_decode(file_get_contents('php://input'), true);
$platSign = $res['platSign'];
unset($res['platSign']);
$public_key = 'MIGfMA0GCSqGSIb3DQEBAQUAA4GNADCBiQKBgQDFJ/AmUV4Z8udG8aOBUt/kEwc/DbxF5Gtfw6Y00NHQ4Pz2X2x9IxjUZxn2dnFxmrmhqKNlfwXOqyejhBzi0pSHyGoI4XP9IEfZGO6YkSb9DCY1ZxX8fDl2G+tPCbWYTVO4JutFmzTWgk1Uhhu6L9dlOMUHvZf3/6czA/a9C7azXwIDAQAB';
$decryptSign = public_key_decrypt($platSign, $public_key);

$params = $res;
ksort($params);
$params_str = '';
foreach ($params as $key => $val) {
    $params_str = $params_str . $val;
}

if($params_str == $decryptSign) {
    if($res['code'] == '00') {
        echo 'success';
    }
    else {
        echo 'fail';
    }
}
else {
    echo 'fail';
}

function public_key_decrypt($data, $public_key)
{
    $public_key = '-----BEGIN PUBLIC KEY-----'."\n".$public_key."\n".'-----END PUBLIC KEY-----';
    $data = base64_decode($data);
    $pu_key =  openssl_pkey_get_public($public_key);
    $crypto = '';
    foreach (str_split($data, 128) as $chunk) {
        openssl_public_decrypt($chunk, $decryptData, $pu_key);
        $crypto .= $decryptData;
    }

    return $crypto;
}

# NotificationParameters

parameters describe example
platOrderNum platOrderNum BK_1563278763273
orderNum merchantOrderNumber T1231511321515
mchNo mchNo PH0000001
amount amount 100000
fee theAmountOfTheHandlingFee 500
status status SUCCESS , refer to order status
hashCode hashCode 5e5c356af0ewrhgnf3d757h8a6a5506cc66354620
sendAddress sendAddress TDBbbeAB32WE576DVGE82GEC5BhsZs4
inAddress inAddress TDBbbeAB32WE576DVGE82GEC5BhsZs4
mchUserId merchantUserId M00001
specialStatus specialStatus(0-default,1-special) 0
currency currency USDT
netWork netWork TRC20
version version 1
sign signature ja6R8eukQY9jc8zrhtf34654ungj7u8sdgdfjfs