如何在php中获取ascii键的rave参数

时间:2017-10-11 18:10:53

标签: php payment-gateway payment flutterwave

Ravepay文档(https://flutterwavedevelopers.readme.io/docs/checksum)展示了如何使用Nodejs散列值,但是我遇到了生成getpaidSetup键的正确排序顺序的问题,我该如何在php中执行此操作。

目前这是我的实施:


/**
 * Growerprojection
 *
 * @ORM\Table(name="growerProjection")
 * @ORM\Entity
 */
class Growerprojection
{
    /** 
     * @ORM\Id
     * @ORM\ManyToOne(targetEntity="Crop")
     * @ORM\JoinColumn(name="crop_ID", referencedColumnName="crop_ID")
     */
    private $crop;

    ...

}

更新

  

根据GentlemanMax对ksort的回答,我在阵列上运行了一个ksort,   将它与Javascript等效结果进行比较   // In php $amount_in_naira = $_POST['total'] * 400; $customer_email = $_POST['email']; $customer_firstname = $_POST['fullname']; $txref = 'EX' . '_' . get_current_user_id() . '_' . time(); $integity_str = $pb_key . $amount_in_naira . $customer_email . $txref . $sc_key; $hash = hash( 'sha256', $integity_str ); // JS var options = { PBFPubKey: '<?php echo $pb_key; ?>', amount: <?php echo $amount_in_naira; ?>, customer_email: '<?php echo $customer_email; ?>', customer_firstname: '<?php echo $customer_firstname; ?>', txref: '<?php echo $txref; ?>', integity_hash: '<?php echo hash( 'sha256', $integity_str ); ?>', meta: [{ metaname: 'merchant_details', metavalue: '<?php echo $metadata; ?>' }], onclose: function() {}, callback: function(res) { console.log(res); }, } 并且结果匹配,请参阅示例脚本   下面显示如何使用Ksort按ASCII排序。

object.keys({payload}).sort()

1 个答案:

答案 0 :(得分:1)

PHP中的

ksort()将在js中执行与Object.keys({object}).sort()类似的操作。最显着的区别是ksort()对数组进行“就地”排序。

假设您的代码中的字段是您使用的唯一字段,这将满足您的需求:

$options = array(
    'PBFPubKey' => $pb_key,
    'amount' => $amount_in_naira,
    'customer_email' => $customer_email,
    'customer_firstname' => $customer_firstname,
    'txref' => $txref,
);
ksort($options);
$hashedPayload = '';
foreach($options as $option){
    $hashedPayload += $option;
}

$hashedPayload现在包含正确的散列顺序的字符串(未散列)。看起来你只需要在这一点上做一个字符串的sha256哈希。如果您需要有关该部分的帮助,请告诉我。