Kjzfb.class.php 3.5 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <?php
  2. include "getSign.php";
  3. use think\Request;
  4. class Kjzfb
  5. {
  6. private $payUrl = 'http://api.kj-pay.com/alipay/wap_pay';
  7. private $queryUrl = 'http://api.kj-pay.com/alipay/query_pay';
  8. private $merchant_no = ''; //商户号
  9. private $key = ""; //密钥
  10. public function pay($title, $order_no, $pay_amount,$return_url='',$notify_url=''){
  11. //请求的参数(注:不同支付接口请求参数略有不同,具体请参照接口文档)
  12. //分账逻辑处理
  13. $sub_amount = floatval(intval($pay_amount * 100 * 0.99)/100);
  14. $receivers = array();
  15. /*
  16. if($sub_amount){
  17. $receiver = array();
  18. $receiver['member_id'] = '210302154';
  19. $receiver['amount'] = $sub_amount;
  20. $receivers[] = $receiver;
  21. }
  22. */
  23. if($receivers){
  24. $param = array(
  25. 'merchant_no' => $this->merchant_no,
  26. 'merchant_order_no' => $order_no,
  27. //异步通知的地址
  28. 'notify_url' => $notify_url,
  29. //同步跳转的地址
  30. //'return_url' => $return_url,
  31. 'start_time' => date('YmdHis'),
  32. 'trade_amount' => $pay_amount,
  33. 'goods_name' => $title,
  34. 'goods_desc' => $title,
  35. 'user_ip' => Request::instance()->ip(),
  36. 'pay_sence' => '{"type":"Wap","wap_url":"https://www.weilongwl.com","wap_name":"麻花网络"}',
  37. 'receivers' => json_encode($receivers),
  38. 'sign_type' => 1
  39. );
  40. }
  41. else{
  42. $param = array(
  43. 'merchant_no' => $this->merchant_no,
  44. 'merchant_order_no' => $order_no,
  45. //异步通知的地址
  46. 'notify_url' => $notify_url,
  47. //同步跳转的地址
  48. //'return_url' => $return_url,
  49. 'start_time' => date('YmdHis'),
  50. 'trade_amount' => $pay_amount,
  51. 'goods_name' => $title,
  52. 'goods_desc' => $title,
  53. 'user_ip' => Request::instance()->ip(),
  54. 'pay_sence' => '{"type":"Wap","wap_url":"https://www.weilongwl.com","wap_name":"麻花网络"}',
  55. 'sign_type' => 1
  56. );
  57. }
  58. //签名
  59. $sign = local_sign($param, $this->key);
  60. $param['sign'] = $sign;
  61. $res = getdata($this->payUrl, $param);
  62. $list = json_decode($res, true);
  63. /*
  64. echo "<pre>";
  65. print_r($list);
  66. echo "<pre>";
  67. */
  68. //对响应结果进行验签,具体见下面的验签示例
  69. if (local_sign($list['data'], $this->key) == $list['data']['sign']) {
  70. // echo '响应结果验签成功,请继续您的业务层操作';
  71. return $list;
  72. } else {
  73. // echo '验签失败';
  74. return false;
  75. }
  76. }
  77. public function notifyVerify($data){
  78. //签名
  79. $sign = local_sign($data, $this->key);
  80. if ($sign == $data['sign']){
  81. return $data;
  82. } else {
  83. return false;
  84. }
  85. }
  86. public function queryOrder($order_no)
  87. {
  88. //请求的参数(注:不同支付接口请求参数略有不同,具体请参照接口文档)
  89. $param = array(
  90. 'merchant_no' => $this->merchant_no,
  91. 'trade_no' => $order_no,
  92. 'sign_type' => 1
  93. );
  94. //签名
  95. $sign = local_sign($param, $this->key);
  96. $param['sign'] = $sign;
  97. $res = getdata($this->queryUrl, $param);
  98. $list = json_decode($res, true);
  99. /*
  100. echo "<pre>";
  101. print_r($list);
  102. echo "<pre>";
  103. */
  104. //对响应结果进行验签,具体见下面的验签示例
  105. if (isset($list['data']['sign']) && local_sign($list['data'], $this->key) == $list['data']['sign']) {
  106. return $res;
  107. echo '验签成功';
  108. } else {
  109. echo '验签失败';
  110. return false;
  111. }
  112. }
  113. }