Mihua.class.php 5.0 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159
  1. <?php
  2. include "getSign.php";
  3. include "getData.php";
  4. use think\Request;
  5. class Mihua
  6. {
  7. private $payUrl = 'https://platform.mhxxkj.com/paygateway/mbpay/order/v1';
  8. private $queryUrl = 'https://platform.mhxxkj.com/paygateway/mbpay/order/query/v1_1';
  9. private $merNo = ''; //商户编号
  10. private $merAccount = ''; //商户标识
  11. private $privateKey = "";
  12. private $publicKey = "";
  13. public function pay($title, $order_no, $pay_amount,$return_url='',$notify_url=''){
  14. $ch = curl_init($this->payUrl);
  15. $timeout = 6000;
  16. curl_setopt($ch, CURLOPT_POST, 1);
  17. curl_setopt($ch, CURLOPT_HEADER,0 );
  18. curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
  19. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  20. curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
  21. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  22. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
  23. $payAmount = intval($pay_amount * 100);
  24. $data = array(
  25. 'merAccount' => $this->merAccount, //商户标识
  26. 'merNo' => $this->merNo, //商户编号
  27. 'time' => time(),//时间戳
  28. 'orderId' => $order_no,//订单号
  29. 'amount' => $payAmount,//交易金额(分)
  30. 'product' => $title,//商品
  31. 'productDesc' => $title,//商品描述
  32. 'payWay' => 'WEIXIN',
  33. 'payType' => 'H5_WEIXIN',
  34. // 'openId' => 'ojmRm1jJzNSBK-6RxFFdNE30E4_4',
  35. 'userIp' => Request::instance()->ip(),
  36. 'returnUrl' => $return_url, //前端页面回调地址
  37. 'notifyUrl' => $notify_url//后台回调地址
  38. );
  39. $data['sign'] = getSign($data,$this->privateKey);
  40. $encode_data = encryptData($data,$this->privateKey);
  41. $post_data = array(
  42. 'merAccount' => $this->merAccount,//商户标识
  43. 'data' => $encode_data
  44. );
  45. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  46. $ret = curl_exec($ch);
  47. curl_close($ch);
  48. // echo ' return:'.$ret;
  49. $retjson = json_decode($ret,true);
  50. if(checkSign($retjson["data"],$this->publicKey)){
  51. // echo '验签成功';
  52. return $ret;
  53. } else {
  54. // echo '验签失败';
  55. return false;
  56. }
  57. }
  58. public function alipay($title, $order_no, $pay_amount,$return_url='',$notify_url=''){
  59. $ch = curl_init($this->payUrl);
  60. $timeout = 6000;
  61. curl_setopt($ch, CURLOPT_POST, 1);
  62. curl_setopt($ch, CURLOPT_HEADER,0 );
  63. curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
  64. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  65. curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
  66. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  67. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
  68. $payAmount = intval($pay_amount * 100);
  69. $data = array(
  70. 'merAccount' => $this->merAccount, //商户标识
  71. 'merNo' => $this->merNo, //商户编号
  72. 'time' => time(),//时间戳
  73. 'orderId' => $order_no,//订单号
  74. 'amount' => $payAmount,//交易金额(分)
  75. 'product' => $title,//商品
  76. 'productDesc' => $title,//商品描述
  77. 'payWay' => 'ALIPAY',
  78. 'payType' => 'ALIPAY_H5',
  79. // 'openId' => 'ojmRm1jJzNSBK-6RxFFdNE30E4_4',
  80. 'userIp' => Request::instance()->ip(),
  81. 'returnUrl' => $return_url, //前端页面回调地址
  82. 'notifyUrl' => $notify_url//后台回调地址
  83. );
  84. $data['sign'] = getSign($data,$this->privateKey);
  85. $encode_data = encryptData($data,$this->privateKey);
  86. $post_data = array(
  87. 'merAccount' => $this->merAccount,//商户标识
  88. 'data' => $encode_data
  89. );
  90. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  91. $ret = curl_exec($ch);
  92. curl_close($ch);
  93. // echo ' return:'.$ret;
  94. $retjson = json_decode($ret,true);
  95. if(checkSign($retjson["data"],$this->publicKey)){
  96. // echo '验签成功';
  97. return $ret;
  98. } else {
  99. // echo '验签失败';
  100. return false;
  101. }
  102. }
  103. public function notifyVerify($data){
  104. //公钥
  105. $data = decryptData($data,$this->publicKey);
  106. // echo "解密data:".$data;
  107. $retjson = json_decode($data,true);
  108. if(checkSign($retjson,$this->publicKey)){
  109. return $retjson;
  110. } else {
  111. return false;
  112. }
  113. }
  114. public function queryOrder($order_no)
  115. {
  116. $ch = curl_init($this->queryUrl);
  117. $timeout = 6000;
  118. curl_setopt($ch, CURLOPT_POST, 1);
  119. curl_setopt($ch, CURLOPT_HEADER,0 );
  120. curl_setopt($ch, CURLOPT_FRESH_CONNECT, 1);
  121. curl_setopt($ch, CURLOPT_RETURNTRANSFER, 1);
  122. curl_setopt($ch, CURLOPT_FORBID_REUSE, 1);
  123. curl_setopt($ch, CURLOPT_TIMEOUT, $timeout);
  124. curl_setopt($ch, CURLOPT_SSL_VERIFYPEER, false); // 跳过证书检查
  125. $data = array(
  126. 'merAccount' => $this->merAccount, //商户标识
  127. 'orderId' => $order_no,//订单号
  128. 'time' => time(),//时间戳
  129. );
  130. $data['sign'] = getSign($data,$this->privateKey);
  131. $encode_data = encryptData($data,$this->privateKey);
  132. $post_data = array(
  133. 'merAccount' => $this->merAccount,//商户标识
  134. 'data' => $encode_data
  135. );
  136. curl_setopt($ch, CURLOPT_POSTFIELDS, http_build_query($post_data));
  137. $ret = curl_exec($ch);
  138. curl_close($ch);
  139. // echo ' return:'.$ret;
  140. $retjson = json_decode($ret,true);
  141. if(checkSign($retjson["data"],$this->publicKey)){
  142. return $ret;
  143. echo '验签成功';
  144. } else {
  145. echo '验签失败';
  146. }
  147. }
  148. }