PayService.php 2.9 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374
  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',
  11. 'return_url' => 'https://'.$_SERVER['HTTP_HOST'].'/api/ali_return',
  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' => env("WEIXIN_OPEN_APPID"), // APP APPID
  32. //'app_id' => 'wxb3fxxxxxxxxxxx', // 公众号 APPID
  33. //'miniapp_id' => 'wxb3fxxxxxxxxxxx', // 小程序 APPID
  34. 'mch_id' => env("WEIXIN_MCH_ID"),
  35. 'key' => env("WEIXIN_MCH_KEY"),
  36. 'notify_url' => 'https://'.$_SERVER['HTTP_HOST'].'/api/wx_notify',
  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' => 'debug', // 建议生产环境等级调整为 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. //$param['total_fee'] = $param['total_fee']*100;
  57. $param['total_fee'] = 1;
  58. $wechat = Pay::wechat(self::wx_config());
  59. return $wechat->app($param)->send();
  60. }else{
  61. $alipay = Pay::alipay(self::ali_config());
  62. return $alipay->app($param)->send();
  63. }
  64. }
  65. }