AlipayServiceProvider.php 3.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128
  1. <?php
  2. namespace app\common\components\alipay;
  3. use Illuminate\Support\ServiceProvider;
  4. use Setting;
  5. use app\common\helpers\Url;
  6. class AlipayServiceProvider extends ServiceProvider
  7. {
  8. /**
  9. * boot process
  10. */
  11. public function boot()
  12. {
  13. }
  14. /**
  15. * Register the service provider.
  16. *
  17. * @return void
  18. */
  19. public function register()
  20. {
  21. $this->app->bind('alipay.mobile', function ($app)
  22. {
  23. $alipay = new Mobile\SdkPayment();
  24. $alipay->setPem(Setting::get('alipay.pem'))
  25. ->setPartner(Setting::get('alipay.partner_id'))
  26. ->setSellerId(Setting::get('alipay.seller_id'))
  27. ->setSignType(Setting::get('alipay-mobile.sign_type'))
  28. ->setPrivateKeyPath(Setting::get('alipay-mobile.private_key_path'))
  29. ->setPublicKeyPath(Setting::get('alipay-mobile.public_key_path'))
  30. ->setNotifyUrl(Setting::get('alipay-mobile.notify_url'));
  31. return $alipay;
  32. });
  33. $this->app->bind('alipay.web', function ($app)
  34. {
  35. $alipay = new Web\SdkPayment();
  36. $alipay->setPartner(Setting::get('alipay.partner_id'))
  37. ->setSellerId(Setting::get('alipay.seller_id'))
  38. ->setKey(Setting::get('alipay-web.key'))
  39. ->setSignType(Setting::get('alipay-web.sign_type'))
  40. ->setNotifyUrl(Setting::get('alipay-web.notify_url'))
  41. ->setReturnUrl(Setting::get('alipay-web.return_url'))
  42. ->setExterInvokeIp($app->request->getClientIp());
  43. return $alipay;
  44. });
  45. $this->app->bind('alipay.wap', function ($app)
  46. {
  47. $alipay = new Wap\SdkPayment();
  48. $alipay->setPartner(Setting::get('alipay.partner_id'))
  49. ->setSellerId(Setting::get('alipay.seller_id'))
  50. ->setKey(Setting::get('alipay-web.key'))
  51. ->setSignType(Setting::get('alipay-web.sign_type'))
  52. ->setNotifyUrl(Setting::get('alipay-web.notify_url'))
  53. ->setReturnUrl(Setting::get('alipay-web.return_url'))
  54. ->setExterInvokeIp($app->request->getClientIp());
  55. return $alipay;
  56. });
  57. $this->app->bind('alipay.wap2', function ($app)
  58. {
  59. $alipay = new Wap2\SdkPayment();
  60. // $set = \Setting::get('shop_app.pay');
  61. // //$sign = '';
  62. // $app_id = $set['alipay_appid'];
  63. // //$sign_type = '';
  64. // $rsaPrivateKey = $set['alipay_sign_private'];
  65. // $alipayrsaPublicKey = $set['alipay_sign_public'];
  66. $set = \Setting::get('shop.pay');
  67. $app_id = decrypt($set['alipay_app_id']);
  68. $rsaPrivateKey = decrypt($set['rsa_private_key']);
  69. $alipayrsaPublicKey =decrypt($set['rsa_public_key']);
  70. //$alipay->setSign($sign);
  71. //$alipay->setSignType($sign_type);
  72. $alipay->setAppId($app_id);
  73. $alipay->setRsaPrivateKey($rsaPrivateKey);
  74. $alipay->setAlipayrsaPublicKey($alipayrsaPublicKey);
  75. $alipay->setNotifyUrl(Url::shopSchemeUrl('payment/alipay/newNotifyUrl.php'));
  76. $alipay->setReturnUrl(Setting::get('alipay-web.return_url'));
  77. return $alipay;
  78. });
  79. $this->app->bind('alipay.toutiao', function ($app)
  80. {
  81. $alipay = new Wap2\SdkPayment();
  82. $set = \Setting::get('shop.pay');
  83. $app_id = decrypt($set['alipay_app_id']);
  84. $rsaPrivateKey = decrypt($set['rsa_private_key']);
  85. $alipayrsaPublicKey =decrypt($set['rsa_public_key']);
  86. $alipay->setAppId($app_id);
  87. $alipay->setRsaPrivateKey($rsaPrivateKey);
  88. $alipay->setAlipayrsaPublicKey($alipayrsaPublicKey);
  89. $alipay->setNotifyUrl(Url::shopSchemeUrl('payment/toutiaopay/notifyUrlAlipay.php'));
  90. $alipay->setReturnUrl(Setting::get('alipay-web.return_url'));
  91. return $alipay;
  92. });
  93. }
  94. /**
  95. * Get the services provided by the provider.
  96. *
  97. * @return array
  98. */
  99. public function provides()
  100. {
  101. return [
  102. 'alipay.mobile',
  103. 'alipay.web',
  104. 'alipay.wap',
  105. ];
  106. }
  107. }