如何在PHP中使用SHA256和HMAC计算签名

时间:2019-09-25 14:05:59

标签: php sha256 hmac

我需要使用PHP中的SHA 256和HMAC计算签名,以验证和匹配webhook中提供的签名。以下是我们的付款服务提供商文档中的示例,我不知道如何在PHP中实现。

joined_payload = “event_typeORDER.PAYMENT.RECEIVEDresourceamount10.8200resourcecurrencyEURresourcereference1400012634statecompleted"

signed_payload  = :crypto.hmac(:sha256, secret, joined_payload)
signature = Base.encode16(signed_payload, case: :lower)

这是我到目前为止尝试过的但没有成功

$original_sign = "b34dc6cdc08066a34df0e24a6288a45ead05873229e8086b59f30d1a9d3cfdb2";
$joined_payload = "event_typeRDER.PAYMENT.CANCELLEDresourceamount5.00currencyEURreference31725statecancelled";
$signed_payload = hash_hmac('sha256', $joined_payload, CLIENT_SECRET);
$generated_sign1 = base_convert($signed_payload,10,16);

0 个答案:

没有答案