| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133 |
- <?php
- include "getSign.php";
- use think\Request;
- class Kjzfb
- {
- private $payUrl = 'http://api.kj-pay.com/alipay/wap_pay';
- private $queryUrl = 'http://api.kj-pay.com/alipay/query_pay';
- private $merchant_no = ''; //商户号
- private $key = ""; //密钥
- public function pay($title, $order_no, $pay_amount,$return_url='',$notify_url=''){
- //请求的参数(注:不同支付接口请求参数略有不同,具体请参照接口文档)
- //分账逻辑处理
- $sub_amount = floatval(intval($pay_amount * 100 * 0.99)/100);
- $receivers = array();
- /*
- if($sub_amount){
- $receiver = array();
- $receiver['member_id'] = '210302154';
- $receiver['amount'] = $sub_amount;
- $receivers[] = $receiver;
- }
- */
-
- if($receivers){
- $param = array(
- 'merchant_no' => $this->merchant_no,
- 'merchant_order_no' => $order_no,
- //异步通知的地址
- 'notify_url' => $notify_url,
- //同步跳转的地址
- //'return_url' => $return_url,
- 'start_time' => date('YmdHis'),
- 'trade_amount' => $pay_amount,
- 'goods_name' => $title,
- 'goods_desc' => $title,
- 'user_ip' => Request::instance()->ip(),
- 'pay_sence' => '{"type":"Wap","wap_url":"https://www.weilongwl.com","wap_name":"麻花网络"}',
- 'receivers' => json_encode($receivers),
- 'sign_type' => 1
- );
- }
- else{
- $param = array(
- 'merchant_no' => $this->merchant_no,
- 'merchant_order_no' => $order_no,
- //异步通知的地址
- 'notify_url' => $notify_url,
- //同步跳转的地址
- //'return_url' => $return_url,
- 'start_time' => date('YmdHis'),
- 'trade_amount' => $pay_amount,
- 'goods_name' => $title,
- 'goods_desc' => $title,
- 'user_ip' => Request::instance()->ip(),
- 'pay_sence' => '{"type":"Wap","wap_url":"https://www.weilongwl.com","wap_name":"麻花网络"}',
- 'sign_type' => 1
- );
- }
- //签名
- $sign = local_sign($param, $this->key);
- $param['sign'] = $sign;
- $res = getdata($this->payUrl, $param);
- $list = json_decode($res, true);
- /*
- echo "<pre>";
- print_r($list);
- echo "<pre>";
- */
- //对响应结果进行验签,具体见下面的验签示例
- if (local_sign($list['data'], $this->key) == $list['data']['sign']) {
- // echo '响应结果验签成功,请继续您的业务层操作';
- return $list;
- } else {
- // echo '验签失败';
- return false;
- }
- }
- public function notifyVerify($data){
- //签名
- $sign = local_sign($data, $this->key);
- if ($sign == $data['sign']){
- return $data;
- } else {
- return false;
- }
- }
- public function queryOrder($order_no)
- {
- //请求的参数(注:不同支付接口请求参数略有不同,具体请参照接口文档)
- $param = array(
- 'merchant_no' => $this->merchant_no,
- 'trade_no' => $order_no,
- 'sign_type' => 1
- );
- //签名
- $sign = local_sign($param, $this->key);
- $param['sign'] = $sign;
- $res = getdata($this->queryUrl, $param);
- $list = json_decode($res, true);
- /*
- echo "<pre>";
- print_r($list);
- echo "<pre>";
- */
- //对响应结果进行验签,具体见下面的验签示例
- if (isset($list['data']['sign']) && local_sign($list['data'], $this->key) == $list['data']['sign']) {
- return $res;
- echo '验签成功';
- } else {
- echo '验签失败';
- return false;
- }
- }
- }
|