You cannot select more than 25 topics
Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.
190 lines
8.4 KiB
PHP
190 lines
8.4 KiB
PHP
<?php
|
|
namespace Org\HeepaySDK;
|
|
use Think\Exception;
|
|
|
|
class Heepay {
|
|
|
|
// iOS微信SDK
|
|
public function heepay_pay($pay){
|
|
/*************创建签名***************/
|
|
$sign_str = '';
|
|
$sign_str = $sign_str . 'version=' . 1;
|
|
$sign_str = $sign_str . '&agent_id=' . $pay['agent_id'];
|
|
$sign_str = $sign_str . '&agent_bill_id=' . $pay['order_no'];
|
|
$sign_str = $sign_str . '&agent_bill_time=' . $pay['time'];
|
|
$sign_str = $sign_str . '&pay_type=' . $pay['pay_type'];
|
|
$sign_str = $sign_str . '&pay_amt=' . $pay['amount'];
|
|
$sign_str = $sign_str . '¬ify_url=' . $pay['notify_url'];
|
|
$sign_str = $sign_str . '&user_ip=' . $pay['user_ip'];
|
|
$sign_str = $sign_str . '&key=' . $pay['sign_key'];//密钥
|
|
$sign = md5($sign_str); //签名值
|
|
|
|
$data=array(
|
|
'version'=>1,
|
|
'agent_id'=>$pay['agent_id'],//商户号
|
|
'agent_bill_id'=>$pay['order_no'],//订单号
|
|
'agent_bill_time'=>$pay['time'],//date('YmdHis', time()) 时间
|
|
'pay_type'=>$pay['pay_type'],//支付类型
|
|
'pay_amt'=>$pay['amount'],//支付金额
|
|
'notify_url'=>"http://".$_SERVER['HTTP_HOST']."/callback.php/Notify/heepay_callback",//通知地址
|
|
'return_url'=>"http://",
|
|
'user_ip'=>$pay['user_ip'],//用户ip
|
|
'goods_name'=>$pay['payerName'],//商品名
|
|
'goods_num'=>$pay['number'],//商品数量
|
|
'goods_note'=>$pay['goods_note'],//说明
|
|
'remark'=>"",//备注
|
|
'sign'=>$sign,
|
|
);
|
|
$xml=$this->request_post("https://pay.heepay.com/Phone/SDK/PayInit.aspx",$data);
|
|
$string=explode("<token_id>",$xml);
|
|
$token_id=explode("</token_id>",$string[1]);
|
|
return $token_id[0];
|
|
}
|
|
public function wxh5_pay($pay){
|
|
$pay['pay_type'] = 30;
|
|
return $this->h5_pay($pay);
|
|
}
|
|
public function alih5_pay($pay){
|
|
$pay['pay_type'] = 22;
|
|
return $this->h5_pay($pay);
|
|
}
|
|
|
|
// 汇付宝 微信H5
|
|
public function h5_pay($pay){
|
|
/*************创建签名***************/
|
|
$sign_str = '';
|
|
$sign_str = $sign_str . 'version=1';
|
|
$sign_str = $sign_str . '&agent_id=' . $pay['agent_id'];
|
|
$sign_str = $sign_str . '&agent_bill_id=' . $pay['order_no'];
|
|
$sign_str = $sign_str . '&agent_bill_time=' . $pay['time'];
|
|
$sign_str = $sign_str . '&pay_type=' . $pay['pay_type'];
|
|
$sign_str = $sign_str . '&pay_amt=' . $pay['amount'];
|
|
$sign_str = $sign_str . '¬ify_url='.$pay['notify_url'];
|
|
$sign_str = $sign_str . '&return_url='.$pay['return_url'];
|
|
$sign_str = $sign_str . '&user_ip='. $pay['user_ip'];//str_replace('.', '-', $pay['user_ip']);
|
|
$sign_str = $sign_str . '&bank_card_type='. $pay['bank_card_type'];
|
|
$sign_str = $sign_str . '&remark=' . $pay['remark'];
|
|
$sign_str = $sign_str . '&key=' . $pay['sign_key'];//密钥
|
|
$sign = strtolower(md5($sign_str)); //签名值
|
|
// var_dump($sign, $sign_str);
|
|
if ($pay['device'] == 'ios') {
|
|
$meta_option = '{"s":"IOS","n":"应用在App Store中唯一应用名","id":"IOS应用唯一标识"}';
|
|
} else if ($pay['device'] == 'android'){
|
|
$meta_option= '{"s":"Android","n":"帝王的纷争(安卓版)","id":"应用在一台设备上的唯一标识在manifest文件里面的声明"}';
|
|
} else if ($pay['device'] == 'wap') {
|
|
$meta_option = '{"s":"WAP","n":"chengfeng123.cn","id":"chengfeng123.cn"}';
|
|
}
|
|
|
|
$meta_option = urlencode(base64_encode(iconv("UTF-8", "gb2312//IGNORE", $meta_option)));
|
|
$data=array(
|
|
'version'=>1,
|
|
'scene' => 'h5',
|
|
'pay_type'=> $pay['pay_type'],//支付类型
|
|
'agent_id'=>$pay['agent_id'],//商户号
|
|
'agent_bill_id'=>$pay['order_no'],//订单号
|
|
'pay_amt'=>$pay['amount'],//支付金额
|
|
'notify_url'=> $pay['notify_url'],//通知地址
|
|
'return_url' => $pay['return_url'],
|
|
'user_ip'=>$pay['user_ip'],//用户ip
|
|
'agent_bill_time'=>$pay['time'],//date('YmdHis', time()) 时间
|
|
'goods_name' => $pay['payerName'],//商品名
|
|
'remark'=> $pay['remark'],//备注
|
|
// 'goods_num' => $pay['number'],//商品数量
|
|
'goods_note'=>$pay['goods_note'],//说明
|
|
'payment_mode' => 'cashier',
|
|
'meta_option' => $meta_option,
|
|
'bank_card_type' => $pay['bank_card_type'],
|
|
'sign'=>$sign,
|
|
);
|
|
$xml=$this->request_post("https://Pay.Heepay.com/DirectPay/applypay.aspx", $data);
|
|
$xmls =simplexml_load_string($xml);
|
|
$url = simplexml_load_string($xmls.redirectUrl);
|
|
$xmljson= json_encode($xmls);
|
|
$ret=json_decode($xmljson,true);
|
|
// return $ret;
|
|
|
|
$string=explode("<redirectUrl><![CDATA[",$xml);
|
|
// pp($xml);
|
|
$token_id=explode("]]></redirectUrl>",$string[1]);
|
|
$ret['url']= $token_id[0];
|
|
return $ret;
|
|
}
|
|
|
|
/* // 汇付宝 aliH5
|
|
public function alih5_pay($pay){
|
|
$sign_str = '';
|
|
$sign_str = $sign_str . 'version=1';
|
|
$sign_str = $sign_str . '&agent_id=' . $pay['agent_id'];
|
|
$sign_str = $sign_str . '&agent_bill_id=' . $pay['order_no'];
|
|
$sign_str = $sign_str . '&agent_bill_time=' . $pay['time'];
|
|
$sign_str = $sign_str . '&pay_type=22';
|
|
$sign_str = $sign_str . '&pay_amt=' . $pay['amount'];
|
|
$sign_str = $sign_str . '¬ify_url='.$pay['notify_url'];
|
|
$sign_str = $sign_str . '&return_url='.$pay['return_url'];
|
|
$sign_str = $sign_str . '&user_ip='. str_replace($pay['user_ip'], "_", ".");
|
|
$sign_str = $sign_str . '&key=' . $pay['sign_key'];//密钥
|
|
$sign = strtolower(md5($sign_str)); //签名值
|
|
// var_dump($sign, $sign_str);
|
|
|
|
$data=array(
|
|
'version'=>1,
|
|
'is_phone' => '1',
|
|
'pay_type'=> 22,//支付类型
|
|
'agent_id'=>$pay['agent_id'],//商户号
|
|
'agent_bill_id'=>$pay['order_no'],//订单号
|
|
'pay_amt'=>$pay['amount'],//支付金额
|
|
'notify_url'=> $pay['notify_url'],//通知地址
|
|
'return_url' => $pay['return_url'],
|
|
'user_ip'=>str_replace($pay['user_ip'], "_", "."),//用户ip
|
|
'agent_bill_time'=>$pay['time'],//date('YmdHis', time()) 时间
|
|
'goods_name' => $pay['payerName'],//商品名
|
|
'remark'=> $pay['remark'],//备注
|
|
// 'goods_num' => $pay['number'],//商品数量
|
|
'goods_note'=>$pay['goods_note'],//说明
|
|
'sign'=>$sign,
|
|
);
|
|
$xml=$this->request_post("https://pay.heepay.com/Payment/Index.aspx", $data);
|
|
echo ($xml);die;
|
|
$xmls =simplexml_load_string($xml);
|
|
$xmljson= json_encode($xmls);
|
|
$ret=json_decode($xmljson,true);
|
|
return $ret;
|
|
|
|
$string=explode("<redirectUrl><![CDATA[",$xml);
|
|
// pp($string);
|
|
$token_id=explode("]]></redirectUrl>",$string[1]);
|
|
return $token_id[0];
|
|
} */
|
|
|
|
//https服务器 POST请求
|
|
public function request_post($url = '', $post_data = array()) {
|
|
if (empty($url) || empty($post_data)) {
|
|
return false;
|
|
}
|
|
|
|
$o = "";
|
|
foreach ( $post_data as $k => $v )
|
|
{
|
|
$o.= "$k=" . urlencode( $v ). "&" ;
|
|
}
|
|
$post_data = substr($o,0,-1);
|
|
$postUrl = $url;
|
|
$curlPost = $post_data;
|
|
$curl = curl_init();//初始化curl
|
|
curl_setopt($curl, CURLOPT_URL, $postUrl); // 要访问的地址
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYPEER, 0); // 对认证证书来源的检查
|
|
curl_setopt($curl, CURLOPT_SSL_VERIFYHOST, 1); // 从证书中检查SSL加密算法是否存在
|
|
curl_setopt($curl, CURLOPT_USERAGENT, $_SERVER['HTTP_USER_AGENT']); // 模拟用户使用的浏览器
|
|
curl_setopt($curl, CURLOPT_FOLLOWLOCATION, 1); // 使用自动跳转
|
|
curl_setopt($curl, CURLOPT_AUTOREFERER, 1); // 自动设置Referer
|
|
curl_setopt($curl, CURLOPT_POST, 1); // 发送一个常规的Post请求
|
|
curl_setopt($curl, CURLOPT_POSTFIELDS, $curlPost); // Post提交的数据包
|
|
curl_setopt($curl, CURLOPT_TIMEOUT, 30); // 设置超时限制防止死循环
|
|
curl_setopt($curl, CURLOPT_HEADER, 0); // 显示返回的Header区域内容
|
|
curl_setopt($curl, CURLOPT_RETURNTRANSFER, 1); // 获取的信息以文件流的形式返回
|
|
$data = curl_exec($curl);//运行curl
|
|
curl_close($curl);
|
|
return $data;
|
|
}
|
|
|
|
} |