| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159 |
- <?php
- include "getSign.php";
- include "getData.php";
- use think\Request;
- class Mihuazfb
- {
- private $payUrl = 'https://platform.mhxxkj.com/paygateway/mbpay/order/v1';
- private $queryUrl = 'https://platform.mhxxkj.com/paygateway/mbpay/order/query/v1_1';
- private $merNo = ''; //商户编号
- private $merAccount = ''; //商户标识
- private $privateKey = "";
- private $publicKey = "";
- public function pay($title, $order_no, $pay_amount,$return_url='',$notify_url=''){
- $ch = curl_init($this->payUrl);
- $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); // 跳过证书检查
-
- $payAmount = intval($pay_amount * 100);
- $data = array(
- 'merAccount' => $this->merAccount, //商户标识
- 'merNo' => $this->merNo, //商户编号
- 'time' => time(),//时间戳
- 'orderId' => $order_no,//订单号
- 'amount' => $payAmount,//交易金额(分)
- 'product' => $title,//商品
- 'productDesc' => $title,//商品描述
- 'payWay' => 'WEIXIN',
- 'payType' => 'H5_WEIXIN',
- // 'openId' => 'ojmRm1jJzNSBK-6RxFFdNE30E4_4',
- 'userIp' => Request::instance()->ip(),
- 'returnUrl' => $return_url, //前端页面回调地址
- 'notifyUrl' => $notify_url//后台回调地址
- );
- $data['sign'] = getSign($data,$this->privateKey);
- $encode_data = encryptData($data,$this->privateKey);
- $post_data = array(
- 'merAccount' => $this->merAccount,//商户标识
- 'data' => $encode_data
- );
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
- $ret = curl_exec($ch);
- curl_close($ch);
- // echo ' return:'.$ret;
- $retjson = json_decode($ret,true);
- if(checkSign($retjson["data"],$this->publicKey)){
- // echo '验签成功';
- return $ret;
- } else {
- // echo '验签失败';
- return false;
- }
- }
- public function alipay($title, $order_no, $pay_amount,$return_url='',$notify_url=''){
- $ch = curl_init($this->payUrl);
- $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); // 跳过证书检查
-
- $payAmount = intval($pay_amount * 100);
- $data = array(
- 'merAccount' => $this->merAccount, //商户标识
- 'merNo' => $this->merNo, //商户编号
- 'time' => time(),//时间戳
- 'orderId' => $order_no,//订单号
- 'amount' => $payAmount,//交易金额(分)
- 'product' => $title,//商品
- 'productDesc' => $title,//商品描述
- 'payWay' => 'ALIPAY',
- 'payType' => 'ALIPAY_H5',
- // 'openId' => 'ojmRm1jJzNSBK-6RxFFdNE30E4_4',
- 'userIp' => Request::instance()->ip(),
- 'returnUrl' => $return_url, //前端页面回调地址
- 'notifyUrl' => $notify_url//后台回调地址
- );
- $data['sign'] = getSign($data,$this->privateKey);
- $encode_data = encryptData($data,$this->privateKey);
- $post_data = array(
- 'merAccount' => $this->merAccount,//商户标识
- 'data' => $encode_data
- );
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
- $ret = curl_exec($ch);
- curl_close($ch);
- // echo ' return:'.$ret;
- $retjson = json_decode($ret,true);
- if(checkSign($retjson["data"],$this->publicKey)){
- // echo '验签成功';
- return $ret;
- } else {
- // echo '验签失败';
- return false;
- }
- }
- public function notifyVerify($data){
- //公钥
- $data = decryptData($data,$this->publicKey);
- // echo "解密data:".$data;
- $retjson = json_decode($data,true);
- if(checkSign($retjson,$this->publicKey)){
- return $retjson;
- } else {
- return false;
- }
- }
- public function queryOrder($order_no)
- {
- $ch = curl_init($this->queryUrl);
- $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); // 跳过证书检查
-
- $data = array(
- 'merAccount' => $this->merAccount, //商户标识
- 'orderId' => $order_no,//订单号
- 'time' => time(),//时间戳
- );
- $data['sign'] = getSign($data,$this->privateKey);
- $encode_data = encryptData($data,$this->privateKey);
- $post_data = array(
- 'merAccount' => $this->merAccount,//商户标识
- 'data' => $encode_data
- );
- curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
- $ret = curl_exec($ch);
- curl_close($ch);
- // echo ' return:'.$ret;
- $retjson = json_decode($ret,true);
- if(checkSign($retjson["data"],$this->publicKey)){
- return $ret;
- echo '验签成功';
- } else {
- echo '验签失败';
- }
- }
- }
|