|
|
@@ -67,85 +67,91 @@ class PaymentService extends BaseService
|
|
|
public function createPay($scene, $payType = 10, $payPt = '')
|
|
|
{
|
|
|
$config = ConfigService::make()->getConfigOptionByGroup(6);
|
|
|
- if ($payType == 10) {
|
|
|
- $appid = isset($config['wxpay_appid']) ? $config['wxpay_appid'] : '';
|
|
|
- $mpAppid = isset($config['wxpay_mp_appid']) ? $config['wxpay_mp_appid'] : '';
|
|
|
- $minAppid = isset($config['wxpay_min_appid']) ? $config['wxpay_min_appid'] : '';
|
|
|
- $mchid = isset($config['wxpay_mchd']) ? $config['wxpay_mchd'] : '';
|
|
|
- $secretV3Key = isset($config['wxpay_key_v3']) ? $config['wxpay_key_v3'] : '';
|
|
|
- $secretV2Key = isset($config['wxpay_key_v2']) ? $config['wxpay_key_v2'] : '';
|
|
|
- $wxpaySecretCert = isset($config['wxpay_secret_cert']) ? $config['wxpay_secret_cert'] : '';
|
|
|
- $wxpayPublicCert = isset($config['wxpay_public_cert']) ? $config['wxpay_public_cert'] : '';
|
|
|
- if (empty($appid) || empty($mchid) || empty($secretV3Key)) {
|
|
|
- $this->error = 2616;
|
|
|
- return false;
|
|
|
- }
|
|
|
+ try {
|
|
|
+ if ($payType == 10) {
|
|
|
+ $appid = isset($config['wxpay_appid']) ? $config['wxpay_appid'] : '';
|
|
|
+ $mpAppid = isset($config['wxpay_mp_appid']) ? $config['wxpay_mp_appid'] : '';
|
|
|
+ $minAppid = isset($config['wxpay_min_appid']) ? $config['wxpay_min_appid'] : '';
|
|
|
+ $mchid = isset($config['wxpay_mchd']) ? $config['wxpay_mchd'] : '';
|
|
|
+ $secretV3Key = isset($config['wxpay_key_v3']) ? $config['wxpay_key_v3'] : '';
|
|
|
+ $secretV2Key = isset($config['wxpay_key_v2']) ? $config['wxpay_key_v2'] : '';
|
|
|
+ $wxpaySecretCert = isset($config['wxpay_secret_cert']) ? $config['wxpay_secret_cert'] : '';
|
|
|
+ $wxpayPublicCert = isset($config['wxpay_public_cert']) ? $config['wxpay_public_cert'] : '';
|
|
|
+ if (empty($appid) || empty($mchid) || empty($secretV3Key)) {
|
|
|
+ $this->error = 2616;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 支付参数
|
|
|
- $payConfig = config('payment.wechat');
|
|
|
- $payConfig['wechat']['default']['mch_id'] = $mchid;
|
|
|
- if ($payPt == 'min') {
|
|
|
- // 小程序支付
|
|
|
- $payConfig['wechat']['default']['mini_app_id'] = $minAppid ? $minAppid : $appid;
|
|
|
- } else if ($payPt == 'mp') {
|
|
|
- // 公众号
|
|
|
- $payConfig['wechat']['default']['mp_app_id'] = $mpAppid ? $mpAppid : $appid;
|
|
|
- } else {
|
|
|
- // APP支付
|
|
|
- $payConfig['wechat']['default']['app_id'] = $appid;
|
|
|
- }
|
|
|
+ // 支付参数
|
|
|
+ $payConfig = config('payment.wechat');
|
|
|
+ $payConfig['wechat']['default']['mch_id'] = $mchid;
|
|
|
+ if ($payPt == 'min') {
|
|
|
+ // 小程序支付
|
|
|
+ $payConfig['wechat']['default']['mini_app_id'] = $minAppid ? $minAppid : $appid;
|
|
|
+ } else if ($payPt == 'mp') {
|
|
|
+ // 公众号
|
|
|
+ $payConfig['wechat']['default']['mp_app_id'] = $mpAppid ? $mpAppid : $appid;
|
|
|
+ } else {
|
|
|
+ // APP支付
|
|
|
+ $payConfig['wechat']['default']['app_id'] = $appid;
|
|
|
+ }
|
|
|
|
|
|
- if ($secretV3Key) {
|
|
|
- $payConfig['wechat']['default']['mch_secret_key'] = $secretV3Key;
|
|
|
- } else if ($secretV2Key) {
|
|
|
- $payConfig['wechat']['default']['mch_secret_key_v2'] = $secretV2Key;
|
|
|
- }
|
|
|
+ if ($secretV3Key) {
|
|
|
+ $payConfig['wechat']['default']['mch_secret_key'] = $secretV3Key;
|
|
|
+ } else if ($secretV2Key) {
|
|
|
+ $payConfig['wechat']['default']['mch_secret_key_v2'] = $secretV2Key;
|
|
|
+ }
|
|
|
|
|
|
- if ($wxpaySecretCert) {
|
|
|
- $payConfig['wechat']['default']['mch_secret_cert'] = $wxpaySecretCert;
|
|
|
- }
|
|
|
- if ($wxpayPublicCert) {
|
|
|
- $payConfig['wechat']['default']['mch_public_cert_path'] = $wxpayPublicCert;
|
|
|
- }
|
|
|
- //$payConfig['wechat']['default']['notify_url'] = url('/api/notify/' . $scene . '/10');
|
|
|
- $payConfig['wechat']['default']['notify_url'] = url(env('APP_URL') . 'api/notify/' . $scene . '/10');
|
|
|
-
|
|
|
- $this->config = $payConfig;
|
|
|
- var_dump($payConfig);
|
|
|
- return Pay::wechat($payConfig);
|
|
|
- } else if ($payType == 20) {
|
|
|
- $appid = isset($config['alipay_appid']) ? $config['alipay_appid'] : '';
|
|
|
- $appSecretCert = isset($config['alipay_secret_cert']) ? $config['alipay_secret_cert'] : '';
|
|
|
- $appPublicCert = isset($config['alipay_app_public_cert_path']) ? $config['alipay_app_public_cert_path'] : '';
|
|
|
- $alipayPublicCert = isset($config['alipay_public_cert_path']) ? $config['alipay_public_cert_path'] : '';
|
|
|
- $alipayRootCert = isset($config['alipay_root_cert_path']) ? $config['alipay_root_cert_path'] : '';
|
|
|
- if (empty($appid) || empty($appSecretCert)) {
|
|
|
- $this->error = 2619;
|
|
|
- return false;
|
|
|
- }
|
|
|
+ if ($wxpaySecretCert) {
|
|
|
+ $payConfig['wechat']['default']['mch_secret_cert'] = $wxpaySecretCert;
|
|
|
+ }
|
|
|
+ if ($wxpayPublicCert) {
|
|
|
+ $payConfig['wechat']['default']['mch_public_cert_path'] = $wxpayPublicCert;
|
|
|
+ }
|
|
|
+ //$payConfig['wechat']['default']['notify_url'] = url('/api/notify/' . $scene . '/10');
|
|
|
+ $payConfig['wechat']['default']['notify_url'] = url(env('APP_URL') . 'api/notify/' . $scene . '/10');
|
|
|
+
|
|
|
+ $this->config = $payConfig;
|
|
|
+ var_dump($payConfig);
|
|
|
+ return Pay::wechat($payConfig);
|
|
|
+ } else if ($payType == 20) {
|
|
|
+ $appid = isset($config['alipay_appid']) ? $config['alipay_appid'] : '';
|
|
|
+ $appSecretCert = isset($config['alipay_secret_cert']) ? $config['alipay_secret_cert'] : '';
|
|
|
+ $appPublicCert = isset($config['alipay_app_public_cert_path']) ? $config['alipay_app_public_cert_path'] : '';
|
|
|
+ $alipayPublicCert = isset($config['alipay_public_cert_path']) ? $config['alipay_public_cert_path'] : '';
|
|
|
+ $alipayRootCert = isset($config['alipay_root_cert_path']) ? $config['alipay_root_cert_path'] : '';
|
|
|
+ if (empty($appid) || empty($appSecretCert)) {
|
|
|
+ $this->error = 2619;
|
|
|
+ return false;
|
|
|
+ }
|
|
|
|
|
|
- // 支付参数
|
|
|
- $payConfig = config('payment.alipay');
|
|
|
- $payConfig['alipay']['default']['app_id'] = $appid;
|
|
|
- $payConfig['alipay']['default']['app_secret_cert'] = $appSecretCert;
|
|
|
- if ($appPublicCert) {
|
|
|
- $payConfig['alipay']['default']['app_public_cert_path'] = $appPublicCert;
|
|
|
- }
|
|
|
- if ($alipayPublicCert) {
|
|
|
- $payConfig['alipay']['default']['alipay_public_cert_path'] = $alipayPublicCert;
|
|
|
- }
|
|
|
- if ($alipayRootCert) {
|
|
|
- $payConfig['alipay']['default']['alipay_root_cert_path'] = $alipayRootCert;
|
|
|
+ // 支付参数
|
|
|
+ $payConfig = config('payment.alipay');
|
|
|
+ $payConfig['alipay']['default']['app_id'] = $appid;
|
|
|
+ $payConfig['alipay']['default']['app_secret_cert'] = $appSecretCert;
|
|
|
+ if ($appPublicCert) {
|
|
|
+ $payConfig['alipay']['default']['app_public_cert_path'] = $appPublicCert;
|
|
|
+ }
|
|
|
+ if ($alipayPublicCert) {
|
|
|
+ $payConfig['alipay']['default']['alipay_public_cert_path'] = $alipayPublicCert;
|
|
|
+ }
|
|
|
+ if ($alipayRootCert) {
|
|
|
+ $payConfig['alipay']['default']['alipay_root_cert_path'] = $alipayRootCert;
|
|
|
+ }
|
|
|
+ $payConfig['alipay']['default']['notify_url'] = url('/api/notify/' . $scene . '/20');
|
|
|
+
|
|
|
+ $this->config = $payConfig;
|
|
|
+ return Pay::alipay($payConfig);
|
|
|
+ } else if ($payType == 30) {
|
|
|
+ return true;
|
|
|
}
|
|
|
- $payConfig['alipay']['default']['notify_url'] = url('/api/notify/' . $scene . '/20');
|
|
|
|
|
|
- $this->config = $payConfig;
|
|
|
- return Pay::alipay($payConfig);
|
|
|
- } else if ($payType == 30) {
|
|
|
- return true;
|
|
|
+ return false;
|
|
|
+ } catch (\Exception $exception){
|
|
|
+ $this->errorData = $this->config;
|
|
|
+ $this->error = '请检查支付配置是否正常:'.$exception->getMessage();
|
|
|
+ return false;
|
|
|
}
|
|
|
-
|
|
|
- return false;
|
|
|
}
|
|
|
|
|
|
/**
|