Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
You can’t perform that action at this time.