Skip to content

Instantly share code, notes, and snippets.

@payjscn
Last active April 9, 2019 19:20
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save payjscn/8759b682fbbca89cb395f4fb8fe8d9d1 to your computer and use it in GitHub Desktop.
Save payjscn/8759b682fbbca89cb395f4fb8fe8d9d1 to your computer and use it in GitHub Desktop.
PAYJS 退款接口 PHP DEMO
<?php
class Payjs
{
private $url = 'https://payjs.cn/api/refund';
private $key = ''; // 填写通信密钥
private $mchid = ''; // 特写商户号
public function __construct($payjs_order_id=null) {
$this->payjs_order_id = $payjs_order_id;
}
public function refund(){
$data = array();
$data['payjs_order_id'] = $this->payjs_order_id;
$data['sign'] = $this->sign($data);
return $this->post($data, $this->url);
}
public function post($data, $url) {
$ch = curl_init();
curl_setopt($ch, CURLOPT_URL, $url);
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
curl_setopt($ch, CURLOPT_POST, 1);
curl_setopt($ch, CURLOPT_POSTFIELDS, $data);
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false);
curl_setopt($ch, CURLOPT_SSL_VERIFYHOST, 0);
$rst = curl_exec($ch);
curl_close($ch);
return $rst;
}
public function sign(array $attributes) {
ksort($attributes);
$sign = strtoupper(md5(urldecode(http_build_query($attributes)) . '&key=' . $this->key));
return $sign;
}
}
$payjs_order_id = '2019***********'; // 订单号
$payjs = new Payjs($payjs_order_id);
$rst = $payjs->refund();
print_r($rst);
?>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment