PayService.php 2.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172
  1. <?php
  2. namespace App\Services;
  3. use Yansongda\Pay\Pay;
  4. class PayService
  5. {
  6. //public function
  7. public static function ali_config(){
  8. $config = [
  9. 'app_id' => '2016082000295641',
  10. 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'].'/api/ali_notify.php',
  11. 'return_url' => 'https://'.$_SERVER['HTTP_HOST'].'/api/ali_return.php',
  12. 'ali_public_key' => '',//支付宝公钥
  13. 'private_key' => '',//应用私钥
  14. 'log' => [ // optional
  15. 'file' => './logs/alipay.log',
  16. 'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
  17. 'type' => 'single', // optional, 可选 daily.
  18. 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
  19. ],
  20. 'http' => [ // optional
  21. 'timeout' => 5.0,
  22. 'connect_timeout' => 5.0,
  23. // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
  24. ],
  25. // 'mode' => 'dev', // optional,设置此参数,将进入沙箱模式
  26. ];
  27. return $config;
  28. }
  29. public static function wx_config(){
  30. $config = [
  31. 'appid' => 'wxb3fxxxxxxxxxxx', // APP APPID
  32. //'app_id' => 'wxb3fxxxxxxxxxxx', // 公众号 APPID
  33. //'miniapp_id' => 'wxb3fxxxxxxxxxxx', // 小程序 APPID
  34. 'mch_id' => '145776xxxx',
  35. 'key' => 'mF2suE9sU6Mk1CxxxxIxxxxx',
  36. 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'].'/api/wx_notify.php',
  37. //'cert_client' => './cert/apiclient_cert.pem', // optional, 退款,红包等情况时需要用到
  38. //'cert_key' => './cert/apiclient_key.pem',// optional, 退款,红包等情况时需要用到
  39. 'log' => [ // optional
  40. 'file' => './logs/wechat.log',
  41. 'level' => 'info', // 建议生产环境等级调整为 info,开发环境为 debug
  42. 'type' => 'single', // optional, 可选 daily.
  43. 'max_file' => 30, // optional, 当 type 为 daily 时有效,默认 30 天
  44. ],
  45. 'http' => [ // optional
  46. 'timeout' => 5.0,
  47. 'connect_timeout' => 5.0,
  48. // 更多配置项请参考 [Guzzle](https://guzzle-cn.readthedocs.io/zh_CN/latest/request-options.html)
  49. ],
  50. // 'mode' => 'dev',
  51. ];
  52. return $config;
  53. }
  54. public static function pay($param){
  55. if($param['payment'] == 1){
  56. $wechat = Pay::wechat(self::wx_config());
  57. return $wechat->app($param)->send();
  58. }else{
  59. $alipay = Pay::alipay(self::ali_config());
  60. return $alipay->app($param)->send();
  61. }
  62. }
  63. }