Hupijiaopay.php 1.6 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. <?php
  2. namespace app\service\api;
  3. use app\service\ConfServiceFacade;
  4. use laytp\traits\Error;
  5. use think\facade\Cache;
  6. use think\facade\Config;
  7. use think\facade\Request;
  8. use Xunhu\Hupijiao\Hupijiao;
  9. class Hupijiaopay
  10. {
  11. use Error;
  12. /**
  13. * phpmailer对象
  14. */
  15. protected $client;
  16. protected $pay;
  17. private $config;
  18. /**
  19. * 构造函数
  20. */
  21. public function __construct()
  22. {
  23. global $_GPC;
  24. $pay = ConfServiceFacade::groupGet('system.pay', true);
  25. if(empty($pay)){
  26. return $this->error('未配置支付接口参数');
  27. }
  28. $this->pay=$pay;
  29. $apiUrl='https://api.xunhupay.com/payment';
  30. if(!empty($pay['hupijiao_gateway'])){
  31. $ex = explode('/do.html',$pay['hupijiao_gateway']);
  32. $apiUrl=$ex[0];
  33. }
  34. $this->config = [
  35. 'app_id' => $pay['hupijiao_appid'], // 配置商户号
  36. 'app_secret' => $pay['hupijiao_appsecret'], // 配置密钥
  37. 'api_url'=>$apiUrl
  38. ];
  39. }
  40. public function pay($post){
  41. // 初始化
  42. $Hupijiao=new Hupijiao($this->config);
  43. $data=$post;
  44. //回调地址,服务器post发送成功支付参数到此地址
  45. //异步跳转地址,支付成功后跳转地址
  46. $data['wap_url']=!empty($this->pay['hupijiao_gateway'])?$this->pay['hupijiao_gateway']:'https://api.xunhupay.com/payment';
  47. $response=$Hupijiao->request('wx_native',$data);
  48. return $response;
  49. }
  50. }