CollectAsynchronousNotifications

# CollectAsynchronousNotifications

  • Please note: The current collection service will only have a callback notification when the order is successfully paid
  • When verifying the signature, you need to use the platform public key provided in the merchant background - payment collection and payment configuration - API configuration for decryption!!
  • AFTER ACCEPTING THE ASYNCHRONOUS NOTIFICATION, YOU RESPOND WITH THE SUCCESS STRING
  • Otherwise, TopPay will continue to send out 5 notifications

import com.google.gson.JsonObject;

public class TopPayNotify {
    // testAccount
    private static final String MCH_NO = "PHOT000001";  // 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) {
            // ... The signature is verified and the normal business logic is processed
        } else {
            // ... signatureVerificationError
        }
    }
}

<?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
method method Requested method
name customerName Neo
amount amount 100000
fee theAmountOfTheHandlingFee 500
customerName customerName [email protected]
customerEmail customerEmail 123456798
customerPhone customerPhone 123456798
status status SUCCESS , refer to order status
version version 1
sign signature ja6R8eukQY9jc8zrhtf34654ungj7u8sdgdfjfs