Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Payment Notify Verify is 0 #5

Open
sidealice opened this issue Apr 26, 2022 · 0 comments
Open

Payment Notify Verify is 0 #5

sidealice opened this issue Apr 26, 2022 · 0 comments

Comments

@sidealice
Copy link

sidealice commented Apr 26, 2022

We use alipay global's public key:(sandbox)
MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAtOcJhqk3mKhcGC0ARNjdFoZtYGEhfcgrUEUe9CF+sDzIJZMMVypRY67GoDQEdZTmHBPnVtsBRKNGSq4/h8r4BZ3XNE81K8CqwX0YzwqEvd0qlhyn9KzGCQF3Ps9wQRkPKdFzvmYcrW4WXmMOVMDg+XxuzNpXygqpxOJ++7Dpi8E6Ste0/ZtrJ2ACLIZVKCh951Cko25ePd2QyJpXq1g2jyWMRQVIapPp+t+UHG/4affBYI5GNREsxcXukg+SeymMlR2TwZvbyGYMlEb34icznLeD4jdkXOnU3pmkxYg2FmVCg0YujqrUL6yjQ648WkGruKFAyMkXC9inj9eZJwn8eQIDAQAB

And the notify verification is always 0.
Could you help to figure out the verify testing use case and we can check if code is correct?

e.g.

<?php

function verify($httpMethod, $path, $clientId, $rspTime, $rspBody, $signature, $alipayPublicKey)
{
    $rspContent = genSignContent($httpMethod, $path, $clientId, $rspTime, $rspBody);
    return verifySignatureWithSHA256RSA($rspContent, $signature, $alipayPublicKey);
}

function genSignContent($httpMethod, $path, $clientId, $timeString, $content)
{
    $payload = $httpMethod . " " . $path . "\n" . $clientId . "." . $timeString . "." . $content;
    return $payload;
}
function verifySignatureWithSHA256RSA($rspContent, $rspSignValue, $alipayPublicKey)
{
    $pubKey = "-----BEGIN PUBLIC KEY-----\n" .
        wordwrap($alipayPublicKey, 64, "\n", true) .
        "\n-----END PUBLIC KEY-----";
    if (
        strstr($rspSignValue, "=")
        || strstr($rspSignValue, "+")
        || strstr($rspSignValue, "/")
        || $rspSignValue == base64_encode(base64_decode($rspSignValue))
    ) {
        $originalRspSignValue = base64_decode($rspSignValue);
    } else {
        $originalRspSignValue = base64_decode(urldecode($rspSignValue));
    }
    $verifyResult = openssl_verify($rspContent, $originalRspSignValue, $pubKey, OPENSSL_ALGO_SHA256);
    return $verifyResult;
}
$httpMethod = "POST";
$path = "";
$clientId = "SANDBOX_5Y606G2YJPQB00270";
$rspTime = "2022-04-26T04:39:22Z";

$signature = "bc6MuaBUCbIgxG6fbGh6MHJP%2FqiI6lrosdnN8mEEunDRR3k5j8cjRbGI8fAeE%2Bibhu%2FN4JxjGGCY7c%2B%2FTM8kUdv8nTdHU2MERsBn3mRcFe4eBW%2BxtFLL2brYaKSc%2Bb3mwIA0icHoUpwirVbfl9RrUviMsEJtSFW14rzKVjqBvwNo4iqzkh%2B2UIjzx%2FI7pbrSinZcJNZdjmMRRReQAMsYcrGGrzR%2BPtUjS%2FwNtA8NVHHk2LUeTuwtDVt%2F2ZxrsVm6C%2FufIZ3dz4yInSoR6fRms2%2FP67lb9PSTq0LGNM9EcXhtb3gCWmfdPPrUUuqxuBgDFno7%2F2%2BaPcht3GKP%2FPNrAg%3D%3D";
$alipayPublicKey = "MIIBIjANBgkqhkiG9w0BAQEFAAOCAQ8AMIIBCgKCAQEAi1ltikGrnsmknSD/OYNQSMw485C/OF7Y9MVxHIDkbIWZm8JC9cuhdZbduTmx2AKeDmkYK73dbF1xZnZQGd38sSKAkiWOSbz15a0bfd/XMlcx5ICqjkWi6gMWYOgUBp1RLuHvisjicwb4fBIN7IPySGMvSFFgPspUUc6gY3HKJgP59KAUJR1WA7B7tPw0C/xhcRFKln0nsU7wzk7R4HhYzKua0BxV6mYYDxGbVepH5tJ5ZzSNVR3IGJRQc6c7+gU1F6z5Jc3V4NT7EHOmu7T888A+Uhec+4XymTVNkRZ+u6ZEj03oMwtv7NcQf2z8Kcp1/VeyOg7toXoQjNtH2oEIWQIDAQAB";
$rspBody = '{
    "notifyType": "PAYMENT_RESULT",
    "result": {
        "resultCode": "SUCCESS",
        "resultStatus": "S",
        "resultMessage": "success"
    },
    "paymentRequestId": "20200101234567890444",
    "paymentId": "20200101234567890132",
    "paymentAmount": {
        "value": "8000",
        "currency": "EUR"
    },
    "actualPaymentAmount": {
        "value": "8000",
        "currency": "EUR"
    },
    "paymentCreateTime": "2020-01-01T12:01:00+08:30",
    "paymentTime": "2020-01-01T12:01:01+08:30"
}';
echo (int) verify($httpMethod, $path, $clientId, $rspTime, $rspBody, $signature, $alipayPublicKey);

the above data is from alipay global's inotify testing data.
All fields is copied at alipay's console except path field, according to the API document notify need to fill the path filed. Could you help me to check if path is needed and how to fill this field when we verify the notification from the payment transaction(async) .

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant