123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189 |
- <?php
- namespace App\Traits;
- use App\Services\Eav\EavSetService;
- use App\Services\Eav\MaterialService;
- use EasyWeChat\Factory;
- use Illuminate\Support\Facades\DB;
- use Illuminate\Support\Facades\Request;
- use Omnipay\Alipay\AopPageGateway;
- use Omnipay\Omnipay;
- trait PayTrait
- {
- /**
- * 获取支付配置信息
- *
- * @param $pay_type
- * @param $storeId
- * @return array|mixed
- */
- public function getPayConfig($pay_type, $storeId)
- {
- // 支付配置信息
- $materialService = new MaterialService(new EavSetService('store_pay_setting'));
- $info = $materialService->elasticClientService()->queryOne(['pay_type' => $pay_type, 'store_id' => $storeId]);
- if ($info) {
- return $info['pay_content'];
- } else {
- return [];
- }
- }
- /**
- * 支付宝支付网关
- *
- * @return AopPageGateway
- */
- protected function alipayGateway($payConfig)
- {
- /**
- * 手机网站支付
- *
- * @var AopPageGateway $gateway
- */
- $gateway = Omnipay::create('Alipay_LegacyWap');
- $gateway->setSignType('RSA2'); //RSA/RSA2
- $gateway->setPartner($payConfig['partner_id']);
- $gateway->setKey($payConfig['key']);
- $gateway->setSellerId($payConfig['seller_id']);
- $gateway->setPrivateKey($payConfig['private_key']);
- $gateway->setAlipayPublicKey($payConfig['public_key']);
- $gateway->setReturnUrl(toRoute('/api/returnUrl/index'));
- $gateway->setNotifyUrl(toRoute('/api/notifyUrl/alipay'));
- return $gateway;
- }
- ######################################################################################################
- /**
- * 微信小程序支付网关
- *
- * @param $payConfig
- * @param $storeId
- * @return \EasyWeChat\Payment\Application
- */
- protected function wxGateway($payConfig, $storeId)
- {
- $dir = base_path('cert/' . $storeId . '/1');
- $cert_path = $dir . '/cert.pem';
- $key_path = $dir . '/key.pem';
- $config = [
- 'app_id' => $payConfig['appid'], //'wx484b70fdf1cee093',
- 'mch_id' => $payConfig['mchid'],
- 'key' => $payConfig['key'], // API 密钥
- // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
- 'cert_path' => $cert_path, // XXX: 绝对路径!!!!
- 'key_path' => $key_path, // XXX: 绝对路径!!!!
- 'notify_url' => toRoute('/api/notifyUrl/wxpay'), // 你也可以在下单时单独设置来想覆盖它
- ];
- return Factory::payment($config);
- }
- /**
- * 微信公众号支付网关
- *
- * @param $payConfig
- * @param $storeId
- * @return \EasyWeChat\Payment\Application
- */
- protected function wechatGateway($payConfig, $storeId)
- {
- $dir = base_path('cert/' . $storeId . '/2');
- $cert_path = $dir . '/cert.pem';
- $key_path = $dir . '/key.pem';
- $config = [
- // 必要配置
- 'app_id' => $payConfig['appid'], //'wx484b70fdf1cee093',
- 'mch_id' => $payConfig['mchid'],
- 'key' => $payConfig['key'], // API 密钥
- // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
- 'cert_path' => $cert_path, // XXX: 绝对路径!!!!
- 'key_path' => $key_path, // XXX: 绝对路径!!!!
- 'notify_url' => toRoute('/api/notifyUrl/wechatpay'), // 你也可以在下单时单独设置来想覆盖它
- ];
- return Factory::payment($config);
- }
- /**
- * 微信开放平台
- *
- * @return \EasyWeChat\OpenPlatform\Application
- */
- protected function getOpenPlatform()
- {
- $config = [
- 'app_id' => 'wxe5e64136caa8bc37', //第三方平台应用appid
- 'secret' => '199791213df4d0a51981820a9ebda097', //第三方平台应用appsecret
- 'token' => 'ac729e367777be95714a03a6939c8026', //第三方平台应用token(消息校验Token)
- 'aes_key' => '729e3a069e7719532c6774a037be9539ca986c86a69' //第三方平台应用Key(消息加解密Key)
- ];
- return Factory::openPlatform($config);
- }
- ######################################################################################################
- ##### 服务商平台支付 ####################################################################################
- ######################################################################################################
- /**
- * 服务商平台支付配置 微信小程序
- */
- protected function getServiceWeappGateway()
- {
- $dir = base_path('cert/tiaotiaoyu');
- $cert_path = $dir . '/cert.pem';
- $key_path = $dir . '/key.pem';
- $config = [
- // 必要配置
- 'app_id' => 'wx484b70fdf1cee093', // 服务商APPID(公众号appid)
- 'mch_id' => '1555516261', //服务商商户号
- 'key' => '67b24e3cf32eb1b48132cfa9c21733ca', // API 密钥
- // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
- 'cert_path' => $cert_path, // XXX: 绝对路径!!!!
- 'key_path' => $key_path, // XXX: 绝对路径!!!!
- 'notify_url' => toRoute('/api/notifyUrl/wechatpay'), // 你也可以在下单时单独设置来想覆盖它
- ];
- return Factory::payment($config);
- }
- /**
- * 服务商平台支付配置 微信公众号
- */
- protected function getServiceWechatGateway()
- {
- $dir = base_path('cert/tiaotiaoyu');
- $cert_path = $dir . '/cert.pem';
- $key_path = $dir . '/key.pem';
- $config = [
- // 必要配置
- 'app_id' => 'wx484b70fdf1cee093', // 服务商APPID(公众号appid)
- 'mch_id' => '1555516261', //服务商商户号
- 'key' => '67b24e3cf32eb1b48132cfa9c21733ca', // API 密钥
- // 如需使用敏感接口(如退款、发送红包等)需要配置 API 证书路径(登录商户平台下载 API 证书)
- 'cert_path' => $cert_path, // XXX: 绝对路径!!!!
- 'key_path' => $key_path, // XXX: 绝对路径!!!!
- 'notify_url' => toRoute('/api/notifyUrl/wechatpay'), // 你也可以在下单时单独设置来想覆盖它
- ];
- return Factory::payment($config);
- }
- }
|