Publicpay.php 1.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace app\api\controller;
  3. use kjpay\kjpay;
  4. use think\Db;
  5. /**
  6. * 公众号支付接口
  7. */
  8. class Publicpay extends Common
  9. {
  10. protected $noNeedLogin = [''];
  11. protected $noNeedRight = '*';
  12. public function _initialize()
  13. {
  14. parent::_initialize();
  15. }
  16. /**
  17. * 微信支付
  18. */
  19. public function wxpay() {
  20. // 获取公共参数
  21. $config = config("publicPay");
  22. //商户订单号,商户网站订单系统中唯一订单号,必填
  23. $out_trade_no = date('YmdHis').rand(10000, 99999);
  24. //商户号
  25. $merchant_no = $config["merchant_no"];
  26. //密钥
  27. $key = $config["key"];
  28. // 实例化支付类
  29. $kjpay = new kjpay();
  30. //请求的参数(注:不同支付接口请求参数略有不同,具体请参照接口文档)
  31. $param = array(
  32. 'merchant_no' => $merchant_no,
  33. 'merchant_order_no' => $out_trade_no,
  34. //异步通知的地址
  35. 'notify_url' => $config["notify_url"],
  36. //同步跳转的地址
  37. //'return_url' => 'http://www.kj-pay.com',
  38. 'start_time' => date('YmdHis'),
  39. 'trade_amount' => 0.01,
  40. 'goods_name' => "商品名称",
  41. 'goods_desc' => "商品描述",
  42. 'user_ip' => $kjpay->get_wx_ip(),
  43. 'pay_sence' => '{"type":"Wap","wap_url":"https://www.kk30.com","wap_name":"快快网络"}',
  44. 'sign_type' => 1
  45. );
  46. //签名
  47. $sign = $kjpay->local_sign($param, $key);
  48. $param['sign'] = $sign;
  49. $res = $kjpay->getdata("http://商户后台查询请求地址/wechar/wap_pay", $param);
  50. $list = json_decode($res, true);
  51. echo "<pre>";
  52. print_r($list);
  53. echo "<pre>";
  54. }
  55. }