代码demo

demo

php代码demo

<?php
$secret='yVttM7eAii1jHvVmnAsmAadp4uef4eJ9nLknDEMRLwU';
$url = 'https://all.atpay.vg/api/order/repay/create';
$param=array(
  'sn'=>'abc',
  'amount'=>10000,
  'channel'=>'country_repay_pakistan',
  'uid'=>'121323434563456',
  'city'=>'',
  'phone'=>null
);
function checkEmpty($value) {
  if (!isset($value))
    return true;
  if ($value === null)
    return true;
  if (trim($value) === "")
    return true;
  return false;
}
function getSignContent($params) {
  ksort($params);
  
  $stringToBeSigned = "";
  $i = 0;
  foreach ($params as $k => $v) {
    if (false === checkEmpty($v) && "@" != substr($v, 0, 1)) {
      if ($i == 0) {
        $stringToBeSigned .= "$k" . "=" . "$v";
      } else {
        $stringToBeSigned .= "&" . "$k" . "=" . "$v";
      }
      $i++;
    }
  }

  unset ($k, $v);
  return $stringToBeSigned;
}
$preSignStr=getSignContent($param);
$sign = hash_hmac('sha256', $preSignStr, $secret, false);
$param['sign']=$sign;
$body=json_encode($param);

$headers = array(
    "Content-Type: application/json;charset=UTF-8"
);
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL,$url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_TIMEOUT, 60);
curl_setopt($ch, CURLOPT_HTTPHEADER, $headers);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $body);
$data = curl_exec($ch);

var_dump($data);
curl_close($ch);
?>

java代码demo

Last updated