<?php | |
class Payjs | |
{ | |
private $url = 'https://payjs.cn/api/native'; | |
private $key = ''; // 填写通信密钥 | |
private $mchid = ''; // 特写商户号 | |
public function __construct($data=null) { | |
$this->data = $data; | |
} | |
public function pay(){ | |
$data = $this->data; | |
$data['mchid'] = $this->mchid; | |
$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; | |
} | |
} | |
$arr = [ | |
'body' => 'test', // 订单标题 | |
'out_trade_no' => time(), // 订单号 | |
'total_fee' => 120, // 金额,单位:分 | |
]; | |
$payjs = new Payjs($arr); | |
$rst = $payjs->pay(); | |
print_r($rst); | |
?> |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment