PayTrait.php 6.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189
  1. <?php
  2. namespace App\Traits;
  3. use App\Services\Eav\EavSetService;
  4. use App\Services\Eav\MaterialService;
  5. use EasyWeChat\Factory;
  6. use Illuminate\Support\Facades\DB;
  7. use Illuminate\Support\Facades\Request;
  8. use Omnipay\Alipay\AopPageGateway;
  9. use Omnipay\Omnipay;
  10. trait PayTrait
  11. {
  12. /**
  13. * 获取支付配置信息
  14. *
  15. * @param $pay_type
  16. * @param $storeId
  17. * @return array|mixed
  18. */
  19. public function getPayConfig($pay_type, $storeId)
  20. {
  21. // 支付配置信息
  22. $materialService = new MaterialService(new EavSetService('store_pay_setting'));
  23. $info = $materialService->elasticClientService()->queryOne(['pay_type' => $pay_type, 'store_id' => $storeId]);
  24. if ($info) {
  25. return $info['pay_content'];
  26. } else {
  27. return [];
  28. }
  29. }
  30. /**
  31. * 支付宝支付网关
  32. *
  33. * @return AopPageGateway
  34. */
  35. protected function alipayGateway($payConfig)
  36. {
  37. /**
  38. * 手机网站支付
  39. *
  40. * @var AopPageGateway $gateway
  41. */
  42. $gateway = Omnipay::create('Alipay_LegacyWap');
  43. $gateway->setSignType('RSA2'); //RSA/RSA2
  44. $gateway->setPartner($payConfig['partner_id']);
  45. $gateway->setKey($payConfig['key']);
  46. $gateway->setSellerId($payConfig['seller_id']);
  47. $gateway->setPrivateKey($payConfig['private_key']);
  48. $gateway->setAlipayPublicKey($payConfig['public_key']);
  49. $gateway->setReturnUrl(toRoute('/api/returnUrl/index'));
  50. $gateway->setNotifyUrl(toRoute('/api/notifyUrl/alipay'));
  51. return $gateway;
  52. }
  53. ######################################################################################################
  54. /**
  55. * 微信小程序支付网关
  56. *
  57. * @param $payConfig
  58. * @param $storeId
  59. * @return \EasyWeChat\Payment\Application
  60. */
  61. protected function wxGateway($payConfig, $storeId)
  62. {
  63. $dir = base_path('cert/' . $storeId . '/1');
  64. $cert_path = $dir . '/cert.pem';
  65. $key_path = $dir . '/key.pem';
  66. $config = [
  67. 'app_id' => $payConfig['appid'], //'wx484b70fdf1cee093',
  68. 'mch_id' => $payConfig['mchid'],
  69. 'key' => $payConfig['key'], // API 密钥
  70. // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
  71. 'cert_path' => $cert_path, // XXX: 绝对路径!!!!
  72. 'key_path' => $key_path, // XXX: 绝对路径!!!!
  73. 'notify_url' => toRoute('/api/notifyUrl/wxpay'), // 你也可以在下单时单独设置来想覆盖它
  74. ];
  75. return Factory::payment($config);
  76. }
  77. /**
  78. * 微信公众号支付网关
  79. *
  80. * @param $payConfig
  81. * @param $storeId
  82. * @return \EasyWeChat\Payment\Application
  83. */
  84. protected function wechatGateway($payConfig, $storeId)
  85. {
  86. $dir = base_path('cert/' . $storeId . '/2');
  87. $cert_path = $dir . '/cert.pem';
  88. $key_path = $dir . '/key.pem';
  89. $config = [
  90. // 必要配置
  91. 'app_id' => $payConfig['appid'], //'wx484b70fdf1cee093',
  92. 'mch_id' => $payConfig['mchid'],
  93. 'key' => $payConfig['key'], // API 密钥
  94. // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
  95. 'cert_path' => $cert_path, // XXX: 绝对路径!!!!
  96. 'key_path' => $key_path, // XXX: 绝对路径!!!!
  97. 'notify_url' => toRoute('/api/notifyUrl/wechatpay'), // 你也可以在下单时单独设置来想覆盖它
  98. ];
  99. return Factory::payment($config);
  100. }
  101. /**
  102. * 微信开放平台
  103. *
  104. * @return \EasyWeChat\OpenPlatform\Application
  105. */
  106. protected function getOpenPlatform()
  107. {
  108. $config = [
  109. 'app_id' => 'wxe5e64136caa8bc37', //第三方平台应用appid
  110. 'secret' => '199791213df4d0a51981820a9ebda097', //第三方平台应用appsecret
  111. 'token' => 'ac729e367777be95714a03a6939c8026', //第三方平台应用token(消息校验Token)
  112. 'aes_key' => '729e3a069e7719532c6774a037be9539ca986c86a69' //第三方平台应用Key(消息加解密Key)
  113. ];
  114. return Factory::openPlatform($config);
  115. }
  116. ######################################################################################################
  117. ##### 服务商平台支付 ####################################################################################
  118. ######################################################################################################
  119. /**
  120. * 服务商平台支付配置 微信小程序
  121. */
  122. protected function getServiceWeappGateway()
  123. {
  124. $dir = base_path('cert/tiaotiaoyu');
  125. $cert_path = $dir . '/cert.pem';
  126. $key_path = $dir . '/key.pem';
  127. $config = [
  128. // 必要配置
  129. 'app_id' => 'wx484b70fdf1cee093', // 服务商APPID(公众号appid)
  130. 'mch_id' => '1555516261', //服务商商户号
  131. 'key' => '67b24e3cf32eb1b48132cfa9c21733ca', // API 密钥
  132. // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
  133. 'cert_path' => $cert_path, // XXX: 绝对路径!!!!
  134. 'key_path' => $key_path, // XXX: 绝对路径!!!!
  135. 'notify_url' => toRoute('/api/notifyUrl/wechatpay'), // 你也可以在下单时单独设置来想覆盖它
  136. ];
  137. return Factory::payment($config);
  138. }
  139. /**
  140. * 服务商平台支付配置 微信公众号
  141. */
  142. protected function getServiceWechatGateway()
  143. {
  144. $dir = base_path('cert/tiaotiaoyu');
  145. $cert_path = $dir . '/cert.pem';
  146. $key_path = $dir . '/key.pem';
  147. $config = [
  148. // 必要配置
  149. 'app_id' => 'wx484b70fdf1cee093', // 服务商APPID(公众号appid)
  150. 'mch_id' => '1555516261', //服务商商户号
  151. 'key' => '67b24e3cf32eb1b48132cfa9c21733ca', // API 密钥
  152. // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
  153. 'cert_path' => $cert_path, // XXX: 绝对路径!!!!
  154. 'key_path' => $key_path, // XXX: 绝对路径!!!!
  155. 'notify_url' => toRoute('/api/notifyUrl/wechatpay'), // 你也可以在下单时单独设置来想覆盖它
  156. ];
  157. return Factory::payment($config);
  158. }
  159. }