118 lines
2.9 KiB
PHP
118 lines
2.9 KiB
PHP
<?php
|
|
namespace ThirdPay;
|
|
|
|
use ThirdPay\KeyFormat;
|
|
use ThirdPay\KeyWorker;
|
|
use ThirdPay\Tools;
|
|
/**
|
|
* 修改版第3方支付
|
|
**/
|
|
|
|
class YueKaiPay
|
|
{
|
|
public $merNo = ""; //商户编号
|
|
public $merAccount = "";//商户标识
|
|
public $privateKey = "";//秘钥
|
|
public $publicKey = ""; //公钥
|
|
public $domain = ""; //接口域名地址
|
|
|
|
public function __construct($merNo,$merAccount,$privateKey,$publicKey,$domain){
|
|
$this->merNo = $merNo;
|
|
$this->merAccount = $merAccount;
|
|
$this->privateKey = $privateKey;
|
|
$this->publicKey = $publicKey;
|
|
$this->domain = $domain;
|
|
}
|
|
|
|
public function order($param){
|
|
$data = array(
|
|
'merAccount' => $this->merAccount,//商户标识
|
|
'merNo' => $this->merNo,//商户编号
|
|
'time' => time(),//时间戳
|
|
'orderId' => $param['order'],//订单号
|
|
'amount' => $param['money'],//交易金额(分)
|
|
'product' => $param['product'],//商品
|
|
'productDesc' => $param['productDesc'],//商品描述
|
|
'payWay' => $param['payWay'],
|
|
'payType' => $param['payType'],
|
|
'openId' =>$param['openId'],
|
|
'userIp' => Tools::get_client_ip(),
|
|
'returnUrl' => $param['returnUrl'],//前端页面回调地址
|
|
'notifyUrl' => $param['notifyUrl'],//后台回调地址
|
|
);
|
|
|
|
//签名信息
|
|
$data['sign'] = $this->getSign($data,$this->privateKey);
|
|
//var_dump(cookie('PAY_REFERER'));exit;
|
|
//用密钥去加密
|
|
$encode_data = Tools::encryptData($data,$this->privateKey);
|
|
|
|
$post_data = array(
|
|
'merAccount' => $this->merAccount,//商户标识
|
|
'data' => $encode_data
|
|
);
|
|
|
|
$ret = $this->http($this->domain,$post_data);
|
|
$retjson = json_decode($ret,true);
|
|
|
|
if($retjson["code"] =="000000"){
|
|
if($this->checkSign($retjson["data"],$this->publicKey)){
|
|
return $retjson;
|
|
} else {
|
|
return json_encode(array("code"=>"100004","msg"=>"签名验证错误!"));
|
|
}
|
|
}else{
|
|
return $retjson;
|
|
}
|
|
}
|
|
|
|
public function http($url,$post_data){
|
|
$ch = curl_init($url);
|
|
$timeout = 6000;
|
|
curl_setopt($ch, CURLOPT_POST, 1);
|
|
curl_setopt($ch, CURLOPT_HEADER,0 );
|
|
curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
|
|
curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
|
|
curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
|
|
curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
|
|
curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); //
|
|
curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
|
|
$ret = curl_exec($ch);
|
|
curl_close($ch);
|
|
return $ret;
|
|
}
|
|
|
|
|
|
//签名方式
|
|
public function getSign($params,$signKey){
|
|
ksort($params);
|
|
$data = "";
|
|
foreach ($params as $key => $value) {
|
|
$data .= trim($value);
|
|
}
|
|
$sign = strtoupper(md5($data.$signKey));
|
|
return $sign;
|
|
}
|
|
|
|
//验签
|
|
public function checkSign($params,$signKey){
|
|
ksort($params);
|
|
$psign = "";
|
|
$data = "";
|
|
foreach ($params as $key => $value) {
|
|
if($key == "sign") {
|
|
$psign = $value;
|
|
} else {
|
|
$data .= $value;
|
|
}
|
|
}
|
|
$sign = strtoupper(md5($data.$signKey));
|
|
if($psign == $sign) {
|
|
return true;
|
|
} else {
|
|
return false;
|
|
};
|
|
}
|
|
|
|
|
|
} |