1

我在数据库中保存数据时遇到错误,因为 webhook(instamojo) url 不适用于我的代码。

我们如何重定向到 webhook 页面以及 codeigniter 框架的 webhook 格式是什么。

我正在使用 instamojo 支付网关

$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, 'https://test.instamojo.com/api/1.1/payment-requests/');
curl_setopt($ch, CURLOPT_HEADER, FALSE);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, TRUE);
curl_setopt($ch, CURLOPT_FOLLOWLOCATION, TRUE);
curl_setopt($ch, CURLOPT_HTTPHEADER,  array("X-Api-Key:test_12345", "X-Auth-Token:test_asbcs"));
$payload = Array(
  'purpose' => $username,
  'amount' => $this->input->post('amount'), 
  'phone' => , 
  'buyer_name' => $username,
  'redirect_url' => 'url',
  'send_email' => true,
  'webhook' => 'url',
  'send_sms' => true,
  'email' => $this->input->post('email'),  
  'allow_repeated_payments' => false,
);
curl_setopt($ch, CURLOPT_POST, true);
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($payload));
$response = curl_exec($ch);
curl_close($ch); 
$json_decode = json_decode($response, true);
$long_url = $json_decode['payment_request']['longurl'];
header('Location:'.$long_url);

这是我在 webhook 页面中使用的 webhook 代码。请帮我解决这个问题。提前致谢

$data = $_POST;
$mac_provided = $data['mac'];
unset($data['mac']);
$ver = explode('.', phpversion());
$major = (int) $ver[0];
$minor = (int) $ver[1];
if($major >= 5 and $minor >= 4){
  ksort($data, SORT_STRING | SORT_FLAG_CASE);
} else {
  uksort($data, 'strcasecmp');
}
$mac_calculated = hash_hmac("sha1", implode("|", $data), "salt key");
if($mac_provided == $mac_calculated){
  if($data['status'] == "Credit"){
    database query ---
    return true;
  } else{
    return false;
  }
} else{ 
  return false;
}
4

0 回答 0